mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-23 03:48:16 +00:00
* Expo-Router partial migration * Full migration to ExpoRouter * i18n * add tests * Merge branch 'main' into expo-router * align package-lock.json * i18n * feedback review * feedback review * android 16kb patch * Refactored emoji picker keyboard using a state machine * set android launch_screen in drawables instead of layout * no conditional hooks * remove duplicate call in test * address feedback * fix tests and address more feedback * small corrections * small corrections * small corrections * fix draft test * fix draft test 2 * remove navigateToScreen in draff test * fix nit in draft test * remove doc file * Feedback review * fix snapshots * improve test coverage * fix i18n * Upgrade t o RN 0.83, other dependencies and new architecture (#9737) * library hardware-keyboard android new arch support fix * library rnshare android new arch support fix * library rnutils android new arch support fix * library secure-pdf-viewer add new arch support * Enable new arch on iOS and Android * update emm and network client with new-arch * update intune to use new-arch * performance improvements * fix tests * fixes post input on new-arch * fix android emoji picker * remove doc * run tests in parallel * upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture Bumps core dependencies to their latest versions: - React Native 0.77.3 → 0.83.9 (New Architecture enabled) - React 18.3.1 → 19.2.5 - Expo SDK 52 → 55 - TypeScript 5.8.3 → 6.0.3 - Node.js 22.16.0 → 24.15.0 - react-native-reanimated 3.17.3 → 4.3.0 - Various other dependency upgrades Migrates iOS AppDelegate from Objective-C to Swift, updates Android build tooling and Gradle wrapper, refreshes all patches and font assets, and adapts app code, tests, and CI workflows throughout for API changes introduced by these upgrades. * remove unecessary dismissKeyboard in notifications * feedback review * update intune to use new-arch * update @mattermost deps * missing i18n string * additional fixes * update fastlane
132 lines
5.4 KiB
TypeScript
132 lines
5.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {fetchMyChannel, switchToChannelById} from '@actions/remote/channel';
|
|
import {fetchPostById} from '@actions/remote/post';
|
|
import {fetchMyTeam} from '@actions/remote/team';
|
|
import {fetchAndSwitchToThread} from '@actions/remote/thread';
|
|
import {getDefaultThemeByAppearance} from '@context/theme';
|
|
import DatabaseManager from '@database/manager';
|
|
import PerformanceMetricsManager from '@managers/performance_metrics_manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import {getMyChannel} from '@queries/servers/channel';
|
|
import {getPostById} from '@queries/servers/post';
|
|
import {queryThemePreferences} from '@queries/servers/preference';
|
|
import {getCurrentTeamId} from '@queries/servers/system';
|
|
import {getMyTeamById} from '@queries/servers/team';
|
|
import {getIsCRTEnabled} from '@queries/servers/thread';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import {isErrorWithStatusCode} from '@utils/errors';
|
|
import {dismissKeyboard} from '@utils/keyboard';
|
|
import {emitNotificationError} from '@utils/notification';
|
|
import {setThemeDefaults, updateThemeIfNeeded} from '@utils/theme';
|
|
|
|
import type MyChannelModel from '@typings/database/models/servers/my_channel';
|
|
import type MyTeamModel from '@typings/database/models/servers/my_team';
|
|
import type PostModel from '@typings/database/models/servers/post';
|
|
|
|
export async function pushNotificationEntry(serverUrl: string, notification: NotificationData, groupLabel?: BaseRequestGroupLabel) {
|
|
// We only reach this point if we have a channel Id in the notification payload
|
|
const channelId = notification.channel_id!;
|
|
const rootId = notification.root_id!;
|
|
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return {error: `${serverUrl} database not found`};
|
|
}
|
|
|
|
// Cold start from push: ensure keyboard is not stuck over the channel after navigation
|
|
await dismissKeyboard();
|
|
|
|
PerformanceMetricsManager.startTimeToInteraction();
|
|
|
|
const {database} = operator;
|
|
|
|
const currentTeamId = await getCurrentTeamId(database);
|
|
const currentServerUrl = await DatabaseManager.getActiveServerUrl();
|
|
|
|
let teamId = notification.team_id;
|
|
if (!teamId) {
|
|
// If the notification payload does not have a teamId we assume is a DM/GM
|
|
teamId = currentTeamId;
|
|
}
|
|
|
|
if (currentServerUrl !== serverUrl) {
|
|
await DatabaseManager.setActiveServerDatabase(serverUrl);
|
|
}
|
|
|
|
if (!EphemeralStore.getTheme()) {
|
|
// 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
|
|
// not match the theme
|
|
const themes = await queryThemePreferences(database, teamId).fetch();
|
|
let theme = getDefaultThemeByAppearance();
|
|
if (themes.length) {
|
|
theme = setThemeDefaults(JSON.parse(themes[0].value) as Theme);
|
|
}
|
|
updateThemeIfNeeded(theme, true);
|
|
}
|
|
|
|
// To make the switch faster we determine if we already have the team & channel
|
|
let myChannel: MyChannelModel | ChannelMembership | undefined = await getMyChannel(database, channelId);
|
|
let myTeam: MyTeamModel | TeamMembership | undefined = await getMyTeamById(database, teamId);
|
|
|
|
if (!myTeam) {
|
|
const resp = await fetchMyTeam(serverUrl, teamId, false, groupLabel);
|
|
if (resp.error) {
|
|
if (isErrorWithStatusCode(resp.error) && resp.error.status_code === 403) {
|
|
emitNotificationError('Team');
|
|
} else {
|
|
emitNotificationError('Connection');
|
|
}
|
|
} else {
|
|
myTeam = resp.memberships?.[0];
|
|
}
|
|
}
|
|
|
|
if (!myChannel) {
|
|
const resp = await fetchMyChannel(serverUrl, teamId, channelId, false, groupLabel);
|
|
if (resp.error) {
|
|
if (isErrorWithStatusCode(resp.error) && resp.error.status_code === 403) {
|
|
emitNotificationError('Channel');
|
|
} else {
|
|
emitNotificationError('Connection');
|
|
}
|
|
} else {
|
|
myChannel = resp.memberships?.[0];
|
|
}
|
|
}
|
|
|
|
const isCRTEnabled = await getIsCRTEnabled(database);
|
|
const isThreadNotification = isCRTEnabled && Boolean(rootId);
|
|
|
|
if (myChannel && myTeam) {
|
|
if (isThreadNotification) {
|
|
let post: PostModel | Post | undefined = await getPostById(database, rootId);
|
|
if (!post) {
|
|
const resp = await fetchPostById(serverUrl, rootId, false, groupLabel);
|
|
post = resp.post;
|
|
}
|
|
|
|
const actualRootId = post && ('root_id' in post ? post.root_id : post.rootId);
|
|
|
|
if (actualRootId) {
|
|
PerformanceMetricsManager.setLoadTarget('THREAD');
|
|
await fetchAndSwitchToThread(serverUrl, actualRootId, true, groupLabel);
|
|
} else if (post) {
|
|
PerformanceMetricsManager.setLoadTarget('THREAD');
|
|
await fetchAndSwitchToThread(serverUrl, rootId, true, groupLabel);
|
|
} else {
|
|
emitNotificationError('Post');
|
|
}
|
|
} else {
|
|
PerformanceMetricsManager.setLoadTarget('CHANNEL');
|
|
await switchToChannelById(serverUrl, channelId, teamId, false, groupLabel);
|
|
}
|
|
}
|
|
|
|
WebsocketManager.openAll(groupLabel);
|
|
|
|
return {};
|
|
}
|