diff --git a/app/actions/websocket/posts.ts b/app/actions/websocket/posts.ts index 9123790cf6..1c5877e18a 100644 --- a/app/actions/websocket/posts.ts +++ b/app/actions/websocket/posts.ts @@ -164,8 +164,13 @@ export async function handleNewPostEvent(serverUrl: string, msg: WebSocketMessag } } + let actionType: string = ActionType.POSTS.RECEIVED_NEW; + if (isCRTEnabled && post.root_id) { + actionType = ActionType.POSTS.RECEIVED_IN_THREAD; + } + const postModels = await operator.handlePosts({ - actionType: ActionType.POSTS.RECEIVED_NEW, + actionType, order: [post.id], posts: [post], prepareRecordsOnly: true, @@ -203,8 +208,14 @@ export async function handlePostEdited(serverUrl: string, msg: WebSocketMessage) models.push(...authorsModels); } + let actionType: string = ActionType.POSTS.RECEIVED_NEW; + const isCRTEnabled = await getIsCRTEnabled(operator.database); + if (isCRTEnabled && post.root_id) { + actionType = ActionType.POSTS.RECEIVED_IN_THREAD; + } + const postModels = await operator.handlePosts({ - actionType: ActionType.POSTS.RECEIVED_NEW, + actionType, order: [post.id], posts: [post], prepareRecordsOnly: true, diff --git a/app/actions/websocket/threads.ts b/app/actions/websocket/threads.ts index c3e7f119bf..7ccea72256 100644 --- a/app/actions/websocket/threads.ts +++ b/app/actions/websocket/threads.ts @@ -2,12 +2,22 @@ // See LICENSE.txt for license information. import {markTeamThreadsAsRead, processReceivedThreads, updateThread} from '@actions/local/thread'; +import {getCurrentTeamId} from '@app/queries/servers/system'; +import DatabaseManager from '@database/manager'; import EphemeralStore from '@store/ephemeral_store'; export async function handleThreadUpdatedEvent(serverUrl: string, msg: WebSocketMessage): Promise { try { + const database = DatabaseManager.serverDatabases[serverUrl]?.database; + if (!database) { + return; + } const thread: Thread = JSON.parse(msg.data.thread); - const teamId = msg.broadcast.team_id; + let teamId = msg.broadcast.team_id; + + if (!teamId) { + teamId = await getCurrentTeamId(database); + } // Mark it as following thread.is_following = true;