mattermost-mobile/app/actions/websocket/threads.ts
Daniel Espino García 75d1c9d228
Try to remove as many as as possible (#6200)
* Try to remove as many ` as ` as possible

* Fix imports
2022-05-12 15:46:11 +02:00

65 lines
2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {markTeamThreadsAsRead, processReceivedThreads, updateThread} from '@actions/local/thread';
import DatabaseManager from '@database/manager';
export async function handleThreadUpdatedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
try {
const thread: Thread = JSON.parse(msg.data.thread);
const teamId = msg.broadcast.team_id;
// Mark it as following
thread.is_following = true;
processReceivedThreads(serverUrl, [thread], teamId, true);
} catch (error) {
// Do nothing
}
}
export async function handleThreadReadChangedEvent(serverUrl: string, msg: WebSocketMessage<ThreadReadChangedData>): Promise<void> {
const operator = DatabaseManager.serverDatabases[serverUrl].operator;
if (!operator) {
return;
}
try {
if (operator) {
const {thread_id, timestamp, unread_mentions, unread_replies} = msg.data;
if (thread_id) {
await updateThread(serverUrl, thread_id, {
last_viewed_at: timestamp,
unread_mentions,
unread_replies,
});
} else {
await markTeamThreadsAsRead(serverUrl, msg.broadcast.team_id);
}
}
} catch (error) {
// Do nothing
}
}
export async function handleThreadFollowChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
const operator = DatabaseManager.serverDatabases[serverUrl].operator;
if (!operator) {
return;
}
try {
if (operator) {
const {reply_count, state, thread_id} = msg.data as {
reply_count: number;
state: boolean;
thread_id: string;
};
await updateThread(serverUrl, thread_id, {
is_following: state,
reply_count,
});
}
} catch (error) {
// Do nothing
}
}