message_edit: Extract update_edit_history.

This commit is contained in:
Aman Agrawal 2021-04-22 05:02:04 +00:00 committed by Tim Abbott
parent 736fdcda49
commit de50f4ae25
1 changed files with 13 additions and 7 deletions

View File

@ -126,6 +126,18 @@ def user_message_exists_for_topic(
).exists()
def update_edit_history(
message: Message, last_edit_time: datetime, edit_history_event: Dict[str, Any]
) -> None:
message.last_edit_time = last_edit_time
if message.edit_history is not None:
edit_history = orjson.loads(message.edit_history)
edit_history.insert(0, edit_history_event)
else:
edit_history = [edit_history_event]
message.edit_history = orjson.dumps(edit_history).decode()
def update_messages_for_topic_edit(
edited_message: Message,
propagate_mode: str,
@ -170,13 +182,7 @@ def update_messages_for_topic_edit(
m.set_topic_name(topic_name)
for message in messages_list:
message.last_edit_time = last_edit_time
if message.edit_history is not None:
edit_history = orjson.loads(message.edit_history)
edit_history.insert(0, edit_history_event)
else:
edit_history = [edit_history_event]
message.edit_history = orjson.dumps(edit_history).decode()
update_edit_history(message, last_edit_time, edit_history_event)
Message.objects.bulk_update(messages_list, update_fields)