mirror of https://github.com/zulip/zulip.git
Fix bug with topic edits on read messages.
If you read a message, then got a topic edit for it, we were adding the message to our data structure of unread stream/topic messages. Now we guard against this in unread.update_unread_topics. I no longer expose an update() method in unread_topic_counter, since we really want to do the unread check at a higher level to keep other data structures consistent.
This commit is contained in:
parent
93c1790d91
commit
5608dc0add
|
@ -145,6 +145,26 @@ var zero_counts = {
|
|||
};
|
||||
unread.update_unread_topics(other_message, event);
|
||||
|
||||
// Update a message that was never marked as unread.
|
||||
var sticky_message = {
|
||||
id: 17,
|
||||
type: 'stream',
|
||||
stream_id: stream_id,
|
||||
subject: 'sticky',
|
||||
};
|
||||
|
||||
unread.process_loaded_messages([sticky_message]);
|
||||
count = unread.num_unread_for_topic(stream_id, 'sticky');
|
||||
assert.equal(count, 1);
|
||||
|
||||
unread.mark_as_read(sticky_message.id);
|
||||
count = unread.num_unread_for_topic(stream_id, 'sticky');
|
||||
assert.equal(count, 0);
|
||||
|
||||
unread.update_unread_topics(sticky_message, {subject: 'sticky'});
|
||||
count = unread.num_unread_for_topic(stream_id, 'sticky');
|
||||
assert.equal(count, 0);
|
||||
|
||||
// cleanup
|
||||
unread.mark_as_read(message.id);
|
||||
count = unread.num_unread_for_topic(stream_id, 'dinner');
|
||||
|
@ -153,6 +173,9 @@ var zero_counts = {
|
|||
unread.mark_as_read(other_message.id);
|
||||
count = unread.num_unread_for_topic(stream_id, 'snack');
|
||||
assert.equal(count, 0);
|
||||
|
||||
// test coverage
|
||||
unread.update_unread_topics(sticky_message, {});
|
||||
}());
|
||||
|
||||
stream_data.get_stream_id = function () {
|
||||
|
|
|
@ -164,11 +164,6 @@ exports.unread_topic_counter = (function () {
|
|||
bucketer.clear();
|
||||
};
|
||||
|
||||
self.update = function (msg_id, stream_id, new_topic) {
|
||||
self.del(msg_id);
|
||||
self.add(stream_id, new_topic, msg_id);
|
||||
};
|
||||
|
||||
self.add = function (stream_id, topic, msg_id) {
|
||||
bucketer.add({
|
||||
bucket_key: stream_id,
|
||||
|
@ -297,13 +292,23 @@ exports.id_flagged_as_unread = function (message_id) {
|
|||
};
|
||||
|
||||
exports.update_unread_topics = function (msg, event) {
|
||||
if (event.subject !== undefined) {
|
||||
exports.unread_topic_counter.update(
|
||||
msg.id,
|
||||
msg.stream_id,
|
||||
event.subject
|
||||
);
|
||||
if (event.subject === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unread_messages.has(msg.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
exports.unread_topic_counter.del(
|
||||
msg.id
|
||||
);
|
||||
|
||||
exports.unread_topic_counter.add(
|
||||
msg.stream_id,
|
||||
event.subject,
|
||||
msg.id
|
||||
);
|
||||
};
|
||||
|
||||
exports.process_loaded_messages = function (messages) {
|
||||
|
|
Loading…
Reference in New Issue