Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

edit_history: Support prev_subject not being present in database.

Tim Abbott5e819cdebc7c
diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py
index 9eef8b72155..96454a47b5c 100644
--- a/tools/linter_lib/custom_check.py
+++ b/tools/linter_lib/custom_check.py
@@ -12,6 +12,7 @@ from zulint.custom_rules import Rule, RuleList
FILES_WITH_LEGACY_SUBJECT = {
# This basically requires a big DB migration:
+ "zerver/lib/message.py",
"zerver/lib/topic.py",
"zerver/lib/types.py",
"zerver/views/message_edit.py",
diff --git a/zerver/lib/message.py b/zerver/lib/message.py
index 318d4e6faf8..bdc2b654611 100644
--- a/zerver/lib/message.py
+++ b/zerver/lib/message.py
@@ -511,12 +511,20 @@ class MessageDict:
edit_history: List[APIEditHistoryEvent] = []
for edit_history_event in raw_edit_history:
# Drop fields we're not yet ready to have appear in the API
+ if "prev_topic" in edit_history_event:
+ # The prev_subject field has been renamed in the
+ # database, but not the API.
+ edit_history_event["prev_subject"] = edit_history_event["prev_topic"]
+
+ # New fields not consistently available, and thus
+ # intentionally not exposed to the API.
if "prev_topic" in edit_history_event:
del edit_history_event["prev_topic"]
if "stream" in edit_history_event:
del edit_history_event["stream"]
if "topic" in edit_history_event:
del edit_history_event["topic"]
+
edit_history.append(edit_history_event)
obj["edit_history"] = edit_history
diff --git a/zerver/lib/types.py b/zerver/lib/types.py
index edd987915c5..c7ab897e4bb 100644
--- a/zerver/lib/types.py
+++ b/zerver/lib/types.py
@@ -121,6 +121,8 @@ class EditHistoryEvent(TypedDict, total=False):
timestamp: int
prev_stream: int
stream: int
+ # One of prev_subject and prev_topic is guaranteed to exist; if
+ # both exist they will have identical values.
prev_subject: str
prev_topic: str
topic: str
diff --git a/zerver/views/message_edit.py b/zerver/views/message_edit.py
index 9944d9fa0a3..68ef39efcc7 100644
--- a/zerver/views/message_edit.py
+++ b/zerver/views/message_edit.py
@@ -51,8 +51,11 @@ def fill_edit_history_entries(
"user_id": edit_history_event["user_id"],
}
- # Add current topic, map LEGACY_PREV_TOPIC => "prev_topic".
- if LEGACY_PREV_TOPIC in edit_history_event:
+ if "prev_topic" in edit_history_event:
+ prev_topic = edit_history_event["prev_topic"]
+ formatted_entry["prev_topic"] = prev_topic
+ elif LEGACY_PREV_TOPIC in edit_history_event:
+ # TODO: Delete this once we've finished migrating legacy message objects.
prev_topic = edit_history_event["prev_subject"]
formatted_entry["prev_topic"] = prev_topic