Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow specifying actions in custom notifications #15666

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions modules/API/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,13 @@ function initCommands() {
* Defaults to "normal" if not provided.
* @param { string } arg.timeout - Timeout type, either `short`, `medium`, `long` or `sticky`.
* Defaults to "short" if not provided.
* @param { Array<Object> } arg.customActions - An array of custom actions to be displayed in the notification.
* Each object should have a `label` and a `uuid` property. It should be used along a listener
* for the `customNotificationActionTriggered` event to handle the custom action.
* @returns {void}
*/
'show-notification': ({
customActions = [],
title,
description,
uid,
Expand All @@ -620,7 +624,15 @@ function initCommands() {
return;
}

const handlers = customActions.map(({ uuid }) => () => {
APP.API.notifyCustomNotificationActionTriggered(uuid);
});

const keys = customActions.map(({ label }) => label);

APP.store.dispatch(showNotification({
customActionHandler: handlers,
customActionNameKey: keys,
uid,
title,
description,
Expand Down Expand Up @@ -1501,6 +1513,21 @@ class API {
});
}

/**
* Notify external application (if API is enabled) that a custom notification action has been triggered.
*
* @param {string} actionUuid - The UUID of the action that has been triggered.
* @returns {void}
*/
notifyCustomNotificationActionTriggered(actionUuid) {
this._sendEvent({
name: 'custom-notification-action-triggered',
data: {
id: actionUuid
}
});
}

/**
* Notify external application (if API is enabled) that the list of sharing participants changed.
*
Expand Down
1 change: 1 addition & 0 deletions modules/API/external/external_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const events = {
'compute-pressure-changed': 'computePressureChanged',
'conference-created-timestamp': 'conferenceCreatedTimestamp',
'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
'custom-notification-action-triggered': 'customNotificationActionTriggered',
'data-channel-closed': 'dataChannelClosed',
'data-channel-opened': 'dataChannelOpened',
'device-list-changed': 'deviceListChanged',
Expand Down
Loading