message_flags: Filter msgs having (or not) the flag before updating.

We were blindly adding / removing flag from UserMessages without
check if they even need to be updated.

This caused server to repeatedly update flags for messages which
already had been updated, creating a confusion for other clients
like mobile.

Fixes #22164
This commit is contained in:
Aman Agrawal
2022-06-02 11:36:42 +00:00
committed by Tim Abbott
parent 0ad282c11e
commit 40fcf5a633
3 changed files with 44 additions and 13 deletions

View File

@@ -38,13 +38,13 @@ def update_message_flags(
request_notes = RequestNotes.get_notes(request)
assert request_notes.log_data is not None
count = do_update_message_flags(user_profile, operation, flag, messages)
count, updated_message_ids = do_update_message_flags(user_profile, operation, flag, messages)
target_count_str = str(len(messages))
log_data_str = f"[{operation} {flag}/{target_count_str}] actually {count}"
request_notes.log_data["extra"] = log_data_str
return json_success(request, data={"messages": messages})
return json_success(request, data={"messages": updated_message_ids})
@has_request_variables