unread: Handle message edits that affect mentions.

We had a bug where if your peer mentioned you in
message, but then edited the message not to mention
you, the latter wouldn't reset your unread counts
for "Mentions".  And the same problem would happen
vice versa.

The fix basically extracts `update_message_for_mention`
and makes sure it handles all combinations of
unread/mentioned flags, instead of assuming
any invariants about which directions of change
are possible.

And then we call that new function from
`message_events.js` whenever we get message
edit events.

Fixes #14544
This commit is contained in:
Steve Howell
2020-04-11 00:51:45 +00:00
committed by Tim Abbott
parent 32157ed6fd
commit 888214196c
4 changed files with 62 additions and 7 deletions

View File

@@ -553,6 +553,40 @@ run_test('mentions', () => {
test_notifiable_count(counts.home_unread_messages, 0);
});
run_test('mention updates', () => {
const message = {
id: 17,
unread: false,
type: 'stream',
};
function test_counted(counted) {
unread.update_message_for_mention(message);
assert.equal(
unread.unread_mentions_counter.has(message.id),
counted
);
}
test_counted(false);
message.unread = true;
message.mentioned = true;
test_counted(true);
message.mentioned = false;
test_counted(false);
message.mentioned = true;
test_counted(true);
message.unread = false;
test_counted(false);
message.unread = true;
test_counted(true);
});
run_test('starring', () => {
// We don't need any setup here, because we just hard code
// this to [] in the code.