Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/fetchers/thread-fetchers.js
Show All 30 Lines | ): Promise<FetchServerThreadInfosResult> { | ||||
const rolesQuery = SQL` | const rolesQuery = SQL` | ||||
SELECT t.id, t.default_role, r.id AS role, r.name, r.permissions | SELECT t.id, t.default_role, r.id AS role, r.name, r.permissions | ||||
FROM threads t | FROM threads t | ||||
LEFT JOIN roles r ON r.thread = t.id | LEFT JOIN roles r ON r.thread = t.id | ||||
`.append(whereClause); | `.append(whereClause); | ||||
const threadsQuery = SQL` | const threadsQuery = SQL` | ||||
SELECT t.id, t.name, t.parent_thread_id, t.containing_thread_id, | SELECT t.id, t.name, t.parent_thread_id, t.containing_thread_id, | ||||
t.community, t.depth, t.color, t.description, t.type, t.creation_time, | t.community, t.depth, t.color, t.description, t.type, t.creation_time, | ||||
t.source_message, t.replies_count, t.avatar, m.user, m.role, m.permissions, | t.source_message, t.replies_count, t.avatar, t.pinned_count, m.user, | ||||
m.subscription, m.last_read_message < m.last_message AS unread, m.sender | m.role, m.permissions, m.subscription, | ||||
m.last_read_message < m.last_message AS unread, m.sender | |||||
FROM threads t | FROM threads t | ||||
LEFT JOIN memberships m ON m.thread = t.id AND m.role >= 0 | LEFT JOIN memberships m ON m.thread = t.id AND m.role >= 0 | ||||
` | ` | ||||
.append(whereClause) | .append(whereClause) | ||||
.append(SQL` ORDER BY m.user ASC`); | .append(SQL` ORDER BY m.user ASC`); | ||||
const [[threadsResult], [rolesResult]] = await Promise.all([ | const [[threadsResult], [rolesResult]] = await Promise.all([ | ||||
dbQuery(threadsQuery), | dbQuery(threadsQuery), | ||||
dbQuery(rolesQuery), | dbQuery(rolesQuery), | ||||
]); | ]); | ||||
Show All 16 Lines | if (!threadInfos[threadID]) { | ||||
: null, | : null, | ||||
depth: threadsRow.depth, | depth: threadsRow.depth, | ||||
community: threadsRow.community | community: threadsRow.community | ||||
? threadsRow.community.toString() | ? threadsRow.community.toString() | ||||
: null, | : null, | ||||
members: [], | members: [], | ||||
roles: {}, | roles: {}, | ||||
repliesCount: threadsRow.replies_count, | repliesCount: threadsRow.replies_count, | ||||
pinnedCount: threadsRow.pinned_count, | |||||
}; | }; | ||||
if (threadsRow.avatar) { | if (threadsRow.avatar) { | ||||
threadInfos[threadID] = { | threadInfos[threadID] = { | ||||
...threadInfos[threadID], | ...threadInfos[threadID], | ||||
avatar: JSON.parse(threadsRow.avatar), | avatar: JSON.parse(threadsRow.avatar), | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | const hasCodeVersionBelow104 = !hasMinCodeVersion( | ||||
viewer.platformDetails, | viewer.platformDetails, | ||||
104, | 104, | ||||
); | ); | ||||
// TODO (atul): Replace with `hasMinCodeVersion` check once we have a | // TODO (atul): Replace with `hasMinCodeVersion` check once we have a | ||||
// native release with thread avatar editing enabled. | // native release with thread avatar editing enabled. | ||||
const filterThreadEditAvatarPermission = true; | const filterThreadEditAvatarPermission = true; | ||||
const hasCodeVersionBelow209 = !hasMinCodeVersion( | |||||
viewer.platformDetails, | |||||
209, | |||||
); | |||||
const threadInfos = {}; | const threadInfos = {}; | ||||
for (const threadID in serverResult.threadInfos) { | for (const threadID in serverResult.threadInfos) { | ||||
const serverThreadInfo = serverResult.threadInfos[threadID]; | const serverThreadInfo = serverResult.threadInfos[threadID]; | ||||
const threadInfo = rawThreadInfoFromServerThreadInfo( | const threadInfo = rawThreadInfoFromServerThreadInfo( | ||||
serverThreadInfo, | serverThreadInfo, | ||||
viewerID, | viewerID, | ||||
{ | { | ||||
includeVisibilityRules: hasCodeVersionBelow70, | includeVisibilityRules: hasCodeVersionBelow70, | ||||
filterMemberList: hasCodeVersionBelow70, | filterMemberList: hasCodeVersionBelow70, | ||||
shimThreadTypes: hasCodeVersionBelow87 ? shimCommunityRoot : null, | shimThreadTypes: hasCodeVersionBelow87 ? shimCommunityRoot : null, | ||||
hideThreadStructure: hasCodeVersionBelow102, | hideThreadStructure: hasCodeVersionBelow102, | ||||
filterDetailedThreadEditPermissions: hasCodeVersionBelow104, | filterDetailedThreadEditPermissions: hasCodeVersionBelow104, | ||||
filterThreadEditAvatarPermission, | filterThreadEditAvatarPermission, | ||||
excludePinInfo: hasCodeVersionBelow209, | |||||
}, | }, | ||||
); | ); | ||||
if (threadInfo) { | if (threadInfo) { | ||||
threadInfos[threadID] = threadInfo; | threadInfos[threadID] = threadInfo; | ||||
} | } | ||||
} | } | ||||
return { threadInfos }; | return { threadInfos }; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |