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

Preparation for deprecating reactions' user metadata #1556

Merged
merged 9 commits into from
Dec 10, 2024

Conversation

Niloth-p
Copy link
Collaborator

What does this PR do, and why?

  • Prepares for the deprecation of user metadata from messages' reactions and reaction events
    • Supports both user_id (ZFL>=2) and user["id"] for messages' reactions (with added test cases)
    • Supports both user_id (ZFL>=2) and user["user_id"] for reaction events (with added test cases)
    • Introduces a common get_user_id_from_reaction() for handling the different possible fields
    • Switches to using _all_users_by_id["user_id"] to remove dependency on `reaction["user"]["full_name"]
    • Improves the ReactionEvent schema to support both versions
  • Fixes a bug in reaction event handling (remove op), and adds tests covering the missing cases
  • Refactors the reactions' functions a bit before the above changes

External discussion & connections

  • Discussed in #zulip-terminal in reaction metadata
  • Fully fixes #
  • Partially fixes issue #
  • Builds upon previous unmerged work in PR #
  • Is a follow-up to work in PR #
  • Requires merge of PR #
  • Merge will enable work on #

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

Visual changes

- Simplified reaction toggling in `toggle_message_reaction()`
- Simplified reaction event handling in `_handle_reaction_event()`
- Simplified reaction agreement command logic

Removed comments for self-explanatory code.
The `reaction_event_index_factory` was previously generating reactions
based on the Reaction Event schema.
When multiple users shared an emoji reaction, the prior implementation
did not account for individual user IDs, leading to buggy handling of
'remove reaction' events.
In preparation for deprecation of `user` field from reactions.

Tests added.
- reaction_event_factory
- reaction_event_index_factory

To test the handling of reaction events conforming to the reactions
schema post ZFL 2.
The "user" field is to be deprecated from messages' reactions and
reaction events in the API.

Add support for `user_id` in MsgInfoView, by using the recently
introduced `get_user_id_from_reaction()`.

Remove dependence on reaction["user"]["full_name"] by instead using
`_all_users_by_id` with the "user_id".

Tests updated.
@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Nov 18, 2024
@Niloth-p Niloth-p changed the title Reactions metadata/pr Preparation for deprecating reactions' user metadata Nov 18, 2024
Copy link
Collaborator

@mounilKshah mounilKshah left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @Niloth-p
At first glance, the get_user_id_from_reaction() seemed unnecessary to me but on closer look, multiple usages of the same logic make the function a necessity. The coverage of cases is more vast than the impact that I had expected. Overall, this worked as expected across all the use cases that I tried for.
I think the commit structure can be changed. You can squash the initial commits which work towards simplifying/switching to the new API response. Then the next commit can be the patch providing the new function of get_user_id_from_reaction() and its test function. Then you may change all implementations of the older response and add the function calls wherever necessary.
Apart from this, I don't have any other changes to suggest for this PR.

if (
reaction["emoji_code"] == event["emoji_code"]
and reaction_user_id == event_user_id
):
message["reactions"].remove(reaction)
break
Copy link
Member

Choose a reason for hiding this comment

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

Feature level 3.0 is old enough that we could drop support for it. But I guess this is OK.

@timabbott timabbott merged commit 23a773c into zulip:main Dec 10, 2024
21 checks passed
@timabbott
Copy link
Member

I did a fairly careful read, and this seems like a good PR to me, and I think it makes sense to merge and fix-forward from here as needed. It's sadly a bit of wasted effort -- we could just process user_id given no other clients support older versions than 5.0 -- but doing that can be left for future work, as it's not a problem for this code path to support ancient versions, just extra code we don't need.

@Niloth-p
Copy link
Collaborator Author

Thank you!
True, I did consider dropping the older version support, but during our GSoC calls, Neil has explicitly expressed how he prefers retaining support for the older versions unlike all the other clients, so this was done for his satisfaction. We've had a few discussions on adding a uniform framework for version-specific features / ZFL-specific handling, so knowing that, I didn't want to be the person who drops the support for older versions.

@Niloth-p Niloth-p deleted the reactions-metadata/pr branch December 11, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants