Page MenuHomePhabricator

D4977.diff
No OneTemporary

D4977.diff

diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js
--- a/keyserver/src/creators/thread-creator.js
+++ b/keyserver/src/creators/thread-creator.js
@@ -27,7 +27,10 @@
import { dbQuery, SQL } from '../database/database';
import { fetchMessageInfoByID } from '../fetchers/message-fetchers';
-import { determineThreadAncestry } from '../fetchers/thread-fetchers';
+import {
+ determineThreadAncestry,
+ personalThreadQuery,
+} from '../fetchers/thread-fetchers';
import {
checkThreadPermission,
validateCandidateMembers,
@@ -233,17 +236,7 @@
otherMemberID,
'Other member id should be set for a PERSONAL thread',
);
- existingThreadQuery = SQL`
- SELECT t.id
- FROM threads t
- INNER JOIN memberships m1
- ON m1.thread = t.id AND m1.user = ${viewer.userID}
- INNER JOIN memberships m2
- ON m2.thread = t.id AND m2.user = ${otherMemberID}
- WHERE t.type = ${threadTypes.PERSONAL}
- AND m1.role > 0
- AND m2.role > 0
- `;
+ existingThreadQuery = personalThreadQuery(viewer.userID, otherMemberID);
} else if (sourceMessageID) {
existingThreadQuery = SQL`
SELECT t.id
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
@@ -214,6 +214,32 @@
return { containingThreadID, community, depth };
}
+function personalThreadQuery(
+ firstMemberID: string,
+ secondMemberID: string,
+): SQLStatementType {
+ return SQL`
+ SELECT t.id
+ FROM threads t
+ INNER JOIN memberships m1
+ ON m1.thread = t.id AND m1.user = ${firstMemberID}
+ INNER JOIN memberships m2
+ ON m2.thread = t.id AND m2.user = ${secondMemberID}
+ WHERE t.type = ${threadTypes.PERSONAL}
+ AND m1.role > 0
+ AND m2.role > 0
+ `;
+}
+
+async function fetchPersonalThreadID(
+ viewerID: string,
+ otherMemberID: string,
+): Promise<?string> {
+ const query = personalThreadQuery(viewerID, otherMemberID);
+ const [threads] = await dbQuery(query);
+ return threads[0]?.id.toString();
+}
+
export {
fetchServerThreadInfos,
fetchThreadInfos,
@@ -221,4 +247,6 @@
verifyThreadIDs,
verifyThreadID,
determineThreadAncestry,
+ personalThreadQuery,
+ fetchPersonalThreadID,
};

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 25, 5:27 AM (11 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2701692
Default Alt Text
D4977.diff (2 KB)

Event Timeline