From ead342b52dc6727fe8f3f96f0e7aa8b61273ef5c Mon Sep 17 00:00:00 2001 From: "anton.buksa" Date: Thu, 11 Apr 2024 10:21:18 +0200 Subject: [PATCH] handle bridge dnd event Changelog: added --- webapp/channels/package.json | 2 +- .../src/actions/ksuite_bridge_actions.ts | 17 +++++++++++++---- .../src/actions/notification_actions.jsx | 7 +++---- .../src/reducers/plugins/ksuite_bridge.ts | 10 ++++++++++ webapp/channels/src/selectors/ksuite_bridge.ts | 4 ++++ webapp/channels/src/types/store/index.ts | 1 + webapp/channels/src/utils/constants.tsx | 1 + yarn.lock | 10 +++++----- 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/webapp/channels/package.json b/webapp/channels/package.json index e3e2831982..cfd2e413b6 100644 --- a/webapp/channels/package.json +++ b/webapp/channels/package.json @@ -14,7 +14,7 @@ "@infomaniak/compass-components": "0.17.0", "@infomaniak/compass-icons": "0.13.0", "@infomaniak/font-suisse": "https://verdaccio.dev.infomaniak.ch/@infomaniak/font-suisse/-/font-suisse-1.0.0.tgz", - "@infomaniak/ksuite-bridge": "https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.2.7.tgz", + "@infomaniak/ksuite-bridge": "https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.3.1.tgz", "@infomaniak/marked": "^0.2.0", "@infomaniak/mattermost-client": "workspace:webapp/platform/client", "@infomaniak/mattermost-types": "workspace:webapp/platform/types", diff --git a/webapp/channels/src/actions/ksuite_bridge_actions.ts b/webapp/channels/src/actions/ksuite_bridge_actions.ts index 7a347c8f81..6a21b0ec81 100644 --- a/webapp/channels/src/actions/ksuite_bridge_actions.ts +++ b/webapp/channels/src/actions/ksuite_bridge_actions.ts @@ -1,15 +1,15 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {KSuiteBridge} from '@infomaniak/ksuite-bridge'; -import {AppReadyMessageKey} from '@infomaniak/ksuite-bridge'; +import type {DoNotDisturbMessage, KSuiteBridge} from '@infomaniak/ksuite-bridge'; +import {AppReadyMessageKey, DoNotDisturbMessageKey} from '@infomaniak/ksuite-bridge'; -import type {DispatchFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; import {BridgeActionTypes} from 'utils/constants'; export function storeBridge(bridge: KSuiteBridge) { - return async (dispatch: DispatchFunc) => { + return async (dispatch: DispatchFunc, getState: GetStateFunc) => { dispatch({ type: BridgeActionTypes.STORE_BRIDGE, bridge, @@ -19,6 +19,15 @@ export function storeBridge(bridge: KSuiteBridge) { type: AppReadyMessageKey, }); + bridge.on(DoNotDisturbMessageKey, (doNotDisturbMessage: DoNotDisturbMessage) => { + if (doNotDisturbMessage.enabled !== getState().ksuite_bridge.dnd) { + dispatch({ + type: BridgeActionTypes.DND_CHANGE, + dnd: doNotDisturbMessage.enabled, + }); + } + }); + return {data: true}; }; } diff --git a/webapp/channels/src/actions/notification_actions.jsx b/webapp/channels/src/actions/notification_actions.jsx index 2f2005b3c4..103a73c322 100644 --- a/webapp/channels/src/actions/notification_actions.jsx +++ b/webapp/channels/src/actions/notification_actions.jsx @@ -17,7 +17,7 @@ import {isChannelMuted} from 'mattermost-redux/utils/channel_utils'; import {isSystemMessage, isUserAddedInChannel} from 'mattermost-redux/utils/post_utils'; import {displayUsername} from 'mattermost-redux/utils/user_utils'; -import {getKSuiteBridge} from 'selectors/ksuite_bridge'; +import {getKSuiteBridge, getKSuiteDnd} from 'selectors/ksuite_bridge'; import {getChannelURL, getPermalinkURL} from 'selectors/urls'; import {isThreadOpen} from 'selectors/views/threads'; @@ -98,6 +98,7 @@ export function sendDesktopNotification(post, msgProps) { const userStatus = getStatusForUserId(state, user.id); const member = getMyChannelMember(state, post.channel_id); const isCrtReply = isCollapsedThreadsEnabled(state) && post.root_id !== ''; + const ksuiteDnd = getKSuiteDnd(state); if (!member || isChannelMuted(member) || userStatus === UserStatuses.DND || userStatus === UserStatuses.OUT_OF_OFFICE) { return; @@ -114,9 +115,7 @@ export function sendDesktopNotification(post, msgProps) { notifyLevel = NotificationLevels.ALL; } - if (window.location.search.includes('dnd=true')) { - return; - } else if (notifyLevel === NotificationLevels.NONE) { + if (ksuiteDnd || window.location.search.includes('dnd=true') || notifyLevel === NotificationLevels.NONE) { return; } else if (channel.type === 'G' && notifyLevel === NotificationLevels.MENTION) { // Compose the whole text in the message, including interactive messages. diff --git a/webapp/channels/src/reducers/plugins/ksuite_bridge.ts b/webapp/channels/src/reducers/plugins/ksuite_bridge.ts index 101e2450c2..dcbfaffe3f 100644 --- a/webapp/channels/src/reducers/plugins/ksuite_bridge.ts +++ b/webapp/channels/src/reducers/plugins/ksuite_bridge.ts @@ -20,6 +20,16 @@ function bridge(state = null, action: GenericAction) { } } +function dnd(state = false, action: GenericAction) { + switch (action.type) { + case BridgeActionTypes.DND_CHANGE: + return action.dnd; + default: + return state; + } +} + export default combineReducers({ bridge, + dnd, }); diff --git a/webapp/channels/src/selectors/ksuite_bridge.ts b/webapp/channels/src/selectors/ksuite_bridge.ts index 14876adc69..523e1736f6 100644 --- a/webapp/channels/src/selectors/ksuite_bridge.ts +++ b/webapp/channels/src/selectors/ksuite_bridge.ts @@ -9,3 +9,7 @@ import type {GlobalState} from 'types/store'; export function getKSuiteBridge(state: GlobalState): KSuiteBridge { return state.ksuite_bridge.bridge; } + +export function getKSuiteDnd(state: GlobalState): boolean { + return state.ksuite_bridge.dnd; +} diff --git a/webapp/channels/src/types/store/index.ts b/webapp/channels/src/types/store/index.ts index a95e70a965..87c5dcf023 100644 --- a/webapp/channels/src/types/store/index.ts +++ b/webapp/channels/src/types/store/index.ts @@ -18,6 +18,7 @@ export type GlobalState = BaseGlobalState & { plugins: PluginsState; ksuite_bridge: { bridge: KSuiteBridge; + dnd: boolean; }; kdrive: { toast: { diff --git a/webapp/channels/src/utils/constants.tsx b/webapp/channels/src/utils/constants.tsx index 03ab765d4b..b3a11dc64a 100644 --- a/webapp/channels/src/utils/constants.tsx +++ b/webapp/channels/src/utils/constants.tsx @@ -201,6 +201,7 @@ export const suitePluginIds = { export const BridgeActionTypes = keyMirror({ STORE_BRIDGE: null, + DND_CHANGE: null, }); export const KDriveActionTypes = keyMirror({ diff --git a/yarn.lock b/yarn.lock index 560041cca8..3e12ed97b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2107,12 +2107,12 @@ __metadata: languageName: node linkType: hard -"@infomaniak/ksuite-bridge@https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.2.7.tgz": - version: 0.2.7 - resolution: "@infomaniak/ksuite-bridge@https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.2.7.tgz" +"@infomaniak/ksuite-bridge@https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.3.1.tgz": + version: 0.3.1 + resolution: "@infomaniak/ksuite-bridge@https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.3.1.tgz" dependencies: emittery: "npm:^1.0.1" - checksum: b289e6acdd9fd0251de09c53e80cda86794d3b04d8f807a1dc592d6ff8a77b65ad8e78036560ff3d79f2908d60aa9023856549823d73fe76e3efc14a97c36c46 + checksum: 5d69e5f042602a4c31c31492dfbb7153c4accd2bdfbe36b2f889863977f7ed05feda1d9f3f1872144ed124451d88234c4f0a1215e9ca203dd24e0d74eb5b854f languageName: node linkType: hard @@ -13676,7 +13676,7 @@ __metadata: "@infomaniak/compass-components": "npm:0.17.0" "@infomaniak/compass-icons": "npm:0.13.0" "@infomaniak/font-suisse": "https://verdaccio.dev.infomaniak.ch/@infomaniak/font-suisse/-/font-suisse-1.0.0.tgz" - "@infomaniak/ksuite-bridge": "https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.2.7.tgz" + "@infomaniak/ksuite-bridge": "https://verdaccio.dev.infomaniak.ch/@infomaniak/ksuite-bridge/-/ksuite-bridge-0.3.1.tgz" "@infomaniak/marked": "npm:^0.2.0" "@infomaniak/mattermost-client": "workspace:webapp/platform/client" "@infomaniak/mattermost-types": "workspace:webapp/platform/types"