message_events_util: Remove unnecessary callback.

All callbacks want to add messages, so we just directly do that.
This commit is contained in:
Aman Agrawal
2024-12-18 22:20:55 +05:30
committed by Tim Abbott
parent 525ae3aaff
commit 238c35f2af
4 changed files with 5 additions and 45 deletions

View File

@@ -558,7 +558,6 @@ export function process_from_server(messages: ServerMessage[]): ServerMessage[]
message_events_util.maybe_add_narrowed_messages(
msgs_to_rerender_or_add_to_narrow,
msg_list,
message_util.add_new_messages,
);
} else {
// In theory, we could just rerender messages where there were

View File

@@ -25,7 +25,6 @@ import * as message_notifications from "./message_notifications.ts";
import * as message_parser from "./message_parser.ts";
import * as message_store from "./message_store.ts";
import {type Message, type RawMessage, raw_message_schema} from "./message_store.ts";
import * as message_util from "./message_util.ts";
import * as message_view from "./message_view.ts";
import * as narrow_state from "./narrow_state.ts";
import * as pm_list from "./pm_list.ts";
@@ -313,11 +312,7 @@ export function insert_new_messages(
continue;
}
message_events_util.maybe_add_narrowed_messages(
messages,
list,
message_util.add_new_messages,
);
message_events_util.maybe_add_narrowed_messages(messages, list);
continue;
}
@@ -739,11 +734,7 @@ export function update_messages(events: UpdateMessageEvent[]): void {
// simply updated.
list.remove_and_rerender(event_msg_ids);
// For filters that cannot be processed locally, ask server.
message_events_util.maybe_add_narrowed_messages(
event_messages,
list,
message_util.add_messages,
);
message_events_util.maybe_add_narrowed_messages(event_messages, list);
}
}
}

View File

@@ -3,7 +3,7 @@ import {z} from "zod";
import * as blueslip from "./blueslip.ts";
import * as channel from "./channel.ts";
import * as compose_notifications from "./compose_notifications.ts";
import type {MessageList, RenderInfo} from "./message_list.ts";
import type {MessageList} from "./message_list.ts";
import * as message_lists from "./message_lists.ts";
import * as message_store from "./message_store.ts";
import type {Message} from "./message_store.ts";
@@ -24,7 +24,6 @@ const msg_match_narrow_api_response_schema = z.object({
export function maybe_add_narrowed_messages(
messages: Message[],
msg_list: MessageList,
callback: (messages: Message[], msg_list: MessageList) => RenderInfo | undefined,
attempt = 1,
): void {
const ids: number[] = [];
@@ -83,7 +82,7 @@ export function maybe_add_narrowed_messages(
// Remove the elsewhere_messages from the message list since
// they don't match the filter as per data from server.
msg_list.remove_and_rerender(elsewhere_messages.map((msg) => msg.id));
callback(new_messages, msg_list);
msg_list.add_messages(new_messages);
unread_ops.process_visible();
compose_notifications.notify_messages_outside_current_search(elsewhere_messages);
},
@@ -112,7 +111,7 @@ export function maybe_add_narrowed_messages(
if (msg_list === message_lists.current) {
// Don't actually try again if we un-narrowed
// while waiting
maybe_add_narrowed_messages(messages, msg_list, callback, attempt + 1);
maybe_add_narrowed_messages(messages, msg_list, attempt + 1);
}
}, delay);
},

View File

@@ -1,7 +1,6 @@
import assert from "minimalistic-assert";
import {all_messages_data} from "./all_messages_data.ts";
import type {MessageList, RenderInfo} from "./message_list.ts";
import * as message_lists from "./message_lists.ts";
import * as message_store from "./message_store.ts";
import type {Message} from "./message_store.ts";
@@ -25,34 +24,6 @@ export function do_unread_count_updates(messages: Message[], expect_no_new_unrea
}
}
export function add_messages(
messages: Message[],
msg_list: MessageList,
append_to_view_opts?: {messages_are_new: boolean},
): RenderInfo | undefined {
if (!messages) {
return undefined;
}
const render_info = msg_list.add_messages(messages, append_to_view_opts);
return render_info;
}
export function add_new_messages(
messages: Message[],
msg_list: MessageList,
): RenderInfo | undefined {
if (!msg_list.data.fetch_status.has_found_newest()) {
// We don't render newly received messages for the message list,
// if we haven't found the latest messages to be displayed in the
// narrow. Otherwise the new message would be rendered just after
// the previously fetched messages when that's inaccurate.
msg_list.data.fetch_status.update_expected_max_message_id(messages);
return undefined;
}
return add_messages(messages, msg_list, {messages_are_new: true});
}
export function get_count_of_messages_in_topic_sent_after_current_message(
stream_id: number,
topic: string,