mirror of
https://github.com/zulip/zulip.git
synced 2025-10-27 18:13:58 +00:00
I lift this function out of message_store to
break some dependencies, and it's also more
consistent with the rest of the codebase:
alert_words.process_message
pm_conversations.process_message
recent_topics.process_messages
recent_senders.process_message_for_senders
We can do further cleanup to make these names
consistent (and possibly have them all work in
bulk), but that's out of the scope of the current PR.
80 lines
2.8 KiB
JavaScript
80 lines
2.8 KiB
JavaScript
import * as alert_words from "./alert_words";
|
|
import * as message_store from "./message_store";
|
|
import * as message_user_ids from "./message_user_ids";
|
|
import * as people from "./people";
|
|
import * as pm_conversations from "./pm_conversations";
|
|
import * as recent_senders from "./recent_senders";
|
|
import * as stream_topic_history from "./stream_topic_history";
|
|
import * as util from "./util";
|
|
|
|
export function process_new_message(message) {
|
|
// Call this function when processing a new message. After
|
|
// a message is processed and inserted into the message store
|
|
// cache, most modules use message_store.get to look at
|
|
// messages.
|
|
const cached_msg = message_store.get_cached_message(message.id);
|
|
if (cached_msg !== undefined) {
|
|
// Copy the match topic and content over if they exist on
|
|
// the new message
|
|
if (util.get_match_topic(message) !== undefined) {
|
|
util.set_match_data(cached_msg, message);
|
|
}
|
|
return cached_msg;
|
|
}
|
|
|
|
message.sent_by_me = people.is_current_user(message.sender_email);
|
|
|
|
people.extract_people_from_message(message);
|
|
people.maybe_incr_recipient_count(message);
|
|
|
|
const sender = people.get_by_user_id(message.sender_id);
|
|
if (sender) {
|
|
message.sender_full_name = sender.full_name;
|
|
message.sender_email = sender.email;
|
|
}
|
|
|
|
// Convert topic even for PMs, as legacy code
|
|
// wants the empty field.
|
|
util.convert_message_topic(message);
|
|
|
|
switch (message.type) {
|
|
case "stream":
|
|
message.is_stream = true;
|
|
message.stream = message.display_recipient;
|
|
message.reply_to = message.sender_email;
|
|
|
|
stream_topic_history.add_message({
|
|
stream_id: message.stream_id,
|
|
topic_name: message.topic,
|
|
message_id: message.id,
|
|
});
|
|
|
|
recent_senders.process_message_for_senders(message);
|
|
message_user_ids.add_user_id(message.sender_id);
|
|
break;
|
|
|
|
case "private":
|
|
message.is_private = true;
|
|
message.reply_to = util.normalize_recipients(message_store.get_pm_emails(message));
|
|
message.display_reply_to = message_store.get_pm_full_names(message);
|
|
message.pm_with_url = people.pm_with_url(message);
|
|
message.to_user_ids = people.pm_reply_user_string(message);
|
|
|
|
pm_conversations.process_message(message);
|
|
|
|
if (people.is_my_user_id(message.sender_id)) {
|
|
for (const recip of message.display_recipient) {
|
|
message_user_ids.add_user_id(recip.id);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
alert_words.process_message(message);
|
|
if (!message.reactions) {
|
|
message.reactions = [];
|
|
}
|
|
message_store.update_message_cache(message);
|
|
return message;
|
|
}
|