Let ServerDatabases type hold undefined values (#6423)

* Let ServerDatabases type hold undefined values

* Avoid model.database
This commit is contained in:
Daniel Espino García
2022-06-22 23:51:28 +02:00
committed by GitHub
parent b5ff344b64
commit 844f2c0393
37 changed files with 136 additions and 108 deletions

View File

@@ -9,8 +9,13 @@ import {getPostById} from '@queries/servers/post';
import {deletePreferences, differsFromLocalNameFormat} from '@queries/servers/preference';
export async function handlePreferenceChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
const operator = DatabaseManager.serverDatabases[serverUrl].operator;
if (!operator) {
let database;
let operator;
try {
const result = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
database = result.database;
operator = result.operator;
} catch (e) {
return;
}
@@ -18,7 +23,7 @@ export async function handlePreferenceChangedEvent(serverUrl: string, msg: WebSo
const preference: PreferenceType = JSON.parse(msg.data.preference);
handleSavePostAdded(serverUrl, [preference]);
const hasDiffNameFormatPref = await differsFromLocalNameFormat(operator.database, [preference]);
const hasDiffNameFormatPref = await differsFromLocalNameFormat(database, [preference]);
if (operator) {
await operator.handlePreferences({

View File

@@ -2,7 +2,6 @@
// 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 {
@@ -18,23 +17,16 @@ export async function handleThreadUpdatedEvent(serverUrl: string, msg: WebSocket
}
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);
}
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
@@ -42,23 +34,16 @@ export async function handleThreadReadChangedEvent(serverUrl: string, msg: WebSo
}
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 {
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,
});
}
await updateThread(serverUrl, thread_id, {
is_following: state,
reply_count,
});
} catch (error) {
// Do nothing
}