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.

recent_senders: Fix twice sent user ids in PM to self case.

Aman Agrawale6f3ffb94656
diff --git a/web/src/recent_senders.js b/web/src/recent_senders.js
index 3c85220a4dd..6107895f7fc 100644
--- a/web/src/recent_senders.js
+++ b/web/src/recent_senders.js
@@ -232,14 +232,23 @@ export function get_pm_recent_senders(user_ids_string) {
return pm_senders_info;
}
+ if (!(user_ids.length === 1 && user_ids[0] === people.my_current_user_id())) {
+ // For group PMs or 1:1 private messages, the user_ids_string
+ // contains just the other user, so we need to add ourselves if not
+ // already present. For PM to self, the current user is already present,
+ // in user_ids_string, so we don't need to add it.
+ //
+ // TODO: Replace this logic with a people.js common function for parsing
+ // user_ids_string and returning the set of user_ids, self included.
+ user_ids.push(people.my_current_user_id());
+ }
+
function compare_pm_user_ids_by_recency(user_id1, user_id2) {
const max_id1 = sender_dict.get(user_id1)?.max_id() || -1;
const max_id2 = sender_dict.get(user_id2)?.max_id() || -1;
return max_id2 - max_id1;
}
- // Add current user to user_ids.
- user_ids.push(people.my_current_user_id());
pm_senders_info.non_participants = user_ids.filter((user_id) => {
if (sender_dict.get(user_id)) {
pm_senders_info.participants.push(user_id);
diff --git a/web/tests/recent_senders.test.js b/web/tests/recent_senders.test.js
index 0036bf512a8..f299f55e717 100644
--- a/web/tests/recent_senders.test.js
+++ b/web/tests/recent_senders.test.js
@@ -347,4 +347,14 @@ test("process_pms", () => {
participants: [],
non_participants: [],
});
+
+ rs.process_private_message({
+ to_user_ids: "1",
+ sender_id: sender1,
+ id: 4,
+ });
+ assert.deepEqual(rs.get_pm_recent_senders("1"), {
+ participants: [1],
+ non_participants: [],
+ });
});