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.

message_events: Move get_post_edit_topic to helper function.

Evy Kassirera7d49fc7f231
diff --git a/web/src/message_events.ts b/web/src/message_events.ts
index 381ec3a938f..d34e65ab55f 100644
--- a/web/src/message_events.ts
+++ b/web/src/message_events.ts
@@ -416,6 +416,26 @@ function topic_resolve_toggled(new_topic: string, original_topic: string): boole
return false;
}
+function get_post_edit_topic(
+ topic_edited: boolean,
+ event: UpdateMessageEvent,
+ new_topic: string | undefined,
+ anchor_message: Message | undefined,
+): string {
+ const pre_edit_topic = util.get_edit_event_orig_topic(event);
+ assert(pre_edit_topic !== undefined);
+
+ if (topic_edited) {
+ assert(new_topic !== undefined);
+ return new_topic;
+ }
+ if (anchor_message !== undefined) {
+ assert(anchor_message.type === "stream");
+ return anchor_message.topic;
+ }
+ return pre_edit_topic;
+}
+
export function update_messages(events: UpdateMessageEvent[]): void {
const messages_to_rerender: Message[] = [];
let changed_narrow = false;
@@ -802,20 +822,14 @@ export function update_messages(events: UpdateMessageEvent[]): void {
if (topic_edited || stream_changed) {
// We must be moving stream messages.
assert(old_stream_id !== undefined);
- let pre_edit_topic = util.get_edit_event_orig_topic(event);
+ const pre_edit_topic = util.get_edit_event_orig_topic(event);
assert(pre_edit_topic !== undefined);
-
- let post_edit_topic: string;
- if (topic_edited) {
- assert(new_topic !== undefined);
- post_edit_topic = new_topic;
- } else {
- if (anchor_message !== undefined) {
- assert(anchor_message.type === "stream");
- pre_edit_topic = anchor_message.topic;
- }
- post_edit_topic = pre_edit_topic;
- }
+ const post_edit_topic = get_post_edit_topic(
+ topic_edited,
+ event,
+ new_topic,
+ anchor_message,
+ );
// new_stream_id is undefined if this is only a topic edit.
const post_edit_stream_id = new_stream_id ?? old_stream_id;