Page MenuHomePhabricator

[keyserver/lib] Update isInvalidSidebarSource to check messageSpec.canBeSidebarSource
ClosedPublic

Authored by rohan on Sep 29 2023, 8:35 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 29, 9:17 PM
Unknown Object (File)
Fri, Nov 29, 9:47 AM
Unknown Object (File)
Fri, Nov 29, 7:31 AM
Unknown Object (File)
Fri, Nov 22, 7:22 AM
Unknown Object (File)
Thu, Nov 21, 2:17 PM
Unknown Object (File)
Wed, Nov 20, 4:38 PM
Unknown Object (File)
Wed, Nov 20, 4:38 PM
Unknown Object (File)
Wed, Nov 20, 4:38 PM
Subscribers

Details

Summary

Now that existing message specs each have a canBeSidebarSource method, I need to update the function isInvalidSidebarSource to check messageSpec.canBeSidebarSource.

Resolves https://linear.app/comm/issue/ENG-5209/update-isinvalidsidebarsource-to-check-messagespeccanbesidebarsource

Depends on D9325

Test Plan

Ran flow and manually tested sidebar creation on a variety of message robotext types & text messages

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

rohan requested review of this revision.Sep 29 2023, 8:54 AM

Update isInvalidSidebarSource

rohan retitled this revision from [keyserver/lib] Replace most instances of isInvalidSidebarSource with canBeSidebarSource to [keyserver/lib] Update isInvalidSidebarSource to check messageSpec.canBeSidebarSource.
rohan edited the summary of this revision. (Show Details)

Update isInvalidSidebarSource to pass unit tests

lib/shared/message-utils.js
662–667 ↗(On Diff #31875)

Ideally, I would just check messageSpecs[message.type].canBeSidebarSource. Doing this though causes several flow issues throughout the message-fetchers.js since type refinement doesn't occur without explicitly checking for types.

I couldn't think of a better solution to the Flow issue, but we're safeguarded by the unit tests testing both isInvalidSidebarSource and messageSpec.canBeSidebarSource anyways

lib/shared/message-utils.js
662–667 ↗(On Diff #31875)

Update: I think this check can actually be simplified back down to !messageSpecs[message.type].canBeSidebarSource once ENG-5215 is done since that should remove the use case of this function in message-fetchers. For now to pass flow checks I'll need to keep it though (ENG-5215 will come after this in the stack, so I'll fix this check then if it can be done)

ashoat added inline comments.
lib/shared/message-utils.js
662–667 ↗(On Diff #31875)

Just wondering, how does Flow feel about the following?

if (messageSpecs[message.type].canBeSidebarSource) {
  return false;
}
invariant(
  message.type === messageTypes.REACTION ||
    message.type === messageTypes.EDIT_MESSAGE ||
    message.type === messageTypes.SIDEBAR_SOURCE ||
    message.type === messageTypes.TOGGLE_PIN,
  "only four types canBeSidebarSource",
);
return true;
This revision is now accepted and ready to land.Oct 14 2023, 10:15 AM
lib/shared/message-utils.js
662–667 ↗(On Diff #31875)

Thanks for the suggestion, though when I tried it I got the same Flow warnings as just doing

function isInvalidSidebarSource(
  message: RawMessageInfo | MessageInfo,
): boolean {
    return messageSpecs[message.type].canBeSidebarSource;
}