mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
slack: Don't create duplicate reactions.
Just like in the prior commit we add similar code in `get_subscription`, here we do this for reactions. If two Slack accounts, which will be merged into one Zulip account, posted the same emoji reaction to a message, we need to avoid duplication.
This commit is contained in:
committed by
Tim Abbott
parent
86f17026ac
commit
61b6e823b6
@@ -1213,6 +1213,7 @@ def build_reactions(
|
||||
merged_reactions[emoji_name].update(slack_reaction["users"])
|
||||
reactions = [{"name": k, "users": v, "count": len(v)} for k, v in merged_reactions.items()]
|
||||
|
||||
processed_reactions: set[tuple[int, int, str, str]] = set()
|
||||
# For the Unicode emoji codes, we use equivalent of
|
||||
# function 'get_emoji_data' in 'zerver/lib/emoji' here
|
||||
for slack_reaction in reactions:
|
||||
@@ -1249,7 +1250,17 @@ def build_reactions(
|
||||
|
||||
reaction_dict = model_to_dict(reaction, exclude=["message", "user_profile"])
|
||||
reaction_dict["message"] = message_id
|
||||
reaction_dict["user_profile"] = slack_user_id_to_zulip_user_id[slack_user_id]
|
||||
zulip_user_id = slack_user_id_to_zulip_user_id[slack_user_id]
|
||||
reaction_dict["user_profile"] = zulip_user_id
|
||||
|
||||
reaction_tuple = (zulip_user_id, message_id, reaction_type, emoji_code)
|
||||
if reaction_tuple in processed_reactions:
|
||||
# Due to possible merging of Slack accounts into a single Zulip account,
|
||||
# we need to ensure reactions don't get duplicated, violating the unique
|
||||
# constraint on the (user_profile_id, message_id, reaction_type, emoji_code)
|
||||
# index.
|
||||
continue
|
||||
processed_reactions.add(reaction_tuple)
|
||||
|
||||
reaction_list.append(reaction_dict)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user