Page MenuHomePhabricator

[keyserver] Code for updating last_message_for_unread_check
ClosedPublic

Authored by ashoat on Feb 10 2025, 11:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Mar 11, 3:49 PM
Unknown Object (File)
Tue, Mar 11, 3:40 PM
Unknown Object (File)
Feb 26 2025, 10:36 PM
Unknown Object (File)
Feb 26 2025, 11:03 AM
Unknown Object (File)
Feb 24 2025, 9:36 PM
Unknown Object (File)
Feb 24 2025, 3:25 AM
Unknown Object (File)
Feb 22 2025, 9:20 PM
Unknown Object (File)
Feb 22 2025, 9:20 PM
Subscribers
None

Details

Summary

This diff sets up code for keeping last_message_for_unread_check updated, but does not (yet) support excluding certain message types as outlined in ENG-9557.

We are doing one of two things for each change:

  1. Setting last_message_for_unread_check to the same value as last_message
  2. Where appropriate, replacing a get or set of last_message with a set of last_message_for_unread_check. I will explain these inline

Depends on D14328

Test Plan

Tested in combination with later diffs, to confirm that it's possible for some message types to not set a thread to unread

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

keyserver/src/creators/message-creator.js
668 ↗(On Diff #46977)

The changes here simply set last_message_for_unread_check to the same value as last_message (though this will change in a later diff)

keyserver/src/updaters/activity-updaters.js
164–166 ↗(On Diff #46977)

This is the only place where lastMessage (the one changed below) is used. It's used to determine what to set last_read_message to. Since this value is compared to last_message_for_unread_check now, it makes sense to set it based on that. Ultimately it's not super important, but I think this is the more "correct" approach

507 ↗(On Diff #46977)

The changes here update us to use last_message_for_unread_check instead of last_message. See comment above (in same file) for how this is used

keyserver/src/updaters/thread-permission-updaters.js
961 ↗(On Diff #46977)

I removed this line (and last_read_message below) because it already the DEFAULT value for the column, so there's no point specifying it

976 ↗(On Diff #46977)

I replaced last_message with last_message_for_unread_check here because:

  1. last_message only exists to join a message with that ID, and no message with ID 0 exists
  2. We want to set last_message_for_unread_check so that the thread might appear unread in the case of rowToSave.unread
1010–1062 ↗(On Diff #46977)

This query was introduced in D9598 to address ENG-4101.

There was some complexity here to deal with the fact that last_message was previously used for two things. The query needed to set last_message correctly to make sure we could fetch at least one message for the thread, but that previously meant we also needed to set last_read_message correctly, so that the thread unread status would appear correctly.

Now that last_message isn't used for the unread status, we don't have to set last_read_message in this query, and can rely on the approach in the INSERT above (leaving last_read_message as 0, and setting last_message_for_unread_check to either 0 or 1, depending on whether the thread should appear as unread).

1061–1078 ↗(On Diff #46977)

Here, we simply set last_message_for_unread_check to the same value as last_read_message when a user leaves a thread, so that we can make sure that the thread is "marked as read". It doesn't particularly matter as this doesn't appear in the UI, but it seemed like the "correct" thing to do

This revision is now accepted and ready to land.Feb 11 2025, 5:15 AM