diff --git a/keyserver/src/updaters/upload-updaters.js b/keyserver/src/updaters/upload-updaters.js index 5c284d4b3..fa54d1778 100644 --- a/keyserver/src/updaters/upload-updaters.js +++ b/keyserver/src/updaters/upload-updaters.js @@ -1,41 +1,47 @@ // @flow import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js'; import { getUploadIDsFromMediaMessageServerDBContents } from 'lib/types/messages/media.js'; import { dbQuery, SQL } from '../database/database.js'; import type { Viewer } from '../session/viewer.js'; async function assignImages( viewer: Viewer, mediaIDs: $ReadOnlyArray, containerID: string, threadID: string, ): Promise { const query = SQL` UPDATE uploads SET container = ${containerID}, thread = ${threadID} - WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} - AND container IS NULL AND thread IS NULL + WHERE id IN (${mediaIDs}) + AND uploader = ${viewer.id} + AND container IS NULL + AND user_container IS NULL + AND thread IS NULL `; await dbQuery(query); } async function assignMessageContainerToMedia( viewer: Viewer, mediaMessageContents: $ReadOnlyArray, containerID: string, threadID: string, ): Promise { const uploadIDs = getUploadIDsFromMediaMessageServerDBContents(mediaMessageContents); const query = SQL` UPDATE uploads SET container = ${containerID}, thread = ${threadID} - WHERE id IN (${uploadIDs}) AND uploader = ${viewer.id} - AND container IS NULL AND thread IS NULL + WHERE id IN (${uploadIDs}) + AND uploader = ${viewer.id} + AND container IS NULL + AND user_container IS NULL + AND thread IS NULL `; await dbQuery(query); } export { assignImages, assignMessageContainerToMedia };