DEV: Plugin API to add desktop notification handlers (#15280)
This commit is contained in:
parent
08f4edc032
commit
53475cf5be
|
@ -19,6 +19,14 @@ const idleThresholdTime = 1000 * 10; // 10 seconds
|
|||
const context = "discourse_desktop_notifications_";
|
||||
const keyValueStore = new KeyValueStore(context);
|
||||
|
||||
let desktopNotificationHandlers = [];
|
||||
export function registerDesktopNotificationHandler(handler) {
|
||||
desktopNotificationHandlers.push(handler);
|
||||
}
|
||||
export function clearDesktopNotificationHandlers() {
|
||||
desktopNotificationHandlers = [];
|
||||
}
|
||||
|
||||
// Called from an initializer
|
||||
function init(messageBus, appEvents) {
|
||||
liveEnabled = false;
|
||||
|
@ -176,11 +184,14 @@ function onNotification(data, siteSettings, user) {
|
|||
icon: notificationIcon,
|
||||
tag: notificationTag,
|
||||
});
|
||||
|
||||
notification.onclick = () => {
|
||||
DiscourseURL.routeTo(data.post_url);
|
||||
notification.close();
|
||||
};
|
||||
|
||||
desktopNotificationHandlers.forEach((handler) =>
|
||||
handler(data, siteSettings, user)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ import { registerCustomPostMessageCallback as registerCustomPostMessageCallback1
|
|||
import { registerHighlightJSLanguage } from "discourse/lib/highlight-syntax";
|
||||
import { registerTopicFooterButton } from "discourse/lib/register-topic-footer-button";
|
||||
import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown";
|
||||
import { registerDesktopNotificationHandler } from "discourse/lib/desktop-notifications";
|
||||
import { replaceFormatter } from "discourse/lib/utilities";
|
||||
import { replaceTagRenderer } from "discourse/lib/render-tag";
|
||||
import { setNewCategoryDefaultColors } from "discourse/routes/new-category";
|
||||
|
@ -775,6 +776,19 @@ class PluginApi {
|
|||
registerTopicFooterDropdown(dropdownOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a desktop notificaiton handler
|
||||
*
|
||||
* ```javascript
|
||||
* api.registerDesktopNotificationHandler((data, siteSettings, user) => {
|
||||
* // Do something!
|
||||
* });
|
||||
* ```
|
||||
**/
|
||||
registerDesktopNotificationHandler(handler) {
|
||||
registerDesktopNotificationHandler(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a small icon to be used for custom small post actions
|
||||
*
|
||||
|
|
|
@ -53,6 +53,7 @@ import { resetLastEditNotificationClick } from "discourse/models/post-stream";
|
|||
import { clearAuthMethods } from "discourse/models/login-method";
|
||||
import { clearTopicFooterDropdowns } from "discourse/lib/register-topic-footer-dropdown";
|
||||
import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
|
||||
import { clearDesktopNotificationHandlers } from "discourse/lib/desktop-notifications";
|
||||
import {
|
||||
clearPresenceCallbacks,
|
||||
setTestPresence,
|
||||
|
@ -297,6 +298,7 @@ export function acceptance(name, optionsOrCallback) {
|
|||
cleanUpComposerUploadPreProcessor();
|
||||
clearTopicFooterDropdowns();
|
||||
clearTopicFooterButtons();
|
||||
clearDesktopNotificationHandlers();
|
||||
resetLastEditNotificationClick();
|
||||
clearAuthMethods();
|
||||
setTestPresence(true);
|
||||
|
|
Loading…
Reference in New Issue