recent_topics: Update stored message id of locally echoed messages.

This fixes the bug that message was undefined since we used to store
locally echoed message id and were not updating it after new message
id for the same message was received from the server.
This commit is contained in:
Aman Agrawal
2020-05-28 13:18:58 +05:30
committed by Tim Abbott
parent 35f584e5ef
commit e6611089fd
3 changed files with 55 additions and 0 deletions

View File

@@ -272,6 +272,7 @@ exports.reify_message_id = function (local_id, server_id) {
message_store.reify_message_id(opts);
notifications.reify_message_id(opts);
recent_topics.reify_message_id_if_available(opts);
};
exports.process_from_server = function (messages) {

View File

@@ -38,6 +38,10 @@ exports.process_message = function (msg, do_inplace_rerender) {
const is_ours = people.is_my_user_id(msg.sender_id);
const topic_data = topics.get(key);
if (topic_data.last_msg_id < msg.id) {
// NOTE: This also stores locally echoed msg_id which
// has not been successfully received from the server.
// We store it now and reify it when response is available
// from server.
topic_data.last_msg_id = msg.id;
}
topic_data.participated = is_ours || topic_data.participated;
@@ -48,6 +52,16 @@ exports.process_message = function (msg, do_inplace_rerender) {
return true;
};
exports.reify_message_id_if_available = function (opts) {
for (const [, value] of topics.entries()) {
if (value.last_msg_id === opts.old_id) {
value.last_msg_id = opts.new_id;
return true;
}
}
return false;
};
function get_sorted_topics() {
// Sort all recent topics by last message time.
return new Map(Array.from(topics.entries()).sort(function (a, b) {