mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
do_update_message: Clean up timestamp code.
By moving this logic to the topic of the functon, we make the code a lot more readable.
This commit is contained in:
@@ -4493,15 +4493,22 @@ def do_update_message(user_profile: UserProfile, message: Message, topic_name: O
|
|||||||
With topic edits, propagate_mode determines whether other message
|
With topic edits, propagate_mode determines whether other message
|
||||||
also have their topics edited.
|
also have their topics edited.
|
||||||
"""
|
"""
|
||||||
|
timestamp = timezone_now()
|
||||||
|
message.last_edit_time = timestamp
|
||||||
|
|
||||||
event = {'type': 'update_message',
|
event = {'type': 'update_message',
|
||||||
# TODO: We probably want to remove the 'sender' field
|
# TODO: We probably want to remove the 'sender' field
|
||||||
# after confirming it isn't used by any consumers.
|
# after confirming it isn't used by any consumers.
|
||||||
'sender': user_profile.email,
|
'sender': user_profile.email,
|
||||||
'user_id': user_profile.id,
|
'user_id': user_profile.id,
|
||||||
|
'edit_timestamp': datetime_to_timestamp(timestamp),
|
||||||
'message_id': message.id} # type: Dict[str, Any]
|
'message_id': message.id} # type: Dict[str, Any]
|
||||||
|
|
||||||
edit_history_event = {
|
edit_history_event = {
|
||||||
'user_id': user_profile.id,
|
'user_id': user_profile.id,
|
||||||
|
'timestamp': event['edit_timestamp'],
|
||||||
} # type: Dict[str, Any]
|
} # type: Dict[str, Any]
|
||||||
|
|
||||||
changed_messages = [message]
|
changed_messages = [message]
|
||||||
|
|
||||||
stream_being_edited = None
|
stream_being_edited = None
|
||||||
@@ -4598,10 +4605,6 @@ def do_update_message(user_profile: UserProfile, message: Message, topic_name: O
|
|||||||
|
|
||||||
changed_messages += messages_list
|
changed_messages += messages_list
|
||||||
|
|
||||||
message.last_edit_time = timezone_now()
|
|
||||||
assert message.last_edit_time is not None # assert needed because stubs for django are missing
|
|
||||||
event['edit_timestamp'] = datetime_to_timestamp(message.last_edit_time)
|
|
||||||
edit_history_event['timestamp'] = event['edit_timestamp']
|
|
||||||
if message.edit_history is not None:
|
if message.edit_history is not None:
|
||||||
edit_history = ujson.loads(message.edit_history)
|
edit_history = ujson.loads(message.edit_history)
|
||||||
edit_history.insert(0, edit_history_event)
|
edit_history.insert(0, edit_history_event)
|
||||||
|
|||||||
Reference in New Issue
Block a user