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 134 Lines • ▼ Show 20 Lines | ): Promise<RawMessageInfo[]> { | ||||
const messageInsertQuery = SQL` | const messageInsertQuery = SQL` | ||||
INSERT INTO messages(id, thread, user, type, content, time, | INSERT INTO messages(id, thread, user, type, content, time, | ||||
creation, target_message) | creation, target_message) | ||||
VALUES ${messageInsertRows} | VALUES ${messageInsertRows} | ||||
`; | `; | ||||
const messageInsertPromise = dbQuery(messageInsertQuery); | const messageInsertPromise = dbQuery(messageInsertQuery); | ||||
const processMessages = processMessagesForSearch(returnMessageInfos); | |||||
const postMessageSendPromise = postMessageSend( | const postMessageSendPromise = postMessageSend( | ||||
viewer, | viewer, | ||||
threadsToMessageIndices, | threadsToMessageIndices, | ||||
subthreadPermissionsToCheck, | subthreadPermissionsToCheck, | ||||
stripLocalIDs(newMessageInfos), | stripLocalIDs(newMessageInfos), | ||||
newMessageDatas, | newMessageDatas, | ||||
updatesForCurrentSession, | updatesForCurrentSession, | ||||
); | ); | ||||
if (!viewer.isScriptViewer) { | if (!viewer.isScriptViewer) { | ||||
// If we're not being called from a script, then we avoid awaiting | // If we're not being called from a script, then we avoid awaiting | ||||
// postMessageSendPromise below so that we don't delay the response to the | // postMessageSendPromise below so that we don't delay the response to the | ||||
// user on external services. In that case, we use handleAsyncPromise to | // user on external services. In that case, we use handleAsyncPromise to | ||||
// make sure any exceptions are caught and logged. | // make sure any exceptions are caught and logged. | ||||
handleAsyncPromise(postMessageSendPromise); | handleAsyncPromise(postMessageSendPromise); | ||||
} | } | ||||
await Promise.all([ | await Promise.all([ | ||||
messageInsertPromise, | messageInsertPromise, | ||||
updateRepliesCount(threadsToMessageIndices, newMessageDatas), | updateRepliesCount(threadsToMessageIndices, newMessageDatas), | ||||
processMessages, | |||||
viewer.isScriptViewer ? postMessageSendPromise : undefined, | viewer.isScriptViewer ? postMessageSendPromise : undefined, | ||||
]); | ]); | ||||
if (updatesForCurrentSession !== 'return') { | if (updatesForCurrentSession !== 'return') { | ||||
return []; | return []; | ||||
} | } | ||||
return shimUnsupportedRawMessageInfos( | return shimUnsupportedRawMessageInfos( | ||||
▲ Show 20 Lines • Show All 471 Lines • Show Last 20 Lines |