[Gekidou] Skip push notification processing for CRT (#6289)

* Skip push notification processing for CRT

* Fix pushNotificationEntry
This commit is contained in:
Elias Nahum
2022-05-19 13:03:14 -04:00
committed by GitHub
parent c1a39094c6
commit 353e5ceb0a
4 changed files with 43 additions and 28 deletions

View File

@@ -91,8 +91,6 @@ export async function switchToChannel(serverUrl: string, channelId: string, team
await operator.batchRecords(models);
}
PushNotifications.cancelChannelNotifications(channelId);
if (!EphemeralStore.theme) {
// When opening the app from a push notification the theme may not be set in the EphemeralStore
// causing the goToScreen to use the Appearance theme instead and that causes the screen background color to potentially
@@ -212,6 +210,7 @@ export async function markChannelAsViewed(serverUrl: string, channelId: string,
});
try {
PushNotifications.cancelChannelNotifications(channelId);
if (!prepareRecordsOnly) {
await operator.batchRecords([member]);
}

View File

@@ -1,13 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {switchToChannel} from '@actions/local/channel';
import {markChannelAsRead, switchToChannelById} from '@actions/remote/channel';
import {switchToChannelById} from '@actions/remote/channel';
import {Screens} from '@constants';
import DatabaseManager from '@database/manager';
import {getMyChannel} from '@queries/servers/channel';
import {getCommonSystemValues, getCurrentTeamId, getWebSocketLastDisconnected, setCurrentTeamAndChannelId} from '@queries/servers/system';
import {getMyTeamById} from '@queries/servers/team';
import {getIsCRTEnabled} from '@queries/servers/thread';
import {getCurrentUser} from '@queries/servers/user';
import EphemeralStore from '@store/ephemeral_store';
import {isTablet} from '@utils/helpers';
@@ -45,10 +45,14 @@ export async function pushNotificationEntry(serverUrl: string, notification: Not
// To make the switch faster we determine if we already have the team & channel
const myChannel = await getMyChannel(database, channelId);
const myTeam = await getMyTeamById(database, teamId);
if (myChannel && myTeam) {
await EphemeralStore.waitUntilScreenHasLoaded(Screens.HOME);
markChannelAsRead(serverUrl, channelId);
await switchToChannel(serverUrl, channelId, teamId);
const isCRTEnabled = await getIsCRTEnabled(database);
await EphemeralStore.waitUntilScreenHasLoaded(Screens.HOME);
let switchedToChannel = isCRTEnabled;
if (myChannel && myTeam && !switchedToChannel) {
await switchToChannelById(serverUrl, channelId, teamId);
switchedToChannel = true;
}
const entryData = await entry(serverUrl, teamId, channelId);
@@ -72,15 +76,16 @@ export async function pushNotificationEntry(serverUrl: string, notification: Not
}
}
let switchedToChannel = false;
if (isTabletDevice || (selectedChannelId === channelId)) {
// Make switch again to get the missing data and make sure the team is the correct one
switchedToChannel = true;
switchToChannelById(serverUrl, selectedChannelId, selectedTeamId);
} else if (selectedTeamId !== teamId || selectedChannelId !== channelId) {
// If in the end the selected team or channel is different than the one from the notification
// we switch again
setCurrentTeamAndChannelId(operator, selectedTeamId, selectedChannelId);
if (!switchedToChannel) {
if (isTabletDevice || (selectedChannelId === channelId)) {
// Make switch again to get the missing data and make sure the team is the correct one
switchedToChannel = true;
switchToChannelById(serverUrl, selectedChannelId, selectedTeamId);
} else if (selectedTeamId !== teamId || selectedChannelId !== channelId) {
// If in the end the selected team or channel is different than the one from the notification
// we switch again
setCurrentTeamAndChannelId(operator, selectedTeamId, selectedChannelId);
}
}
if (selectedTeamId !== teamId) {

View File

@@ -4,7 +4,7 @@
import {Platform} from 'react-native';
import {updatePostSinceCache} from '@actions/local/notification';
import {fetchMissingSidebarInfo, fetchMyChannel, markChannelAsRead, switchToChannelById} from '@actions/remote/channel';
import {fetchMissingSidebarInfo, fetchMyChannel, switchToChannelById} from '@actions/remote/channel';
import {forceLogoutIfNecessary} from '@actions/remote/session';
import {fetchMyTeam} from '@actions/remote/team';
import {Preferences} from '@constants';
@@ -14,6 +14,7 @@ import {getMyChannel, getChannelById} from '@queries/servers/channel';
import {queryPreferencesByCategoryAndName} from '@queries/servers/preference';
import {getCommonSystemValues, getWebSocketLastDisconnected} from '@queries/servers/system';
import {getMyTeamById} from '@queries/servers/team';
import {getIsCRTEnabled} from '@queries/servers/thread';
import {getCurrentUser} from '@queries/servers/user';
import {emitNotificationError} from '@utils/notification';
@@ -91,8 +92,12 @@ export const backgroundNotification = async (serverUrl: string, notification: No
return;
}
const lastDisconnectedAt = await getWebSocketLastDisconnected(database);
const isCRTEnabled = await getIsCRTEnabled(database);
if (isCRTEnabled && notification.payload?.root_id) {
return;
}
const lastDisconnectedAt = await getWebSocketLastDisconnected(database);
if (lastDisconnectedAt) {
if (Platform.OS === 'ios') {
updatePostSinceCache(serverUrl, notification);
@@ -109,10 +114,12 @@ export const openNotification = async (serverUrl: string, notification: Notifica
}
try {
const channelId = notification.payload!.channel_id!;
await markChannelAsRead(serverUrl, channelId);
const {database} = operator;
const channelId = notification.payload!.channel_id!;
const isCRTEnabled = await getIsCRTEnabled(database);
if (isCRTEnabled && notification.payload?.root_id) {
return {error: 'Opening CRT notifications not implemented yet'};
}
const system = await getCommonSystemValues(database);
const currentServerUrl = await DatabaseManager.getActiveServerUrl();
let teamId = notification.payload?.team_id;
@@ -131,8 +138,7 @@ export const openNotification = async (serverUrl: string, notification: Notifica
const myTeam = await getMyTeamById(database, teamId);
if (myChannel && myTeam) {
switchToChannelById(serverUrl, channelId, teamId);
return {};
return switchToChannelById(serverUrl, channelId, teamId);
}
const result = await fetchNotificationData(serverUrl, notification);

View File

@@ -24,6 +24,7 @@ import {DEFAULT_LOCALE, getLocalizedMessage, t} from '@i18n';
import NativeNotifications from '@notifications';
import {queryServerName} from '@queries/app/servers';
import {getCurrentChannelId} from '@queries/servers/system';
import {getIsCRTEnabled} from '@queries/servers/thread';
import {showOverlay} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import {isTablet} from '@utils/helpers';
@@ -121,8 +122,14 @@ class PushNotifications {
const serverUrl = await this.getServerUrlFromNotification(notification);
if (serverUrl && payload?.channel_id) {
markChannelAsViewed(serverUrl, payload?.channel_id, false);
this.cancelChannelNotifications(payload.channel_id);
const database = DatabaseManager.serverDatabases[serverUrl]?.database;
if (database) {
const isCRTEnabled = await getIsCRTEnabled(database);
if (isCRTEnabled && payload.root_id) {
return;
}
markChannelAsViewed(serverUrl, payload.channel_id, false);
}
}
};
@@ -164,7 +171,6 @@ class PushNotifications {
handleMessageNotification = async (notification: NotificationWithData) => {
const {payload, foreground, userInteraction} = notification;
const serverUrl = await this.getServerUrlFromNotification(notification);
if (serverUrl) {
if (foreground) {
// Move this to a local action
@@ -172,7 +178,6 @@ class PushNotifications {
} else if (userInteraction && !payload?.userInfo?.local) {
// Handle notification tapped
openNotification(serverUrl, notification);
this.cancelChannelNotifications(notification.payload!.channel_id);
} else {
backgroundNotification(serverUrl, notification);
}