Page MenuHomePhabricator

Implement main <-> renderer IPC and use it to decrypt notifications
ClosedPublic

Authored by marcin on Nov 23 2023, 9:01 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 14, 3:11 AM
Unknown Object (File)
Mon, Apr 22, 12:47 PM
Unknown Object (File)
Mon, Apr 22, 12:47 PM
Unknown Object (File)
Mon, Apr 22, 12:47 PM
Unknown Object (File)
Mon, Apr 22, 12:47 PM
Unknown Object (File)
Mon, Apr 22, 12:47 PM
Unknown Object (File)
Mon, Apr 22, 12:46 PM
Unknown Object (File)
Mon, Apr 22, 12:42 PM
Subscribers

Details

Summary

This differential implements main <-> rendered IPC and uses it combined with decryption function from previous differential to decrypt notifications. In
summary notification decryption workflow is as follows:

  1. Desktop code in push-notifications.js receives notification and checks that it is encrypted (encryptedPayload) field.
  2. Sends decrypted payload to renderer process (web app) using onEncryptedNotification IPC.
  3. Renderer receives it in callback registered in push-notifs-handler.js in web code. In this callback it decrypts payload using decryptDesktopNotification

function.

  1. Decrypted notification is sent to main process using showDecryptedNotification IPC.
  2. Main process receives decrypted notification in ipcMain.on('show-decrypted-notification', (...) => {...}) where it shows notification.
Test Plan
  1. Apply this patch to local keyserver (it basically enables session establishment for desktop device and encrypts notification):

https://gist.github.com/marcinwasowicz/2df9c9bd4491862173241744d54a016f

  1. Send some notifications.
  2. Ensure they are correctly displayed and olm session version for currently logged user in desktop app increments with each notification.

With this differential we can also test large influx of out of order notifications (https://linear.app/comm/issue/ENG-5385/handle-large-number-of-out-of-order-notifications-incoming-afer-long).

  1. Apply this patch on top of first patch to your local keyserver (it artificially calls multiple sendPushNotifs promises on single message): https://gist.github.com/marcinwasowicz/673b62b70998588a7e6f4be31bddd2c8
  2. Send message.
  3. Ensure all notifications that arrive are correctly decrypted.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Accepting, but please fix the issues in inline comments.

web/push-notif/push-notifs-handler.js
49–57 ↗(On Diff #33575)

electron?.onX functions return a function that unregister the listener.
This is the () => void in electron-types.js and return () => ipcRenderer.removeListener('on-encrypted-notification', withEvent); in preload.js

We can return a cleanup function from useEffect to be called whenever we re-run it.

Alternatively we can write

React.useEffect(() => {
   const cleanupFunction = electron?.onEncryptedNotification(...);
   return cleanupFunction;
}, [staffCanSee])
55 ↗(On Diff #33575)

I don't think this await is needed here

This revision is now accepted and ready to land.Nov 24 2023, 6:13 AM
web/push-notif/push-notifs-handler.js
49–57 ↗(On Diff #33575)

Your first suggestion results in eslint error:

React Hook useEffect received a function whose dependencies are unknown. Pass an inline function instead.

That said I went ahead with the second option.

web/push-notif/push-notifs-handler.js
49–57 ↗(On Diff #33575)

Please ignore the comment above - it resulted from my mistake.

Return cleanup function fore effect