Page MenuHomePhabricator

[keyserver/lib] Introduce a parseDerivedMessages function in the message specs
ClosedPublic

Authored by rohan on Oct 19 2023, 9:16 AM.
Tags
None
Referenced Files
F3396136: D9542.diff
Sun, Dec 1, 10:38 AM
Unknown Object (File)
Fri, Nov 29, 3:47 PM
Unknown Object (File)
Fri, Nov 29, 7:45 AM
Unknown Object (File)
Fri, Nov 29, 7:31 AM
Unknown Object (File)
Wed, Nov 20, 10:43 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

The last step of ENG-4849 is to simplify the derived messages logic in fetchDerivedMessages. Ideally, rather than handling parsing out the JSON object in the function itself, we'll introduce a function in specific message specs (only SIDEBAR_SOURCE and TOGGLE_PIN since those are the ones that are involved here) that, if defined, contains the logic for parsing in itself. This once again moves the source of truth to the message specs. The next diff will involve updating the callsites of rawMessageInfoFromServerDBRow to only pass in derivedMessages as a param if this function is defined in the message spec.

Resolves https://linear.app/comm/issue/ENG-5220/introduce-a-requiresderivedmessages-function-in-the-message-specs

Depends on D9538

Test Plan

Logged out requiredIDs before and after this change when loading Comm and confirmed that the Sets were the same containing the same message IDs

Diff Detail

Repository
rCOMM Comm
Branch
ENG-4849
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

rohan held this revision as a draft.

Destructure parseDerivedMessages

rohan published this revision for review.Oct 19 2023, 9:59 AM

Good to land as is

keyserver/src/fetchers/message-fetchers.js
724–728

You could do something like

messageSpecs[row.type]?.parseDerivedMessages?.(row, requiredIDs);

or maybe more realistically

const { parseDerivedMessages } = messageSpecs[row.type];
parseDerivedMessages?.(row, requiredIDs);

Whatever you prefer though, totally fine as is

lib/shared/messages/sidebar-source-message-spec.js
179–182

Should we maybe do some validation/error-handling here?

This revision is now accepted and ready to land.Oct 19 2023, 11:44 AM
lib/shared/messages/sidebar-source-message-spec.js
179–182

We could do, I just matched the same behavior that exists on master currently. We haven't had any issues with the parsing so far. I could at least catch the error and console log it