Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32221612
D6929.1765198745.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D6929.1765198745.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
@@ -23,6 +23,7 @@
type UpdateThreadRequest,
type ServerThreadJoinRequest,
type ThreadJoinResult,
+ type ToggleMessagePinRequest,
threadPermissions,
threadTypes,
} from 'lib/types/thread-types.js';
@@ -841,6 +842,38 @@
await createUpdates(updateDatas);
}
+async function toggleMessagePinForThread(
+ viewer: Viewer,
+ request: ToggleMessagePinRequest,
+): Promise<void> {
+ const { messageID, action } = request;
+
+ const threadQuery = SQL`SELECT thread FROM messages WHERE id = ${messageID}`;
+ const [threadResult] = await dbQuery(threadQuery);
+ const threadID = threadResult[0].thread.toString();
+
+ const hasPermission = await checkThreadPermission(
+ viewer,
+ threadID,
+ threadPermissions.MANAGE_PINS,
+ );
+
+ if (!hasPermission) {
+ throw new ServerError('invalid_credentials');
+ }
+
+ const pinnedValue = action === 'pin' ? 1 : 0;
+ const pinTimeValue = action === 'pin' ? Date.now() : null;
+
+ const togglePinQuery = SQL`
+ UPDATE messages
+ SET pinned = ${pinnedValue}, pin_time = ${pinTimeValue}
+ WHERE id = ${messageID} AND thread = ${threadID}
+ `;
+
+ await dbQuery(togglePinQuery);
+}
+
export {
updateRole,
removeMembers,
@@ -848,4 +881,5 @@
updateThread,
joinThread,
updateThreadMembers,
+ toggleMessagePinForThread,
};
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
@@ -473,6 +473,11 @@
+mostRecentNonLocalMessage: ?string,
};
+export type ToggleMessagePinRequest = {
+ +messageID: string,
+ +action: 'pin' | 'unpin',
+};
+
// We can show a max of 3 sidebars inline underneath their parent in the chat
// tab. If there are more, we show a button that opens a modal to see the rest
export const maxReadSidebars = 3;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 8, 12:59 PM (13 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5848364
Default Alt Text
D6929.1765198745.diff (1 KB)
Attached To
Mode
D6929: [keyserver] Add a function to toggle the pin status of a message
Attached
Detach File
Event Timeline
Log In to Comment