Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bots: Only send avatar_url from backend when client cannot compute it. #25073

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ujjawal3
Copy link
Collaborator

Earlier realm_bots data sent in page_params contain avatar_url for all cases. This commit changes this behaviour and now avatar_url is only sent when client cannot compute it and also make changes in frontend for computing the avatar_url when not sent from backend.

Fixes: #24698

Screenshots and screen captures:

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

@Ujjawal3
Copy link
Collaborator Author

@sahil839 please review this PR.

Copy link
Collaborator

@sahil839 sahil839 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted few comments. Also, there is a typo in second commit message. It should be "deprecated".

@@ -416,6 +416,7 @@ paths:
The ID of the user who is affected by this change.
avatar_url:
type: string
nullable: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add **Changes** entry here and also the appropriate changes in changelog.md and version.py.

avatar_source=botdict["avatar_source"],
avatar_version=botdict["avatar_version"],
medium=False,
client_gravatar=True,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot pass client_gravatar as True always. It depends on the client.

@@ -516,7 +516,15 @@ def get_owned_bot_dicts(
"default_events_register_stream": botdict["default_events_register_stream__name"],
"default_all_public_streams": botdict["default_all_public_streams"],
"owner_id": botdict["bot_owner_id"],
"avatar_url": avatar_url_from_dict(botdict),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If removing this line removes 100% coverage on zerver/lib/avatar.py, then the function should be removed in this commit itself, since we want each commit to pass the tests.

@@ -343,7 +343,7 @@ def stream_name(stream: Optional[Stream]) -> Optional[str]:
default_sending_stream=default_sending_stream_name,
default_events_register_stream=default_events_register_stream_name,
default_all_public_streams=user_profile.default_all_public_streams,
avatar_url=avatar_url(user_profile),
avatar_url=avatar_url(user_profile, client_gravatar=True),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to set client_gravatar as False here, since we would not know whether client can compute the gravatar or not. notify_created_user has similar implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sahil839 making client_gravatar always equal to False here will cause various backend tests related to bots to fail. The reason for this is that many tests are calling the function implemented here. As this function matches the state received from server and states after applying events. As in states received from event avatar_url is always sent and in state received from server avatar_url is None states does not match and hence tests are failed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot assume that client can compute url for all clients by passing client_gravatar as True just for the sake of tests. Otherwise, the clients who cannot compute the url will also not recieve URL and would not be able to render the avatar correctly.

Instead we should assume that client cannot compute gravatar and send the url to all clients. For the tests, we would need to add code to events.py which sets the avatar_url to None if client can compute it. See the code for realm_user/add type event in lib/events.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I was able to figure out how to fix the failing test cases.

@Ujjawal3
Copy link
Collaborator Author

@sahil839 I have addressed all your comments. Please have a look.

Copy link
Collaborator

@sahil839 sahil839 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the documentation changes once again. You have added Changes entry in the places where behavior is not changed.

description: |
URL for the user's avatar.

**Changes**: In Zulip 7.0 (feature level 177)
this will be `null` when client can compute the URL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this PR changes the response of the users/me endpoint?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always passing client_gravatar=False to get_raw_user_data from get_profile_backend.

description: |
Present if `realm_user` is present in `fetch_event_types`.

The URL of the avatar for the current user at 100x100
resolution. See also `avatar_url_medium`.

**Changes**: In Zulip 7.0 (feature level 177)
this will be `null` when client can compute the URL.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also incorrect. The avatar_url field for the user themselves is always passed assuming client_gravatar=False.

Earlier `realm_bots` data sent in `page_params` contain
`avatar_url` for all cases. This commit changes this behaviour
and now `avatar_url` is only sent when client cannot compute it
and also make changes in frontend for computing the `avatar_url`
when not sent from backend and removes deprecated function
`avatar_url_from_dict` in `zerver.lib.avatar` as it was no longer used.

Fixes zulip#24698.
@zulipbot
Copy link
Member

Heads up @Ujjawal3, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

realm_bots: Only send avatar_url when client cannot compute it.
3 participants