Skip to content

Commit

Permalink
recent_senders: Return senders in most recent sender first order.
Browse files Browse the repository at this point in the history
Since the library is named `recent_senders`, most recent sender
first order is expected from this library.
  • Loading branch information
amanagr authored and timabbott committed Dec 6, 2022
1 parent 2c0c881 commit 28c73c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions frontend_tests/node_tests/recent_senders.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ test("process_stream_message", () => {

// Test topic change
assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "3");
assert.equal(rs.get_topic_recent_senders(stream3, topic2).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream3, topic2).toString(), "3,2");

// message7's topic was changed by user
message7.topic = topic3;
Expand All @@ -240,11 +240,11 @@ test("process_stream_message", () => {
new_topic: topic3,
});

assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "3,2");
assert.equal(rs.get_topic_recent_senders(stream3, topic2).toString(), "3");

// Test stream change
assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "3,2");
assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "");

message7.stream_id = stream4;
Expand All @@ -258,10 +258,10 @@ test("process_stream_message", () => {
});

assert.equal(rs.get_topic_recent_senders(stream3, topic3).toString(), "");
assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "3,2");

// Test stream & topic change
assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "3,2");
assert.equal(rs.get_topic_recent_senders(stream5, topic4).toString(), "");

message7.stream_id = stream5;
Expand All @@ -279,8 +279,8 @@ test("process_stream_message", () => {
});

assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "");
assert.equal(rs.get_topic_recent_senders(stream5, topic4).toString(), "2,3");
assert.equal(rs.get_topic_recent_senders(stream1, topic1).toString(), "2,1");
assert.equal(rs.get_topic_recent_senders(stream5, topic4).toString(), "3,2");
assert.equal(rs.get_topic_recent_senders(stream1, topic1).toString(), "1,2");

// delete message1 and message5 sent by sender1
rs.update_topics_of_deleted_message_ids([message1.id, message5.id]);
Expand Down
2 changes: 1 addition & 1 deletion frontend_tests/node_tests/recent_topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mock_esm("../../static/js/pm_list", {
handle_narrow_deactivated: noop,
});
mock_esm("../../static/js/recent_senders", {
get_topic_recent_senders: () => [1, 2],
get_topic_recent_senders: () => [2, 1],
});
mock_esm("../../static/js/stream_data", {
is_muted: () =>
Expand Down
2 changes: 1 addition & 1 deletion static/js/recent_senders.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function get_topic_recent_senders(stream_id, topic) {
function by_max_message_id(item1, item2) {
const list1 = item1[1];
const list2 = item2[1];
return list1.max_id() - list2.max_id();
return list2.max_id() - list1.max_id();
}

const sorted_senders = Array.from(sender_dict.entries()).sort(by_max_message_id);
Expand Down
8 changes: 6 additions & 2 deletions static/js/recent_topics_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,12 @@ function format_conversation(conversation_data) {
context.topic,
);

// Display in most recent sender first order
all_senders = recent_senders.get_topic_recent_senders(context.stream_id, context.topic);
// Since the css for displaying senders in reverse order is much simpler,
// we provide our handlebars with senders in opposite order.
// Display in most recent sender first order.
all_senders = recent_senders
.get_topic_recent_senders(context.stream_id, context.topic)
.reverse();
senders = all_senders.slice(-MAX_AVATAR);

// Collect extra sender fullname for tooltip
Expand Down

0 comments on commit 28c73c6

Please sign in to comment.