DEV: APIs to disable PWA badging and unsubscribe from user notifications (#14595)

This commit is contained in:
Mark VanLandingham 2021-10-13 11:47:30 -05:00 committed by GitHub
parent bc68da24cd
commit e1d3175668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -1,12 +1,19 @@
// Updates the PWA badging if available // Updates the PWA badging if available
let defaultBadgingDisabled = false;
export function disableDefaultBadging() {
defaultBadgingDisabled = true;
}
export default { export default {
name: "badging", name: "badging",
after: "message-bus", after: "message-bus",
initialize(container) { initialize(container) {
if (!navigator.setAppBadge) { // must have the Badging API
if (defaultBadgingDisabled || !navigator.setAppBadge) {
return; return;
} // must have the Badging API }
const user = container.lookup("current-user:main"); const user = container.lookup("current-user:main");
if (!user) { if (!user) {

View File

@ -13,11 +13,20 @@ import {
} from "discourse/lib/push-notifications"; } from "discourse/lib/push-notifications";
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
let subscribeToNotifications = true;
export function unsubscribeFromNotifications() {
subscribeToNotifications = false;
}
export default { export default {
name: "subscribe-user-notifications", name: "subscribe-user-notifications",
after: "message-bus", after: "message-bus",
initialize(container) { initialize(container) {
if (!subscribeToNotifications) {
return;
}
const user = container.lookup("current-user:main"); const user = container.lookup("current-user:main");
const bus = container.lookup("message-bus:main"); const bus = container.lookup("message-bus:main");
const appEvents = container.lookup("service:app-events"); const appEvents = container.lookup("service:app-events");

View File

@ -90,6 +90,8 @@ import {
addSearchSuggestion, addSearchSuggestion,
} from "discourse/widgets/search-menu-results"; } from "discourse/widgets/search-menu-results";
import { CUSTOM_USER_SEARCH_OPTIONS } from "select-kit/components/user-chooser"; import { CUSTOM_USER_SEARCH_OPTIONS } from "select-kit/components/user-chooser";
import { unsubscribeFromNotifications } from "discourse/initializers/subscribe-user-notifications";
import { disableDefaultBadging } from "discourse/initializers/badging";
// If you add any methods to the API ensure you bump up this number // If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = "0.12.6"; const PLUGIN_API_VERSION = "0.12.6";
@ -1495,6 +1497,14 @@ class PluginApi {
{ ignoreMissing: true } { ignoreMissing: true }
); );
} }
// Stops the subscribe-user-notifications initializer from listening to notifications
unsubscribeFromNotifications() {
unsubscribeFromNotifications();
}
// Stops the badging initializer from updating the PWA badge with the user's notification count
disableDefaultBadging() {
disableDefaultBadging();
}
/** /**
* Support for customizing the composer text. By providing a callback. Callbacks should * Support for customizing the composer text. By providing a callback. Callbacks should