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

This caused double user avatar to appear in recent conversations
for when showing user PM to self.
This commit is contained in:
Aman Agrawal
2023-02-22 04:45:38 +00:00
committed by Tim Abbott
parent f62b55a5cf
commit 66b593e505
2 changed files with 21 additions and 2 deletions

View File

@@ -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: [],
});
});

View File

@@ -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);