Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/creators/message-creator.js
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
import { creationString } from '../utils/idempotent.js'; | import { creationString } from '../utils/idempotent.js'; | ||||
type UserThreadInfo = { | type UserThreadInfo = { | ||||
+devices: Map< | +devices: Map< | ||||
string, | string, | ||||
{ | { | ||||
+platform: string, | +platform: string, | ||||
+deviceToken: string, | +deviceToken: string, | ||||
+cookieID: string, | |||||
+codeVersion: ?string, | +codeVersion: ?string, | ||||
}, | }, | ||||
>, | >, | ||||
+threadIDs: Set<string>, | +threadIDs: Set<string>, | ||||
+notFocusedThreadIDs: Set<string>, | +notFocusedThreadIDs: Set<string>, | ||||
+userNotMemberOfSubthreads: Set<string>, | +userNotMemberOfSubthreads: Set<string>, | ||||
+subthreadsCanSetToUnread: Set<string>, | +subthreadsCanSetToUnread: Set<string>, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | for (const subthread of subthreadPermissionsToCheck) { | ||||
join.append(SQL`thread = ${subthread} AND `); | join.append(SQL`thread = ${subthread} AND `); | ||||
join.append(`stm${index}.user = m.user`); | join.append(`stm${index}.user = m.user`); | ||||
subthreadJoins.push(join); | subthreadJoins.push(join); | ||||
} | } | ||||
const time = earliestFocusedTimeConsideredExpired(); | const time = earliestFocusedTimeConsideredExpired(); | ||||
const visibleExtractString = `$.${threadPermissions.VISIBLE}.value`; | const visibleExtractString = `$.${threadPermissions.VISIBLE}.value`; | ||||
const query = SQL` | const query = SQL` | ||||
SELECT m.user, m.thread, c.platform, c.device_token, c.versions, | SELECT m.user, m.thread, c.platform, c.device_token, c.versions, c.id, | ||||
f.user AS focused_user | f.user AS focused_user | ||||
`; | `; | ||||
query.append(subthreadSelects); | query.append(subthreadSelects); | ||||
query.append(SQL` | query.append(SQL` | ||||
FROM memberships m | FROM memberships m | ||||
LEFT JOIN cookies c ON c.user = m.user AND c.device_token IS NOT NULL | LEFT JOIN cookies c ON c.user = m.user AND c.device_token IS NOT NULL | ||||
LEFT JOIN focused f ON f.user = m.user AND f.thread = m.thread | LEFT JOIN focused f ON f.user = m.user AND f.thread = m.thread | ||||
AND f.time > ${time} | AND f.time > ${time} | ||||
Show All 9 Lines | ) { | ||||
const [result] = await dbQuery(query); | const [result] = await dbQuery(query); | ||||
for (const row of result) { | for (const row of result) { | ||||
const userID = row.user.toString(); | const userID = row.user.toString(); | ||||
const threadID = row.thread.toString(); | const threadID = row.thread.toString(); | ||||
const deviceToken = row.device_token; | const deviceToken = row.device_token; | ||||
const focusedUser = !!row.focused_user; | const focusedUser = !!row.focused_user; | ||||
const { platform } = row; | const { platform } = row; | ||||
const versions = JSON.parse(row.versions); | const versions = JSON.parse(row.versions); | ||||
const cookieID = row.id; | |||||
let thisUserInfo = perUserInfo.get(userID); | let thisUserInfo = perUserInfo.get(userID); | ||||
if (!thisUserInfo) { | if (!thisUserInfo) { | ||||
thisUserInfo = { | thisUserInfo = { | ||||
devices: new Map(), | devices: new Map(), | ||||
threadIDs: new Set(), | threadIDs: new Set(), | ||||
notFocusedThreadIDs: new Set(), | notFocusedThreadIDs: new Set(), | ||||
userNotMemberOfSubthreads: new Set(), | userNotMemberOfSubthreads: new Set(), | ||||
subthreadsCanSetToUnread: new Set(), | subthreadsCanSetToUnread: new Set(), | ||||
Show All 19 Lines | if (!thisUserInfo) { | ||||
if ( | if ( | ||||
!isSubthreadMember || | !isSubthreadMember || | ||||
!permissionLookup(subthreadPermissions, threadPermissions.VISIBLE) | !permissionLookup(subthreadPermissions, threadPermissions.VISIBLE) | ||||
) { | ) { | ||||
thisUserInfo.userNotMemberOfSubthreads.add(subthread); | thisUserInfo.userNotMemberOfSubthreads.add(subthread); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (deviceToken) { | if (deviceToken && cookieID) { | ||||
thisUserInfo.devices.set(deviceToken, { | thisUserInfo.devices.set(deviceToken, { | ||||
platform, | platform, | ||||
deviceToken, | deviceToken, | ||||
cookieID: cookieID.toString(), | |||||
codeVersion: versions ? versions.codeVersion : null, | codeVersion: versions ? versions.codeVersion : null, | ||||
}); | }); | ||||
} | } | ||||
thisUserInfo.threadIDs.add(threadID); | thisUserInfo.threadIDs.add(threadID); | ||||
if (!focusedUser) { | if (!focusedUser) { | ||||
thisUserInfo.notFocusedThreadIDs.add(threadID); | thisUserInfo.notFocusedThreadIDs.add(threadID); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |