mirror of https://github.com/zulip/zulip.git
message_flags: Avoid relying on redundant messages list in response.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
c7fefab05d
commit
1e84edf4f2
|
@ -20,7 +20,6 @@ export const _unread_batch_size = 1000;
|
||||||
|
|
||||||
export const send_read = (function () {
|
export const send_read = (function () {
|
||||||
let queue = [];
|
let queue = [];
|
||||||
let on_success;
|
|
||||||
let start;
|
let start;
|
||||||
function server_request() {
|
function server_request() {
|
||||||
// Wait for server IDs before sending flags
|
// Wait for server IDs before sending flags
|
||||||
|
@ -40,24 +39,19 @@ export const send_read = (function () {
|
||||||
channel.post({
|
channel.post({
|
||||||
url: "/json/messages/flags",
|
url: "/json/messages/flags",
|
||||||
data: {messages: JSON.stringify(real_msg_ids_batch), op: "add", flag: "read"},
|
data: {messages: JSON.stringify(real_msg_ids_batch), op: "add", flag: "read"},
|
||||||
success: on_success,
|
success() {
|
||||||
|
const batch_set = new Set(real_msg_ids_batch);
|
||||||
|
queue = queue.filter((message) => !batch_set.has(message.id));
|
||||||
|
|
||||||
|
if (queue.length > 0) {
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start = _.throttle(server_request, 1000);
|
start = _.throttle(server_request, 1000);
|
||||||
|
|
||||||
on_success = function on_success(data) {
|
|
||||||
if (data === undefined || data.messages === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
queue = queue.filter((message) => !data.messages.includes(message.id));
|
|
||||||
|
|
||||||
if (queue.length > 0) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function add(messages) {
|
function add(messages) {
|
||||||
queue = queue.concat(messages);
|
queue = queue.concat(messages);
|
||||||
start();
|
start();
|
||||||
|
|
Loading…
Reference in New Issue