* Push notifications entry point * Process android notification natively only if RN is not initialized * Database changes to store local channel viewed_at * EphemeralStore wait until screen removed * Move schedule session notification to utility * Fix channel remote & local actions + added actions for markChannelAsViewed & fetchMyChannel * Add fetchMyTeam remote action * Add dismissAllModalsAndPopToScreen to navigation * Improve post list component & add app state to re-trigger queries * Improve WS implementation * Handle push notification events * Fix postsInChannel since handler * Handle in-app notifications * Post list to listen to column changes * Track selected bottom tab in ephemeral store * add useIsTablet hook * in-app notifications on tablets
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {MM_TABLES} from '@constants/database';
|
|
import DatabaseManager from '@database/manager';
|
|
import {queryPostsInChannel} from '@queries/servers/post';
|
|
|
|
import type PostModel from '@typings/database/models/servers/post';
|
|
|
|
export const updatePostSinceCache = async (serverUrl: string, notification: NotificationWithData) => {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return {error: `${serverUrl} database not found`};
|
|
}
|
|
|
|
try {
|
|
if (notification.payload?.channel_id) {
|
|
const {database} = operator;
|
|
const chunks = await queryPostsInChannel(database, notification.payload.channel_id);
|
|
if (chunks.length) {
|
|
const recent = chunks[0];
|
|
const lastPost = await database.get<PostModel>(MM_TABLES.SERVER.POST).find(notification.payload.post_id);
|
|
await operator.database.write(async () => {
|
|
await recent.update(() => {
|
|
recent.latest = lastPost.createAt;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
return {};
|
|
} catch (error) {
|
|
return {error};
|
|
}
|
|
};
|
|
|