MM-54443 - Fix: registerDesktopNotificationHook is missing (#23884) (#24497)

(cherry picked from commit 46a659e06d)
This commit is contained in:
Christopher Poile 2023-09-08 08:16:26 -04:00 committed by GitHub
parent 924cc0ec1a
commit 4022d2e762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1177,4 +1177,52 @@ export default class PluginRegistry {
data,
});
});
// Register a hook to intercept desktop notifications before they occur.
// Accepts a function to run before the desktop notification is triggered.
// The function has the following signature:
// (post: Post, msgProps: NewPostMessageProps, channel: Channel,
// teamId: string, args: DesktopNotificationArgs) => Promise<{
// error?: string;
// args?: DesktopNotificationArgs;
// }>)
//
// DesktopNotificationArgs is the following type:
// export type DesktopNotificationArgs = {
// title: string;
// body: string;
// silent: boolean;
// soundName: string;
// url: string;
// notify: boolean;
// };
//
// To stop a desktop notification and allow subsequent hooks to process the notification, return:
// {args: {...args, notify: false}}
// To enable a desktop notification and allow subsequent hooks to process the notification, return:
// {args: {...args, notify: true}}
// To stop a desktop notification and prevent subsequent hooks from processing the notification, return either:
// {error: 'log this error'}, or {}
// To allow subsequent hooks to process the notification, return:
// {args}, or null or undefined (thanks js)
//
// The args returned by the hook will be used as the args for the next hook, until all hooks are
// completed. The resulting args will be used as the arguments for the `notifyMe` function.
//
// Returns a unique identifier.
registerDesktopNotificationHook = reArg(['hook'], ({hook}) => {
const id = generateId();
store.dispatch({
type: ActionTypes.RECEIVED_PLUGIN_COMPONENT,
name: 'DesktopNotificationHooks',
data: {
id,
pluginId: this.id,
hook,
},
});
return id;
});
}