Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/updaters/upload-updaters.js
// @flow | // @flow | ||||
import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js'; | |||||
import { dbQuery, SQL } from '../database/database'; | import { dbQuery, SQL } from '../database/database'; | ||||
import type { Viewer } from '../session/viewer'; | import type { Viewer } from '../session/viewer'; | ||||
async function assignMedia( | async function assignMedia( | ||||
viewer: Viewer, | viewer: Viewer, | ||||
mediaIDs: $ReadOnlyArray<string>, | mediaIDs: $ReadOnlyArray<string>, | ||||
containerID: string, | containerID: string, | ||||
): Promise<void> { | ): Promise<void> { | ||||
const query = SQL` | const query = SQL` | ||||
UPDATE uploads | UPDATE uploads | ||||
SET container = ${containerID} | SET container = ${containerID} | ||||
WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} AND container IS NULL | WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} AND container IS NULL | ||||
`; | `; | ||||
await dbQuery(query); | await dbQuery(query); | ||||
} | } | ||||
export { assignMedia }; | async function assignMessageContainerToMedia( | ||||
viewer: Viewer, | |||||
mediaMessageContents: $ReadOnlyArray<MediaMessageServerDBContent>, | |||||
containerID: string, | |||||
): Promise<void> { | |||||
const mediaIDs: string[] = []; | |||||
for (const mediaContent of mediaMessageContents) { | |||||
mediaIDs.push(mediaContent.uploadID); | |||||
if (mediaContent.type === 'video') { | |||||
mediaIDs.push(mediaContent.thumbnailUploadID); | |||||
} | |||||
} | |||||
ashoat: Seen this logic pop up in multiple places... wonder if there should be a helper for it instead… | |||||
atulAuthorUnsubmitted Done Inline ActionsYeah was going to defer refactoring work for later, but this was quick enough: https://phab.comm.dev/D5190 atul: Yeah was going to defer refactoring work for later, but this was quick enough: https://phab. | |||||
const query = SQL` | |||||
UPDATE uploads | |||||
SET container = ${containerID} | |||||
WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} AND container IS NULL | |||||
`; | |||||
await dbQuery(query); | |||||
} | |||||
export { assignMedia, assignMessageContainerToMedia }; |
Seen this logic pop up in multiple places... wonder if there should be a helper for it instead of copy-pasting