mirror of https://github.com/zulip/zulip.git
sent_messages: Convert messages from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
bf0a3d9d14
commit
7844be6d3a
|
@ -1,4 +1,4 @@
|
|||
exports.messages = {};
|
||||
exports.messages = new Map();
|
||||
|
||||
exports.reset_id_state = function () {
|
||||
exports.next_local_id = 0;
|
||||
|
@ -36,14 +36,14 @@ exports.start_tracking_message = function (opts) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (exports.messages[local_id] !== undefined) {
|
||||
if (exports.messages.has(local_id)) {
|
||||
blueslip.error('We are re-using a local_id');
|
||||
return;
|
||||
}
|
||||
|
||||
const state = exports.message_state(opts);
|
||||
|
||||
exports.messages[local_id] = state;
|
||||
exports.messages.set(local_id, state);
|
||||
};
|
||||
|
||||
exports.message_state = function (opts) {
|
||||
|
@ -123,7 +123,7 @@ exports.message_state = function (opts) {
|
|||
};
|
||||
|
||||
exports.get_message_state = function (local_id) {
|
||||
const state = exports.messages[local_id];
|
||||
const state = exports.messages.get(local_id);
|
||||
|
||||
if (!state) {
|
||||
blueslip.warn('Unknown local_id: ' + local_id);
|
||||
|
|
|
@ -97,23 +97,17 @@ function get_events_success(events) {
|
|||
messages = echo.process_from_server(messages);
|
||||
if (messages.length > 0) {
|
||||
messages.forEach(message_store.set_message_booleans);
|
||||
let sent_by_this_client = false;
|
||||
|
||||
for (const msg of messages) {
|
||||
const msg_state = sent_messages.messages[msg.local_id];
|
||||
if (msg_state) {
|
||||
// Almost every time, this message will be the
|
||||
// only one in messages, because multiple messages
|
||||
// being returned by get_events usually only
|
||||
// happens when a client is offline, but we know
|
||||
// this client just sent a message in this batch
|
||||
// of events. But in any case,
|
||||
// insert_new_messages handles multiple messages,
|
||||
// only one of which was sent by this client,
|
||||
// correctly.
|
||||
sent_by_this_client = true;
|
||||
}
|
||||
}
|
||||
const sent_by_this_client = messages.some(msg =>
|
||||
sent_messages.messages.has(msg.local_id)
|
||||
);
|
||||
// If some message in this batch of events was sent by this
|
||||
// client, almost every time, this message will be the only one
|
||||
// in messages, because multiple messages being returned by
|
||||
// get_events usually only happens when a client is offline.
|
||||
// But in any case, insert_new_messages handles multiple
|
||||
// messages, only one of which was sent by this client,
|
||||
// correctly.
|
||||
|
||||
message_events.insert_new_messages(messages, sent_by_this_client);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue