WS handle new post to be able to prepare myChannel multiple times (#5958)
This commit is contained in:
parent
ac556c66d6
commit
0a45fd9e13
4 changed files with 18 additions and 8 deletions
|
|
@ -284,23 +284,21 @@ export const updateLastPostAt = async (serverUrl: string, channelId: string, las
|
|||
return {error: 'not a member'};
|
||||
}
|
||||
|
||||
const models: Model[] = [];
|
||||
if (lastPostAt > member.lastPostAt) {
|
||||
member.prepareUpdate((m) => {
|
||||
m.lastPostAt = lastPostAt;
|
||||
});
|
||||
models.push();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!prepareRecordsOnly && models.length) {
|
||||
if (!prepareRecordsOnly) {
|
||||
await operator.batchRecords([member]);
|
||||
}
|
||||
} catch (error) {
|
||||
return {error};
|
||||
}
|
||||
|
||||
return {models};
|
||||
return {member};
|
||||
};
|
||||
|
||||
export async function updateChannelsDisplayName(serverUrl: string, channels: ChannelModel[], users: UserProfile[], prepareRecordsOnly = false) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
/* eslint-disable max-lines */
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
import {IntlShape} from 'react-intl';
|
||||
|
||||
|
|
|
|||
|
|
@ -210,9 +210,9 @@ export const fetchPostsForChannel = async (serverUrl: string, channelId: string,
|
|||
for (const post of data.posts) {
|
||||
lastPostAt = post.create_at > lastPostAt ? post.create_at : lastPostAt;
|
||||
}
|
||||
const {models: memberModels} = await updateLastPostAt(serverUrl, channelId, lastPostAt, true);
|
||||
if (memberModels?.length) {
|
||||
models.push(...memberModels);
|
||||
const {member: memberModel} = await updateLastPostAt(serverUrl, channelId, lastPostAt, true);
|
||||
if (memberModel) {
|
||||
models.push(memberModel);
|
||||
}
|
||||
|
||||
if (models.length) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,16 @@ import {queryPostById} from '@queries/servers/post';
|
|||
import {queryCurrentChannelId, queryCurrentUserId} from '@queries/servers/system';
|
||||
import {isFromWebhook, isSystemMessage, shouldIgnorePost} from '@utils/post';
|
||||
|
||||
import type MyChannelModel from '@typings/database/models/servers/my_channel';
|
||||
|
||||
function preparedMyChannelHack(myChannel: MyChannelModel) {
|
||||
// @ts-expect-error hack accessing _preparedState
|
||||
if (!myChannel._preparedState) {
|
||||
// @ts-expect-error hack setting _preparedState
|
||||
myChannel._preparedState = null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleNewPostEvent(serverUrl: string, msg: WebSocketMessage) {
|
||||
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
||||
if (!operator) {
|
||||
|
|
@ -51,7 +61,6 @@ export async function handleNewPostEvent(serverUrl: string, msg: WebSocketMessag
|
|||
// Ensure the channel membership
|
||||
let myChannel = await queryMyChannel(operator.database, post.channel_id);
|
||||
if (myChannel) {
|
||||
// Do not batch lastPostAt update since we may be modifying the member later for unreads
|
||||
await updateLastPostAt(serverUrl, post.channel_id, post.create_at, false);
|
||||
} else {
|
||||
const myChannelRequest = await fetchMyChannel(serverUrl, '', post.channel_id, true);
|
||||
|
|
@ -127,12 +136,14 @@ export async function handleNewPostEvent(serverUrl: string, msg: WebSocketMessag
|
|||
if (markAsRead) {
|
||||
markChannelAsRead(serverUrl, post.channel_id);
|
||||
} else if (markAsViewed) {
|
||||
preparedMyChannelHack(myChannel);
|
||||
const {member: viewedAt} = await markChannelAsViewed(serverUrl, post.channel_id, true);
|
||||
if (viewedAt) {
|
||||
models.push(viewedAt);
|
||||
}
|
||||
} else {
|
||||
const hasMentions = msg.data.mentions.includes(currentUserId);
|
||||
preparedMyChannelHack(myChannel);
|
||||
const {member: unreadAt} = await markChannelAsUnread(
|
||||
serverUrl,
|
||||
post.channel_id,
|
||||
|
|
|
|||
Loading…
Reference in a new issue