swc/bundler/tests/.cache/deno/a1db4a8415b7048abe237b3238f7b5096543d3fe.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

41 lines
1.6 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/handlers/members/GUILD_MEMBERS_CHUNK.ts
import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { GuildMembersChunk } from "../../types/members/guild_members_chunk.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { Collection } from "../../util/collection.ts";
export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
const payload = data.d as GuildMembersChunk;
const guildId = snowflakeToBigint(payload.guildId);
const members = await Promise.all(
payload.members.map(async (member) => {
const discordenoMember = await structures.createDiscordenoMember(member, guildId);
await cacheHandlers.set("members", discordenoMember.id, discordenoMember);
return discordenoMember;
})
);
// Check if its necessary to resolve the fetchmembers promise for this chunk or if more chunks will be coming
if (payload.nonce) {
const resolve = cache.fetchAllMembersProcessingRequests.get(payload.nonce);
if (!resolve) return;
if (payload.chunkIndex + 1 === payload.chunkCount) {
cache.fetchAllMembersProcessingRequests.delete(payload.nonce);
// Only 1 chunk most likely is all members or users only request a small amount of users
if (payload.chunkCount === 1) {
return resolve(new Collection(members.map((m) => [m.id, m])));
}
return resolve(await cacheHandlers.filter("members", (m) => m.guilds.has(guildId)));
}
}
}