Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

unread_ops: Add function to mark PM threads as read.

Aman Agrawal74a97ab398d8
diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js
index dccddacc3da..e9bc8f43ce1 100644
--- a/frontend_tests/node_tests/message_flags.js
+++ b/frontend_tests/node_tests/message_flags.js
@@ -256,6 +256,17 @@ run_test("read", ({override}) => {
},
success: channel_post_opts.success,
});
+
+ msgs_to_flag_read = [1, 2, 3, 4, 5];
+ message_flags.mark_as_read(msgs_to_flag_read);
+ assert.deepEqual(channel_post_opts, {
+ url: "/json/messages/flags",
+ data: {
+ messages: "[1,2,3,4,5]",
+ op: "add",
+ flag: "read",
+ },
+ });
});
run_test("read_empty_data", ({override}) => {
diff --git a/static/js/message_flags.js b/static/js/message_flags.js
index 7b2443eee77..a0173e3f0e7 100644
--- a/static/js/message_flags.js
+++ b/static/js/message_flags.js
@@ -66,6 +66,10 @@ export const send_read = (function () {
return add;
})();
+export function mark_as_read(message_ids) {
+ send_flag_update_for_messages(message_ids, "read", "add");
+}
+
export function mark_as_unread(message_ids) {
send_flag_update_for_messages(message_ids, "read", "remove");
}
diff --git a/static/js/unread_ops.js b/static/js/unread_ops.js
index 874dcdfd0ad..a46f8d67f9c 100644
--- a/static/js/unread_ops.js
+++ b/static/js/unread_ops.js
@@ -227,3 +227,11 @@ export function mark_topic_as_read(stream_id, topic, cont) {
success: cont,
});
}
+
+export function mark_pm_as_read(user_ids_string) {
+ // user_ids_string is a stringified list of user ids which are
+ // participants in the conversation other than the current
+ // user. Eg: "123,124" or "123"
+ const unread_msg_ids = unread.get_msg_ids_for_user_ids_string(user_ids_string);
+ message_flags.mark_as_read(unread_msg_ids);
+}