mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
recent_senders: Update data structures for stream/topic edits.
* Remove old topic and reprocess both old and new topic to ensure that we are correctly storing the last_msg_id of users in the topic. Also, Handle topic's stream (& topic) edit updates. * Add function to get all messages in a topic in message_utils.js. * Send topic edit event to recent_senders. * Add func get sorted list of recent_senders to topic. The function will be useful to handle topic edits in Recent Topic UI.
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
const rs = zrequire('recent_senders');
|
||||
|
||||
let next_id = 0;
|
||||
const messages = [];
|
||||
|
||||
set_global('message_util', {
|
||||
get_messages_in_topic: (stream_id, topic) => {
|
||||
return messages.filter(x => {
|
||||
return x.stream_id === stream_id &&
|
||||
x.topic.toLowerCase() === topic.toLowerCase();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
run_test('process_message_for_senders', () => {
|
||||
const stream1 = 1;
|
||||
@@ -10,10 +20,13 @@ run_test('process_message_for_senders', () => {
|
||||
const topic1 = "topic-1";
|
||||
const topic2 = "topic-2";
|
||||
const topic3 = "topic-3";
|
||||
const topic4 = "topic-4";
|
||||
|
||||
const sender1 = 1;
|
||||
const sender2 = 2;
|
||||
const sender3 = 3;
|
||||
const stream4 = 4;
|
||||
const stream5 = 5;
|
||||
|
||||
// New stream
|
||||
const message1 = {
|
||||
@@ -28,6 +41,8 @@ run_test('process_message_for_senders', () => {
|
||||
topic: topic1,
|
||||
sender_id: sender2,
|
||||
};
|
||||
messages.push(message1, message2);
|
||||
|
||||
rs.process_message_for_senders(message1);
|
||||
rs.process_message_for_senders(message2);
|
||||
|
||||
@@ -51,6 +66,8 @@ run_test('process_message_for_senders', () => {
|
||||
topic: topic2,
|
||||
sender_id: sender3,
|
||||
};
|
||||
messages.push(message3);
|
||||
|
||||
rs.process_message_for_senders(message3);
|
||||
assert.equal(
|
||||
rs.compare_by_recency({user_id: sender3}, {user_id: sender2}, stream1, topic2) < 0,
|
||||
@@ -63,6 +80,8 @@ run_test('process_message_for_senders', () => {
|
||||
topic: topic1,
|
||||
sender_id: sender2,
|
||||
};
|
||||
messages.push(message4);
|
||||
|
||||
rs.process_message_for_senders(message4);
|
||||
assert.equal(
|
||||
rs.compare_by_recency({user_id: sender1}, {user_id: sender2}, stream1, topic1) > 0,
|
||||
@@ -75,6 +94,8 @@ run_test('process_message_for_senders', () => {
|
||||
topic: topic1,
|
||||
sender_id: sender1,
|
||||
};
|
||||
messages.push(message5);
|
||||
|
||||
rs.process_message_for_senders(message5);
|
||||
assert.equal(
|
||||
rs.compare_by_recency({user_id: sender1}, {user_id: sender2}, stream1, topic1) < 0,
|
||||
@@ -99,6 +120,7 @@ run_test('process_message_for_senders', () => {
|
||||
topic: topic3,
|
||||
sender_id: sender3,
|
||||
};
|
||||
messages.push(message6, message7, message8);
|
||||
|
||||
rs.process_message_for_senders(message6);
|
||||
rs.process_message_for_senders(message7);
|
||||
@@ -113,4 +135,72 @@ run_test('process_message_for_senders', () => {
|
||||
true);
|
||||
|
||||
assert.equal(rs.compare_by_recency({}, {}, next_id += 1, ''), 0);
|
||||
|
||||
// new message in topic2
|
||||
const message9 = {
|
||||
stream_id: stream3,
|
||||
id: next_id += 1,
|
||||
topic: topic2,
|
||||
sender_id: sender3,
|
||||
};
|
||||
messages.push(message9);
|
||||
|
||||
rs.process_message_for_senders(message9);
|
||||
|
||||
// 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'
|
||||
);
|
||||
|
||||
// message7's topic was changed by user
|
||||
messages[6].topic = topic3;
|
||||
|
||||
rs.process_topic_edit(stream3, topic2, topic3);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream3, topic3).toString(), '2,3'
|
||||
);
|
||||
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(stream4, topic3).toString(), ''
|
||||
);
|
||||
// stream of topic3 was changed to stream4.
|
||||
messages[6].stream_id = stream4; // message7's topic is topic3
|
||||
messages[7].stream_id = stream4;
|
||||
rs.process_topic_edit(stream3, topic3, topic3, stream4);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream3, topic3).toString(), ''
|
||||
);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream4, topic3).toString(), '2,3'
|
||||
);
|
||||
|
||||
// Test stream & topic change
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream4, topic3).toString(), '2,3'
|
||||
);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream5, topic4).toString(), ''
|
||||
);
|
||||
// stream of topic3 was changed to stream5 and topic was changed to topic4.
|
||||
messages[6].stream_id = stream5;
|
||||
messages[7].stream_id = stream5;
|
||||
messages[6].topic = topic4;
|
||||
messages[7].topic = topic4;
|
||||
rs.process_topic_edit(stream4, topic3, topic4, stream5);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream4, topic3).toString(), ''
|
||||
);
|
||||
assert.equal(
|
||||
rs.get_topic_recent_senders(stream5, topic4).toString(), '2,3'
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user