Page MenuHomePhorge

D6929.1765198745.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D6929.1765198745.diff

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

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)

Event Timeline