Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/fetchers/user-fetchers.js
// @flow | // @flow | ||||
import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; | ||||
import type { AvatarDBContent, ClientAvatar } from 'lib/types/avatar-types.js'; | |||||
import { | import { | ||||
undirectedStatus, | undirectedStatus, | ||||
directedStatus, | directedStatus, | ||||
userRelationshipStatus, | userRelationshipStatus, | ||||
} from 'lib/types/relationship-types.js'; | } from 'lib/types/relationship-types.js'; | ||||
import { | import { | ||||
communityThreadTypes, | communityThreadTypes, | ||||
threadPermissions, | threadPermissions, | ||||
Show All 14 Lines | |||||
async function fetchUserInfos( | async function fetchUserInfos( | ||||
userIDs: string[], | userIDs: string[], | ||||
): Promise<{ [id: string]: GlobalUserInfo }> { | ): Promise<{ [id: string]: GlobalUserInfo }> { | ||||
if (userIDs.length <= 0) { | if (userIDs.length <= 0) { | ||||
return {}; | return {}; | ||||
} | } | ||||
const query = SQL` | const query = SQL` | ||||
SELECT id, username FROM users WHERE id IN (${userIDs}) | SELECT id, username, avatar | ||||
FROM users | |||||
WHERE id IN (${userIDs}) | |||||
`; | `; | ||||
const [result] = await dbQuery(query); | const [result] = await dbQuery(query); | ||||
const userInfos = {}; | const userInfos = {}; | ||||
for (const row of result) { | for (const row of result) { | ||||
const id = row.id.toString(); | const id = row.id.toString(); | ||||
userInfos[id] = { | const avatar: ?AvatarDBContent = row.avatar ? JSON.parse(row.avatar) : null; | ||||
// TODO: Handle construction of `ClientImageAvatar` when `type === 'image'` | |||||
const clientAvatar: ?ClientAvatar = | |||||
avatar && avatar.type !== 'image' ? avatar : null; | |||||
userInfos[id] = avatar | |||||
? { | |||||
id, | |||||
username: row.username, | |||||
avatar: clientAvatar, | |||||
} | |||||
: { | |||||
id, | id, | ||||
username: row.username, | username: row.username, | ||||
}; | }; | ||||
} | } | ||||
for (const userID of userIDs) { | for (const userID of userIDs) { | ||||
if (!userInfos[userID]) { | if (!userInfos[userID]) { | ||||
userInfos[userID] = { | userInfos[userID] = { | ||||
id: userID, | id: userID, | ||||
username: null, | username: null, | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 273 Lines • Show Last 20 Lines |