mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
echo: Convert waiting_for_ack from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
c42aca3cfb
commit
0936381cfd
@@ -40,13 +40,13 @@ set_global('message_list', {});
|
||||
set_global('current_msg_list', '');
|
||||
|
||||
run_test('process_from_server for un-echoed messages', () => {
|
||||
const waiting_for_ack = {};
|
||||
const waiting_for_ack = new Map();
|
||||
const server_messages = [
|
||||
{
|
||||
local_id: "100.1",
|
||||
},
|
||||
];
|
||||
echo._patch_waiting_for_awk(waiting_for_ack);
|
||||
echo._patch_waiting_for_ack(waiting_for_ack);
|
||||
const non_echo_messages = echo.process_from_server(server_messages);
|
||||
assert.deepEqual(non_echo_messages, server_messages);
|
||||
});
|
||||
@@ -56,15 +56,15 @@ run_test('process_from_server for differently rendered messages', () => {
|
||||
// in local echo.
|
||||
const old_value = 'old_value';
|
||||
const new_value = 'new_value';
|
||||
const waiting_for_ack = {
|
||||
100.1: {
|
||||
const waiting_for_ack = new Map([
|
||||
["100.1", {
|
||||
content: "<p>A client rendered message</p>",
|
||||
timestamp: old_value,
|
||||
is_me_message: old_value,
|
||||
submessages: old_value,
|
||||
topic_links: old_value,
|
||||
},
|
||||
};
|
||||
}],
|
||||
]);
|
||||
const server_messages = [
|
||||
{
|
||||
local_id: "100.1",
|
||||
@@ -75,7 +75,7 @@ run_test('process_from_server for differently rendered messages', () => {
|
||||
topic_links: new_value,
|
||||
},
|
||||
];
|
||||
echo._patch_waiting_for_awk(waiting_for_ack);
|
||||
echo._patch_waiting_for_ack(waiting_for_ack);
|
||||
messages_to_rerender = [];
|
||||
disparities = [];
|
||||
const non_echo_messages = echo.process_from_server(server_messages);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
||||
|
||||
const waiting_for_id = new Map();
|
||||
let waiting_for_ack = {};
|
||||
let waiting_for_ack = new Map();
|
||||
|
||||
function resend_message(message, row) {
|
||||
message.content = message.raw_content;
|
||||
@@ -128,7 +128,7 @@ exports.insert_local_message = function (message_request, local_id_float) {
|
||||
markdown.add_topic_links(message);
|
||||
|
||||
waiting_for_id.set(message.local_id, message);
|
||||
waiting_for_ack[message.local_id] = message;
|
||||
waiting_for_ack.set(message.local_id, message);
|
||||
|
||||
message.display_recipient = echo.build_display_recipient(message);
|
||||
local_message.insert_message(message);
|
||||
@@ -260,7 +260,7 @@ exports.process_from_server = function process_from_server(messages) {
|
||||
for (const message of messages) {
|
||||
// In case we get the sent message before we get the send ACK, reify here
|
||||
|
||||
const client_message = waiting_for_ack[message.local_id];
|
||||
const client_message = waiting_for_ack.get(message.local_id);
|
||||
if (client_message === undefined) {
|
||||
// For messages that weren't locally echoed, we go through
|
||||
// the "main" codepath that doesn't have to id reconciliation.
|
||||
@@ -296,7 +296,7 @@ exports.process_from_server = function process_from_server(messages) {
|
||||
client_message.submessages = message.submessages;
|
||||
|
||||
msgs_to_rerender.push(client_message);
|
||||
delete waiting_for_ack[client_message.id];
|
||||
waiting_for_ack.delete(client_message.id);
|
||||
}
|
||||
|
||||
if (msgs_to_rerender.length > 0) {
|
||||
@@ -313,7 +313,7 @@ exports.process_from_server = function process_from_server(messages) {
|
||||
return non_echo_messages;
|
||||
};
|
||||
|
||||
exports._patch_waiting_for_awk = function _patch_waiting_for_awk(data) {
|
||||
exports._patch_waiting_for_ack = function _patch_waiting_for_ack(data) {
|
||||
// Only for testing
|
||||
waiting_for_ack = data;
|
||||
};
|
||||
@@ -340,7 +340,7 @@ exports.initialize = function () {
|
||||
const message_id = rows.id(row);
|
||||
// Message should be waiting for ack and only have a local id,
|
||||
// otherwise send would not have failed
|
||||
const message = waiting_for_ack[message_id];
|
||||
const message = waiting_for_ack.get(message_id);
|
||||
if (message === undefined) {
|
||||
blueslip.warn("Got resend or retry on failure request but did not find message in ack list " + message_id);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user