Page MenuHomePhabricator

[keyserver] reaction messages only notifiy author of target message
ClosedPublic

Authored by ginsu on Jan 5 2023, 1:57 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 30, 7:18 PM
Unknown Object (File)
Sat, Nov 30, 7:18 PM
Unknown Object (File)
Sat, Nov 30, 7:18 PM
Unknown Object (File)
Sat, Nov 30, 10:10 AM
Unknown Object (File)
Sat, Nov 30, 10:10 AM
Unknown Object (File)
Sat, Nov 30, 10:10 AM
Unknown Object (File)
Sat, Nov 30, 10:10 AM
Unknown Object (File)
Nov 9 2024, 2:31 AM
Subscribers

Details

Summary

Reaction messages only notify author of target message. This is done by fetching the target message info and checking if the creatorID of the target message is the same as the userID of the user recieving the notif


Linear Task: ENG-2616

Test Plan

Please watch the demo video to see the changes I made. For additional context ginsu is signed in to the simulator on the left and dan is signed into the simulator on the right

Diff Detail

Repository
rCOMM Comm
Branch
ashoat/generatesNotifs
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

ginsu edited the test plan for this revision. (Show Details)
ginsu added reviewers: atul, tomek.
ginsu requested review of this revision.Jan 5 2023, 2:11 PM
ashoat requested changes to this revision.Jan 5 2023, 4:29 PM
ashoat added inline comments.
keyserver/src/creators/message-creator.js
384 ↗(On Diff #20634)

We should avoid checking types in this file... instead, if we want to introduce some message-type-specific functionality, we should introduce it on the message specs. Keeping all message-type-specific functionality in the message specs makes it way easier and less messy to introduce new message types

385 ↗(On Diff #20634)

You're doing a sequential await nested inside three for statements. It will execute one-by-one for every leaf. This is really bad for performance

This revision now requires changes to proceed.Jan 5 2023, 4:29 PM

address ashoat's comments

keyserver/src/creators/message-creator.js
384 ↗(On Diff #20634)

Writing a follow-up diff rn to address this!

ashoat requested changes to this revision.Jan 9 2023, 7:52 PM

Prefer you squash the changes into here instead of a follow-up diff, but if you feel strongly we can do it as two separate diffs... I'll just need to see the follow-up before I can accept this one. Requesting changes until the comments are addressed

This revision now requires changes to proceed.Jan 9 2023, 7:52 PM
tomek requested changes to this revision.Jan 10 2023, 10:56 AM
tomek added inline comments.
keyserver/src/creators/message-creator.js
387 ↗(On Diff #20745)

Is it really correct? We're overriding the promise in every iteration.

keyserver/src/creators/message-creator.js
387 ↗(On Diff #20745)

Oh yeah, this makes sense. @ginsu you might need a quick primer on Promises + async/await, maybe we can talk about this in person

387 ↗(On Diff #20745)

*This doesn't make sense

Remove errant console.log

The next iteration here might be to make generatesNotifs return a enum, eg. pushType.NOTIF, pushType.RESCIND, or undefined

tomek added inline comments.
keyserver/src/creators/message-creator.js
396–397 ↗(On Diff #20770)

Having this function as a parameter sounds really generic - usually creating a notification should be based on a message and at most one other message, but here we allow fetching a lot of different messages.

In the future we can address this by being more specific when defining the relationship between messages. Currently, only two types reference other messages: reaction and sidebar source. Also editing and deleting messages would reference a message. So it looks like a common part is that all of these types reference exactly one message. It means that we can make this relationship more explicit by creating a single field (e.g. targetMessage) that all the messages can have and pass it as a parameter here instead of this function.

An alternative might be to make ReactionMessageInfo consistent with our current approach: in SidebarSourceMessageInfo there's a field sourceMessage which is a message info, but in ReactionMessageInfo we have only targetMessageID which is an id. If we had a full message info, we wouldn't need a function here.

There are a couple of downsides of the current approach. One is that for each notification we need to send a separate request to our db which might have a performance impact. For SIDEBAR_SOURCE we solved this issue by introducing fetchDerivedMessages function and using its result in rawMessageInfoFromServerDBRow. We probably should use the same mechanism here.

This revision is now accepted and ready to land.Jan 11 2023, 2:37 AM
keyserver/src/creators/message-creator.js
396–397 ↗(On Diff #20770)

In the future we can address this by being more specific when defining the relationship between messages. Currently, only two types reference other messages: reaction and sidebar source. Also editing and deleting messages would reference a message. So it looks like a common part is that all of these types reference exactly one message. It means that we can make this relationship more explicit by creating a single field (e.g. targetMessage) that all the messages can have and pass it as a parameter here instead of this function.

An alternative might be to make ReactionMessageInfo consistent with our current approach: in SidebarSourceMessageInfo there's a field sourceMessage which is a message info, but in ReactionMessageInfo we have only targetMessageID which is an id. If we had a full message info, we wouldn't need a function here.

Yeah, that's fair. To make that work we would still need to individually fetch the source message – for SidebarSourceMessageInfo we do that here in createThread, and we pass it into MessageData before we call createMessages.

Consistency is definitely a good reason to do it the same way, but it would've probably been more complicated to refactor the reaction message types here. This ideally would've been something we considered back when we defined those types.

There are a couple of downsides of the current approach. One is that for each notification we need to send a separate request to our db which might have a performance impact. For SIDEBAR_SOURCE we solved this issue by introducing fetchDerivedMessages function and using its result in rawMessageInfoFromServerDBRow. We probably should use the same mechanism here.

I don't think we use fetchDerivedMessages / rawMessageInfoFromServerDBRow in the workflow that creates SIDEBAR_SOURCE... instead, we call fetchMessageInfoByID before calling createMessages (see link above). I could imagine us refactoring this if we ever needed to create multiple SIDEBAR_SOURCE messages, but as it stands we only ever create one SIDEBAR_SOURCE (and one REACTION) at a time, so the performance impact is the same.

keyserver/src/creators/message-creator.js
396–397 ↗(On Diff #20770)

Going to land for now, but if refactoring targetMessageID to something like targetMessage or sourceMessage is something we want to do in the future, I can create a task to track it

keyserver/src/creators/message-creator.js
396–397 ↗(On Diff #20770)

Ok, that makes sense. Let's keep it for now - I don't think it really makes sense to refactor it soon.