Skip to content

Commit

Permalink
Merge branch 'feat/bridge-dnd-event' into 'master'
Browse files Browse the repository at this point in the history
handle bridge dnd event

See merge request kchat/webapp!719
  • Loading branch information
antonbuks committed Apr 11, 2024
2 parents fa65b83 + ead342b commit 4c8ccc5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion webapp/channels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 13 additions & 4 deletions webapp/channels/src/actions/ksuite_bridge_actions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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};
};
}
7 changes: 3 additions & 4 deletions webapp/channels/src/actions/notification_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions webapp/channels/src/reducers/plugins/ksuite_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
4 changes: 4 additions & 0 deletions webapp/channels/src/selectors/ksuite_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions webapp/channels/src/types/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GlobalState = BaseGlobalState & {
plugins: PluginsState;
ksuite_bridge: {
bridge: KSuiteBridge;
dnd: boolean;
};
kdrive: {
toast: {
Expand Down
1 change: 1 addition & 0 deletions webapp/channels/src/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const suitePluginIds = {

export const BridgeActionTypes = keyMirror({
STORE_BRIDGE: null,
DND_CHANGE: null,
});

export const KDriveActionTypes = keyMirror({
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4c8ccc5

Please sign in to comment.