Page MenuHomePhabricator

[lib] Update types for SIDEBAR_SOURCE messages to reflect isInvalidSidebarSource
ClosedPublic

Authored by rohan on Sep 28 2023, 12:47 PM.
Tags
None
Referenced Files
F2900707: D9324.id32223.diff
Sat, Oct 5, 11:27 AM
F2900706: D9324.id32251.diff
Sat, Oct 5, 11:27 AM
F2900699: D9324.id31537.diff
Sat, Oct 5, 11:25 AM
Unknown Object (File)
Sun, Sep 15, 1:13 PM
Unknown Object (File)
Sun, Sep 15, 1:13 PM
Unknown Object (File)
Sun, Sep 15, 1:13 PM
Unknown Object (File)
Sun, Sep 15, 1:13 PM
Unknown Object (File)
Sun, Sep 15, 1:13 PM
Subscribers

Details

Summary

Now that isInvalidSidebarSource is currently the single source of truth for the valid/invalid message types that can be sidebar sources, it makes sense to update the types for
SidebarSourceMessageInfo SidebarSourceMessageData and RawSidebarSourceMessageInfo to reflect this.

Resolves https://linear.app/comm/issue/ENG-5207/update-types-for-sidebar-source-messages-to-reflect

Depends on D9322

Test Plan

Ran flow to confirm that updating the sourceMessage types didn't cause issues, and manually tested sidebar creation again for test / change role messages / toggle pin messages.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Sep 28 2023, 12:49 PM
Harbormaster failed remote builds in B22905: Diff 31536!

I forgot to include the changes for ValidSidebarSourceMessageInfo in the initial commit

Harbormaster returned this revision to the author for changes because remote builds failed.Sep 28 2023, 1:01 PM
Harbormaster failed remote builds in B22906: Diff 31537!
rohan requested review of this revision.Sep 28 2023, 1:34 PM

I'll rerun CI when it's back up, requesting review in the meantime

This revision is now accepted and ready to land.Sep 29 2023, 12:43 PM
lib/shared/messages/sidebar-source-message-spec.js
90–93 ↗(On Diff #31873)

This invariant feels dangerous.,. you're going to cause the keyserver to crash if a source message is not present in the database. It looks like the previous behavior was to print a warning in that case.

Can you check whether the keyserver already crashes in that scenario? If it doesn't already crash, AND you feel confident that isInvalidSidebarSource by itself should never trigger, THEN I wonder if we can change this to:

invariant(
  !sourceMessage || isInvalidSidebarSource(sourceMessage),
  'SIDEBAR_SOURCE should not point to an invalid message type',
);
lib/shared/messages/sidebar-source-message-spec.js
90–93 ↗(On Diff #31873)

Played around with rawMessageInfoFromServerDBRow, and it looks like we don't crash if sourceMessage is void/null.

I've not experienced the invariant causing a crash yet, but I'd like to ideally avoid it in the worst case. I'll probably need to figure out a better way to appease Flow then

Make return type from rawMessageInfoFromServerDBRow optional. Inspired by how we handle this in createSubThreadMessageSpec. Here, we won't cause the keyserver to crash through an invariant, and the callsites for rawMessageInfoFromServerDBRow already expect the return type to be ?RawMessageInfo

rohan requested review of this revision.Oct 17 2023, 5:09 PM

Re-requesting review because I've changed the logic here

ashoat requested changes to this revision.Oct 18 2023, 4:53 PM

CREATE_SUB_THREAD does work that way, but it's very special-cased...

One thing that's worth understanding is how unread status works in the MariaDB database. Basically we have a last_message and a last_read_message, and if they're equal the chat is deemed to be "read".

There's a risk here if we're not delivering to the user the message marked as last_message, then they won't set that message ID for last_read_message.

CREATE_SUB_THREAD is special-cased in message-creator.js not to bump last_message for users that don't have permission to see the created channel.

Note that it's also special-cased in the message-fetchers.js SQL queries, but I don't think that applies here.

Anyways, I think a better option is to keep the old behavior. If we can't get a valid source message, still return a message, but give it an undefined sourceMessage. Can you confirm that in that case, the client will still get that message, and bump last_read_message? (Or whatever that SQL column is named)

This revision now requires changes to proceed.Oct 18 2023, 4:53 PM

Address feedback. Tested against three different scenarios:

  1. Original behavior (i.e. what master looks like for rawMessageInfoFromServerDBRow)
  2. Artifically forcing sourceMessage to be undefined
  3. New behavior (the code in this diff)

In all three cases, I compared the values for last_message and last_read_message in the memberships table for a user, and observed that the values always got correctly updated in all three scenarios, both for normal text messages and when a sidebar is created. Both the rows for the sidebar in memberships and for the parent thread in memberships were always correct

lib/shared/messages/sidebar-source-message-spec.js
87 ↗(On Diff #32223)

I should be able to make this null if reviewer's feel strongly if I change

export type SidebarSourceMessageData = {
  +type: 17,
  +threadID: string,
  +creatorID: string,
  +time: number,
  +sourceMessage?: ValidRawSidebarSourceMessageInfo,
};

to

export type SidebarSourceMessageData = {
  +type: 17,
  +threadID: string,
  +creatorID: string,
  +time: number,
  +sourceMessage?: ?ValidRawSidebarSourceMessageInfo,
};
This revision is now accepted and ready to land.Oct 19 2023, 12:03 PM