Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3752313
D7430.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
D7430.diff
View Options
diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js
--- a/keyserver/src/updaters/thread-updaters.js
+++ b/keyserver/src/updaters/thread-updaters.js
@@ -614,10 +614,73 @@
if (Object.keys(sqlUpdate).length === 0) {
return;
}
- const updateQuery = SQL`
- UPDATE threads SET ${sqlUpdate} WHERE id = ${request.threadID}
- `;
- await dbQuery(updateQuery);
+
+ const { avatar: avatarUpdate, ...nonAvatarUpdates } = sqlUpdate;
+ const updatePromises = [];
+
+ if (Object.keys(nonAvatarUpdates).length > 0) {
+ const nonAvatarUpdateQuery = SQL`
+ UPDATE threads
+ SET ${nonAvatarUpdates}
+ WHERE id = ${request.threadID}
+ `;
+ updatePromises.push(dbQuery(nonAvatarUpdateQuery));
+ }
+
+ if (avatarUpdate !== undefined) {
+ const avatarUploadID =
+ avatar && avatar.type === 'image' ? avatar.uploadID : null;
+
+ const avatarUpdateQuery = SQL`
+ START TRANSACTION;
+
+ UPDATE uploads
+ SET container = NULL
+ WHERE container = ${request.threadID}
+ AND ${avatarUploadID} IS NOT NULL
+ AND EXISTS (
+ SELECT 1
+ FROM uploads
+ WHERE id = ${avatarUploadID}
+ AND ${avatarUploadID} IS NOT NULL
+ AND uploader = ${viewer.userID}
+ AND container IS NULL
+ AND thread IS NULL
+ );
+
+ UPDATE uploads
+ SET container = ${request.threadID}
+ WHERE id = ${avatarUploadID}
+ AND ${avatarUploadID} IS NOT NULL
+ AND uploader = ${viewer.userID}
+ AND container IS NULL
+ AND thread IS NULL;
+
+ UPDATE threads
+ SET avatar = ${avatarUpdate}
+ WHERE id = ${request.threadID}
+ AND (
+ ${avatarUploadID} IS NULL
+ OR EXISTS (
+ SELECT 1
+ FROM uploads
+ WHERE id = ${avatarUploadID}
+ AND ${avatarUploadID} IS NOT NULL
+ AND uploader = ${viewer.userID}
+ AND container = ${request.threadID}
+ AND thread IS NULL
+ )
+ );
+
+ COMMIT;
+ `;
+
+ updatePromises.push(
+ dbQuery(avatarUpdateQuery, { multipleStatements: true }),
+ );
+ }
+
+ await Promise.all(updatePromises);
})();
const updateRolesPromise = (async () => {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 11, 12:23 AM (19 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2857470
Default Alt Text
D7430.diff (2 KB)
Attached To
Mode
D7430: [keyserver] Update `updateThread` to handle image avatars
Attached
Detach File
Event Timeline
Log In to Comment