Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356816
D6485.id23073.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D6485.id23073.diff
View Options
diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js
--- a/keyserver/src/fetchers/upload-fetchers.js
+++ b/keyserver/src/fetchers/upload-fetchers.js
@@ -3,8 +3,13 @@
import _keyBy from 'lodash/fp/keyBy.js';
import type { Media } from 'lib/types/media-types.js';
+import { messageTypes } from 'lib/types/message-types.js';
import type { MediaMessageServerDBContent } from 'lib/types/messages/media.js';
import { getUploadIDsFromMediaMessageServerDBContents } from 'lib/types/messages/media.js';
+import type {
+ ThreadFetchMediaResult,
+ ThreadFetchMediaRequest,
+} from 'lib/types/thread-types.js';
import { ServerError } from 'lib/utils/errors.js';
import { dbQuery, SQL } from '../database/database.js';
@@ -116,6 +121,79 @@
return result.map(mediaFromRow);
}
+async function fetchMediaForThread(
+ request: ThreadFetchMediaRequest,
+): Promise<ThreadFetchMediaResult> {
+ const query = SQL`
+ SELECT content.photo AS uploadID,
+ u.secret AS uploadSecret,
+ u.type AS uploadType, u.extra AS uploadExtra,
+ u.container, u.creation_time,
+ NULL AS thumbnailID,
+ NULL AS thumbnailUploadSecret,
+ NULL AS thumbnailUploadType,
+ NULL AS thumbnailUploadExtra
+ FROM messages m
+ LEFT JOIN JSON_TABLE(
+ m.content,
+ "$[*]" COLUMNS(photo INT PATH "$")
+ ) content ON 1
+ LEFT JOIN uploads u ON u.id = content.photo
+ WHERE m.thread = ${request.threadID} AND m.type = ${messageTypes.IMAGES}
+ UNION SELECT content.media AS uploadID,
+ uv.secret AS uploadSecret,
+ uv.type AS uploadType, uv.extra AS uploadExtra,
+ uv.container, uv.creation_time,
+ content.thumbnail AS thumbnailID,
+ ut.secret AS thumbnailUploadSecret,
+ ut.type AS thumbnailUploadType,
+ ut.extra AS thumbnailUploadExtra
+ FROM messages m
+ LEFT JOIN JSON_TABLE(
+ m.content,
+ "$[*]" COLUMNS(
+ media INT PATH "$.uploadID",
+ thumbnail INT PATH "$.thumbnailUploadID"
+ )
+ ) content ON 1
+ LEFT JOIN uploads uv ON uv.id = content.media
+ LEFT JOIN uploads ut ON ut.id = content.thumbnail
+ WHERE m.thread = ${request.threadID} AND m.type = ${messageTypes.MULTIMEDIA}
+ ORDER BY creation_time DESC
+ LIMIT ${request.limit} OFFSET ${request.offset}
+ `;
+
+ const [uploads] = await dbQuery(query);
+
+ const media = uploads.map(upload => {
+ const { uploadID, uploadType, uploadSecret, uploadExtra } = upload;
+ const { width, height } = JSON.parse(uploadExtra);
+ const dimensions = { width, height };
+
+ if (uploadType === 'photo') {
+ return {
+ type: 'photo',
+ id: uploadID,
+ uri: getUploadURL(uploadID, uploadSecret),
+ dimensions,
+ };
+ }
+
+ const { thumbnailID, thumbnailUploadSecret } = upload;
+
+ return {
+ type: 'video',
+ id: uploadID,
+ uri: getUploadURL(uploadID, uploadSecret),
+ dimensions,
+ thumbnailID,
+ thumbnailURI: getUploadURL(thumbnailID, thumbnailUploadSecret),
+ };
+ });
+
+ return { media };
+}
+
async function fetchUploadsForMessage(
viewer: Viewer,
mediaMessageContents: $ReadOnlyArray<MediaMessageServerDBContent>,
@@ -203,6 +281,7 @@
getUploadURL,
mediaFromRow,
fetchMedia,
+ fetchMediaForThread,
fetchMediaFromMediaMessageContent,
constructMediaFromMediaMessageContentsAndUploadRows,
};
diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js
--- a/lib/types/thread-types.js
+++ b/lib/types/thread-types.js
@@ -4,6 +4,7 @@
import type { Shape } from './core.js';
import type { CalendarQuery, RawEntryInfo } from './entry-types.js';
+import type { Media } from './media-types.js';
import type {
RawMessageInfo,
MessageTruncationStatuses,
@@ -453,6 +454,15 @@
+userInfos: $ReadOnlyArray<UserInfo>,
};
+export type ThreadFetchMediaResult = {
+ +media: $ReadOnlyArray<Media>,
+};
+export type ThreadFetchMediaRequest = {
+ +threadID: string,
+ +limit: number,
+ +offset: number,
+};
+
export type SidebarInfo = {
+threadInfo: ThreadInfo,
+lastUpdatedTime: number,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 8:52 PM (21 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577286
Default Alt Text
D6485.id23073.diff (4 KB)
Attached To
Mode
D6485: [keyserver] Create a function to query for all uploads from a provided threadID
Attached
Detach File
Event Timeline
Log In to Comment