Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3296234
D7393.id25025.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7393.id25025.diff
View Options
diff --git a/keyserver/src/fetchers/thread-fetchers.js b/keyserver/src/fetchers/thread-fetchers.js
--- a/keyserver/src/fetchers/thread-fetchers.js
+++ b/keyserver/src/fetchers/thread-fetchers.js
@@ -1,5 +1,7 @@
// @flow
+import invariant from 'invariant';
+
import { getAllThreadPermissions } from 'lib/permissions/thread-permissions.js';
import {
rawThreadInfoFromServerThreadInfo,
@@ -7,6 +9,7 @@
getCommunity,
} from 'lib/shared/thread-utils.js';
import { hasMinCodeVersion } from 'lib/shared/version-utils.js';
+import type { AvatarDBContent, ClientAvatar } from 'lib/types/avatar-types.js';
import type { RawMessageInfo, MessageInfo } from 'lib/types/message-types.js';
import {
threadTypes,
@@ -16,6 +19,7 @@
} from 'lib/types/thread-types.js';
import { ServerError } from 'lib/utils/errors.js';
+import { getUploadURL } from './upload-fetchers.js';
import { dbQuery, SQL } from '../database/database.js';
import type { SQLStatementType } from '../database/types.js';
import type { Viewer } from '../session/viewer.js';
@@ -40,9 +44,11 @@
t.community, t.depth, t.color, t.description, t.type, t.creation_time,
t.source_message, t.replies_count, t.avatar, t.pinned_count, m.user,
m.role, m.permissions, m.subscription,
- m.last_read_message < m.last_message AS unread, m.sender
+ m.last_read_message < m.last_message AS unread, m.sender,
+ up.id AS upload_id, up.secret AS upload_secret
FROM threads t
LEFT JOIN memberships m ON m.thread = t.id AND m.role >= 0
+ LEFT JOIN uploads up ON up.container = t.id
`
.append(whereClause)
.append(SQL` ORDER BY m.user ASC`);
@@ -78,9 +84,30 @@
pinnedCount: threadsRow.pinned_count,
};
if (threadsRow.avatar) {
+ const avatar: AvatarDBContent = JSON.parse(threadsRow.avatar);
+ let clientAvatar: ?ClientAvatar;
+ if (avatar && avatar.type !== 'image') {
+ clientAvatar = avatar;
+ } else if (
+ avatar &&
+ avatar.type === 'image' &&
+ threadsRow.upload_id &&
+ threadsRow.upload_secret
+ ) {
+ const uploadID = threadsRow.upload_id.toString();
+ invariant(
+ uploadID === avatar.uploadID,
+ `uploadID of upload should match uploadID of image avatar`,
+ );
+ clientAvatar = {
+ type: 'image',
+ uri: getUploadURL(uploadID, threadsRow.upload_secret),
+ };
+ }
+
threadInfos[threadID] = {
...threadInfos[threadID],
- avatar: JSON.parse(threadsRow.avatar),
+ avatar: clientAvatar,
};
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 18, 1:36 AM (22 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2532223
Default Alt Text
D7393.id25025.diff (2 KB)
Attached To
Mode
D7393: [keyserver] Update `thread-fetchers` to handle image avatars
Attached
Detach File
Event Timeline
Log In to Comment