2018-07-03 01:30:43 +02:00
|
|
|
zrequire('unread');
|
|
|
|
zrequire('unread_ops');
|
|
|
|
zrequire('message_flags');
|
|
|
|
|
|
|
|
set_global('ui', {});
|
|
|
|
set_global('channel', {});
|
2018-08-17 03:46:32 +02:00
|
|
|
set_global('starred_messages', {
|
|
|
|
add: () => {},
|
|
|
|
remove: () => {},
|
|
|
|
});
|
2018-07-03 01:30:43 +02:00
|
|
|
|
|
|
|
run_test('starred', () => {
|
|
|
|
const message = {
|
|
|
|
id: 50,
|
|
|
|
};
|
|
|
|
|
|
|
|
var ui_updated;
|
|
|
|
|
2018-08-01 19:02:38 +02:00
|
|
|
ui.update_starred_view = () => {
|
2018-07-03 01:30:43 +02:00
|
|
|
ui_updated = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var posted_data;
|
|
|
|
|
|
|
|
channel.post = (opts) => {
|
|
|
|
assert.equal(opts.url, '/json/messages/flags');
|
|
|
|
posted_data = opts.data;
|
|
|
|
};
|
|
|
|
|
2018-08-01 20:09:12 +02:00
|
|
|
message_flags.toggle_starred_and_update_server(message);
|
2018-07-03 01:30:43 +02:00
|
|
|
|
|
|
|
assert(ui_updated);
|
|
|
|
|
|
|
|
assert.deepEqual(posted_data, {
|
|
|
|
messages: '[50]',
|
|
|
|
flag: 'starred',
|
|
|
|
op: 'add',
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(message, {
|
|
|
|
id: 50,
|
|
|
|
starred: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
ui_updated = false;
|
|
|
|
|
2018-08-01 20:09:12 +02:00
|
|
|
message_flags.toggle_starred_and_update_server(message);
|
2018-07-03 01:30:43 +02:00
|
|
|
|
|
|
|
assert(ui_updated);
|
|
|
|
|
|
|
|
assert.deepEqual(posted_data, {
|
|
|
|
messages: '[50]',
|
|
|
|
flag: 'starred',
|
|
|
|
op: 'remove',
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(message, {
|
|
|
|
id: 50,
|
|
|
|
starred: false,
|
|
|
|
});
|
|
|
|
});
|
2019-05-04 04:10:05 +02:00
|
|
|
run_test('read', () => {
|
|
|
|
// Way to capture posted info in every request
|
|
|
|
var channel_post_opts;
|
|
|
|
channel.post = (opts) => {
|
|
|
|
channel_post_opts = opts;
|
|
|
|
};
|
|
|
|
|
|
|
|
// For testing purpose limit the batch size value to 5 instead of 1000
|
|
|
|
message_flags._unread_batch_size = 5;
|
|
|
|
var msgs_to_flag_read = [
|
|
|
|
{ locally_echoed: false, id: 1 },
|
|
|
|
{ locally_echoed: false, id: 2 },
|
|
|
|
{ locally_echoed: false, id: 3 },
|
|
|
|
{ locally_echoed: false, id: 4 },
|
|
|
|
{ locally_echoed: false, id: 5 },
|
|
|
|
{ locally_echoed: false, id: 6 },
|
|
|
|
{ locally_echoed: false, id: 7 },
|
|
|
|
];
|
|
|
|
message_flags.send_read(msgs_to_flag_read);
|
|
|
|
assert.deepEqual(channel_post_opts, {
|
|
|
|
url: '/json/messages/flags',
|
|
|
|
idempotent: true,
|
|
|
|
data: {
|
|
|
|
messages: '[1,2,3,4,5]',
|
|
|
|
op: 'add',
|
|
|
|
flag: 'read',
|
|
|
|
},
|
|
|
|
success: channel_post_opts.success,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mock successful flagging of ids
|
|
|
|
var success_response_data = {
|
|
|
|
messages: [1, 2, 3, 4, 5],
|
|
|
|
};
|
|
|
|
channel_post_opts.success(success_response_data);
|
|
|
|
assert.deepEqual(channel_post_opts, {
|
|
|
|
url: '/json/messages/flags',
|
|
|
|
idempotent: true,
|
|
|
|
data: {
|
|
|
|
messages: '[6,7]',
|
|
|
|
op: 'add',
|
|
|
|
flag: 'read',
|
|
|
|
},
|
|
|
|
success: channel_post_opts.success,
|
|
|
|
});
|
|
|
|
success_response_data = {
|
|
|
|
messages: [6, 7],
|
|
|
|
};
|
|
|
|
channel_post_opts.success(success_response_data);
|
|
|
|
|
|
|
|
// Don't flag locally echoed messages as read
|
|
|
|
var local_msg_1 = { locally_echoed: true, id: 1 };
|
|
|
|
var local_msg_2 = { locally_echoed: true, id: 2 };
|
|
|
|
msgs_to_flag_read = [
|
|
|
|
local_msg_1,
|
|
|
|
local_msg_2,
|
|
|
|
{ locally_echoed: false, id: 3 },
|
|
|
|
{ locally_echoed: false, id: 4 },
|
|
|
|
{ locally_echoed: false, id: 5 },
|
|
|
|
{ locally_echoed: false, id: 6 },
|
|
|
|
{ locally_echoed: false, id: 7 },
|
|
|
|
];
|
|
|
|
message_flags.send_read(msgs_to_flag_read);
|
|
|
|
assert.deepEqual(channel_post_opts, {
|
|
|
|
url: '/json/messages/flags',
|
|
|
|
idempotent: true,
|
|
|
|
data: {
|
|
|
|
messages: '[3,4,5,6,7]',
|
|
|
|
op: 'add',
|
|
|
|
flag: 'read',
|
|
|
|
},
|
|
|
|
success: channel_post_opts.success,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mark them non local
|
|
|
|
local_msg_1.locally_echoed = false;
|
|
|
|
local_msg_2.locally_echoed = false;
|
|
|
|
|
|
|
|
// Mock successful flagging of ids
|
|
|
|
success_response_data = {
|
|
|
|
messages: [3, 4, 5, 6, 7],
|
|
|
|
};
|
|
|
|
channel_post_opts.success(success_response_data);
|
|
|
|
|
|
|
|
// Former locally echoed messages flagging retried
|
|
|
|
assert.deepEqual(channel_post_opts, {
|
|
|
|
url: '/json/messages/flags',
|
|
|
|
idempotent: true,
|
|
|
|
data: {
|
|
|
|
messages: '[1,2]',
|
|
|
|
op: 'add',
|
|
|
|
flag: 'read',
|
|
|
|
},
|
|
|
|
success: channel_post_opts.success,
|
|
|
|
});
|
|
|
|
});
|