Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/creators/message-creator.js
Show All 26 Lines | |||||
import type { UpdatesForCurrentSession } from './update-creator.js'; | import type { UpdatesForCurrentSession } from './update-creator.js'; | ||||
import { createUpdates } from './update-creator.js'; | import { createUpdates } from './update-creator.js'; | ||||
import { | import { | ||||
dbQuery, | dbQuery, | ||||
SQL, | SQL, | ||||
appendSQLArray, | appendSQLArray, | ||||
mergeOrConditions, | mergeOrConditions, | ||||
} from '../database/database.js'; | } from '../database/database.js'; | ||||
import { processMessagesForSearch } from '../database/search-utils.js'; | |||||
import { | import { | ||||
fetchMessageInfoForLocalID, | fetchMessageInfoForLocalID, | ||||
fetchMessageInfoByID, | fetchMessageInfoByID, | ||||
} from '../fetchers/message-fetchers.js'; | } from '../fetchers/message-fetchers.js'; | ||||
import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers.js'; | import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers.js'; | ||||
import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | import { fetchServerThreadInfos } from '../fetchers/thread-fetchers.js'; | ||||
import { sendPushNotifs, sendRescindNotifs } from '../push/send.js'; | import { sendPushNotifs, sendRescindNotifs } from '../push/send.js'; | ||||
import { handleAsyncPromise } from '../responders/handlers.js'; | import { handleAsyncPromise } from '../responders/handlers.js'; | ||||
▲ Show 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | if (updatedThreads.length > 0) { | ||||
await createUpdates(updates); | await createUpdates(updates); | ||||
} | } | ||||
} | } | ||||
// Handles: | // Handles: | ||||
// (1) Sending push notifs | // (1) Sending push notifs | ||||
// (2) Setting threads to unread and generating corresponding UpdateInfos | // (2) Setting threads to unread and generating corresponding UpdateInfos | ||||
// (3) Publishing to Redis so that active sockets pass on new messages | // (3) Publishing to Redis so that active sockets pass on new messages | ||||
// (4) Processing messages for search | |||||
async function postMessageSend( | async function postMessageSend( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
threadsToMessageIndices: Map<string, number[]>, | threadsToMessageIndices: Map<string, number[]>, | ||||
subthreadPermissionsToCheck: Set<string>, | subthreadPermissionsToCheck: Set<string>, | ||||
messageInfos: RawMessageInfo[], | messageInfos: RawMessageInfo[], | ||||
messageDatas: MessageData[], | messageDatas: MessageData[], | ||||
updatesForCurrentSession: UpdatesForCurrentSession, | updatesForCurrentSession: UpdatesForCurrentSession, | ||||
) { | ) { | ||||
const processForSearch = processMessagesForSearch(messageInfos); | |||||
let joinIndex = 0; | let joinIndex = 0; | ||||
let subthreadSelects = ''; | let subthreadSelects = ''; | ||||
const subthreadJoins = []; | const subthreadJoins = []; | ||||
for (const subthread of subthreadPermissionsToCheck) { | for (const subthread of subthreadPermissionsToCheck) { | ||||
const index = joinIndex++; | const index = joinIndex++; | ||||
subthreadSelects += ` | subthreadSelects += ` | ||||
, | , | ||||
stm${index}.permissions AS subthread${subthread}_permissions, | stm${index}.permissions AS subthread${subthread}_permissions, | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | ) { | ||||
const latestMessages = flattenLatestMessagesPerUser(latestMessagesPerUser); | const latestMessages = flattenLatestMessagesPerUser(latestMessagesPerUser); | ||||
const [pushInfo, rescindInfo] = await Promise.all([ | const [pushInfo, rescindInfo] = await Promise.all([ | ||||
promiseAll(userPushInfoPromises), | promiseAll(userPushInfoPromises), | ||||
promiseAll(userRescindInfoPromises), | promiseAll(userRescindInfoPromises), | ||||
createReadStatusUpdates(latestMessages), | createReadStatusUpdates(latestMessages), | ||||
redisPublish(viewer, messageInfosPerUser, updatesForCurrentSession), | redisPublish(viewer, messageInfosPerUser, updatesForCurrentSession), | ||||
updateLatestMessages(latestMessages), | updateLatestMessages(latestMessages), | ||||
processForSearch, | |||||
]); | ]); | ||||
await Promise.all([ | await Promise.all([ | ||||
sendPushNotifs(_pickBy(Boolean)(pushInfo)), | sendPushNotifs(_pickBy(Boolean)(pushInfo)), | ||||
sendRescindNotifs(_pickBy(Boolean)(rescindInfo)), | sendRescindNotifs(_pickBy(Boolean)(rescindInfo)), | ||||
]); | ]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |