add guild position building
This commit is contained in:
parent
3f4335ecb4
commit
2d5bd7f4d1
@ -55,7 +55,7 @@ import {
|
||||
import { check } from "./instanceOf";
|
||||
import { In } from "typeorm";
|
||||
import { PreloadedUserSettings } from "discord-protos";
|
||||
import { DefaultUserGuildSettings, DMChannel, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection, PublicVoiceState, PublicVoiceStateProjection } from "@spacebar/schemas";
|
||||
import { DefaultUserGuildSettings, DMChannel, GuildFolder, IdentifySchema, PrivateUserProjection, PublicUser, PublicUserProjection, PublicVoiceState, PublicVoiceStateProjection } from "@spacebar/schemas";
|
||||
|
||||
// TODO: user sharding
|
||||
// TODO: check privileged intents, if defined in the config
|
||||
@ -75,6 +75,29 @@ const tryGetUserFromToken = async (...args: Parameters<typeof checkToken>) => {
|
||||
}
|
||||
};
|
||||
|
||||
const buildGuildPositions = (folders: GuildFolder[], guildIds: string[],) => {
|
||||
const added = new Set<string>();
|
||||
const result: string[] = [];
|
||||
|
||||
for (const folder of folders) {
|
||||
for (const guildId of folder.guild_ids) {
|
||||
if (!added.has(guildId)) {
|
||||
added.add(guildId);
|
||||
result.push(guildId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const guildId of guildIds) {
|
||||
if (!added.has(guildId)) {
|
||||
added.add(guildId);
|
||||
result.push(guildId);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
const totalSw = Stopwatch.startNew();
|
||||
const taskSw = Stopwatch.startNew();
|
||||
@ -516,7 +539,9 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
||||
});
|
||||
const remapReadStateIdsTime = taskSw.getElapsedAndReset();
|
||||
|
||||
(user.settings as any).guild_positions = [];
|
||||
user.settings.guild_positions = user.settings.guild_folders
|
||||
? buildGuildPositions(user.settings.guild_folders, guildIds)
|
||||
: [];
|
||||
|
||||
const d: ReadyEventData = {
|
||||
v: 9,
|
||||
|
||||
Reference in New Issue
Block a user