[MM-57348] Change result to status as a better descriptor of the notification status (#3005)

This commit is contained in:
Devin Binnie 2024-04-12 09:06:33 -04:00 committed by GitHub
parent 125ff06481
commit 1eda09ae25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 16 additions and 16 deletions

View file

@ -30,7 +30,7 @@ export type DesktopAPI = {
onLogout: () => void; onLogout: () => void;
// Unreads/mentions/notifications // Unreads/mentions/notifications
sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => Promise<{result: string; reason?: string; data?: string}>; sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => Promise<{status: string; reason?: string; data?: string}>;
onNotificationClicked: (listener: (channelId: string, teamId: string, url: string) => void) => () => void; onNotificationClicked: (listener: (channelId: string, teamId: string, url: string) => void) => () => void;
setUnreadsAndMentions: (isUnread: boolean, mentionCount: number) => void; setUnreadsAndMentions: (isUnread: boolean, mentionCount: number) => void;

View file

@ -23,7 +23,7 @@ export type DesktopAPI = {
onLogin: () => void; onLogin: () => void;
onLogout: () => void; onLogout: () => void;
sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => Promise<{ sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => Promise<{
result: string; status: string;
reason?: string; reason?: string;
data?: string; data?: string;
}>; }>;

View file

@ -1,12 +1,12 @@
{ {
"name": "@mattermost/desktop-api", "name": "@mattermost/desktop-api",
"version": "5.8.0-1", "version": "5.8.0-5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@mattermost/desktop-api", "name": "@mattermost/desktop-api",
"version": "5.8.0-1", "version": "5.8.0-5",
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {
"typescript": "^4.3.0 || ^5.0.0" "typescript": "^4.3.0 || ^5.0.0"

View file

@ -1,6 +1,6 @@
{ {
"name": "@mattermost/desktop-api", "name": "@mattermost/desktop-api",
"version": "5.8.0-4", "version": "5.8.0-5",
"description": "Shared types for the Desktop App API provided to the Web App", "description": "Shared types for the Desktop App API provided to the Web App",
"keywords": [ "keywords": [
"mattermost" "mattermost"
@ -29,6 +29,6 @@
"build": "tsc --build --verbose", "build": "tsc --build --verbose",
"run": "tsc --watch --preserveWatchOutput", "run": "tsc --watch --preserveWatchOutput",
"clean": "rm -rf tsconfig.tsbuildinfo ./lib", "clean": "rm -rf tsconfig.tsbuildinfo ./lib",
"prepublish": "npm run build && rm -rf tsconfig.tsbuildinfo" "prepublishOnly": "npm run build && rm -rf ./lib/tsconfig.tsbuildinfo"
} }
} }

2
package-lock.json generated
View file

@ -102,7 +102,7 @@
}, },
"api-types": { "api-types": {
"name": "@mattermost/desktop-api", "name": "@mattermost/desktop-api",
"version": "5.8.0-4", "version": "5.8.0-5",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"peerDependencies": { "peerDependencies": {

View file

@ -32,19 +32,19 @@ class NotificationManager {
if (!Notification.isSupported()) { if (!Notification.isSupported()) {
log.error('notification not supported'); log.error('notification not supported');
return {result: 'error', reason: 'notification_api', data: 'notification not supported'}; return {status: 'error', reason: 'notification_api', data: 'notification not supported'};
} }
if (await getDoNotDisturb()) { if (await getDoNotDisturb()) {
return {result: 'not_sent', reason: 'os_dnd'}; return {status: 'not_sent', reason: 'os_dnd'};
} }
const view = ViewManager.getViewByWebContentsId(webcontents.id); const view = ViewManager.getViewByWebContentsId(webcontents.id);
if (!view) { if (!view) {
return {result: 'error', reason: 'missing_view'}; return {status: 'error', reason: 'missing_view'};
} }
if (!view.view.shouldNotify) { if (!view.view.shouldNotify) {
return {result: 'error', reason: 'view_should_not_notify'}; return {status: 'error', reason: 'view_should_not_notify'};
} }
const serverName = view.view.server.name; const serverName = view.view.server.name;
@ -56,7 +56,7 @@ class NotificationManager {
}; };
if (!await PermissionsManager.doPermissionRequest(webcontents.id, 'notifications', view.view.server.url.toString())) { if (!await PermissionsManager.doPermissionRequest(webcontents.id, 'notifications', view.view.server.url.toString())) {
return {result: 'not_sent', reason: 'notifications_permission_disallowed'}; return {status: 'not_sent', reason: 'notifications_permission_disallowed'};
} }
const mention = new Mention(options, channelId, teamId); const mention = new Mention(options, channelId, teamId);
@ -81,7 +81,7 @@ class NotificationManager {
return new Promise((resolve) => { return new Promise((resolve) => {
// If mention never shows somehow, resolve the promise after 10s // If mention never shows somehow, resolve the promise after 10s
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
resolve({result: 'error', reason: 'notification_timeout'}); resolve({status: 'error', reason: 'notification_timeout'});
}, 10000); }, 10000);
mention.on('show', () => { mention.on('show', () => {
@ -102,13 +102,13 @@ class NotificationManager {
} }
flashFrame(true); flashFrame(true);
clearTimeout(timeout); clearTimeout(timeout);
resolve({result: 'success'}); resolve({status: 'success'});
}); });
mention.on('failed', (_, error) => { mention.on('failed', (_, error) => {
this.allActiveNotifications.delete(mention.uId); this.allActiveNotifications.delete(mention.uId);
clearTimeout(timeout); clearTimeout(timeout);
resolve({result: 'error', reason: 'electron_notification_failed', data: error}); resolve({status: 'error', reason: 'electron_notification_failed', data: error});
}); });
mention.show(); mention.show();
}); });

View file

@ -456,7 +456,7 @@ export class MainWindow extends EventEmitter {
if (this.isMaximized && !this.win?.isMaximized()) { if (this.isMaximized && !this.win?.isMaximized()) {
this.win?.maximize(); this.win?.maximize();
} }
} };
private onEnterFullScreen = () => { private onEnterFullScreen = () => {
this.win?.webContents.send('enter-full-screen'); this.win?.webContents.send('enter-full-screen');