diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index d0d445b9d..99523dab8 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -244,24 +244,28 @@ router.get( return x; }); - await ret - .filter((x: MessageCreateSchema) => x.interaction_metadata && !x.interaction_metadata.user) - .forEachAsync(async (x: MessageCreateSchema) => { - x.interaction_metadata!.user = x.interaction!.user = await User.findOneOrFail({ where: { id: (x as Message).interaction_metadata!.user_id } }); - }); + await Promise.all( + ret + .filter((x: MessageCreateSchema) => x.interaction_metadata && !x.interaction_metadata.user) + .map(async (x: MessageCreateSchema) => { + x.interaction_metadata!.user = x.interaction!.user = await User.findOneOrFail({ where: { id: (x as Message).interaction_metadata!.user_id } }); + }), + ); // polyfill message references for old messages - await ret - .filter((msg) => msg.message_reference && !msg.referenced_message?.id) - .forEachAsync(async (msg) => { - const whereOptions: { id: string; guild_id?: string; channel_id?: string } = { - id: msg.message_reference!.message_id, - }; - if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id; - if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id; + await Promise.all( + ret + .filter((msg) => msg.message_reference && !msg.referenced_message?.id) + .map(async (msg) => { + const whereOptions: { id: string; guild_id?: string; channel_id?: string } = { + id: msg.message_reference!.message_id, + }; + if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id; + if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id; - msg.referenced_message = await Message.findOne({ where: whereOptions, relations: ["author", "mentions", "mention_roles", "mention_channels"] }); - }); + msg.referenced_message = await Message.findOne({ where: whereOptions, relations: ["author", "mentions", "mention_roles", "mention_channels"] }); + }), + ); return res.json(ret); }, diff --git a/src/api/routes/guilds/#guild_id/invites.ts b/src/api/routes/guilds/#guild_id/invites.ts index ec3116c95..9372651ae 100644 --- a/src/api/routes/guilds/#guild_id/invites.ts +++ b/src/api/routes/guilds/#guild_id/invites.ts @@ -40,11 +40,13 @@ router.get( relations: PublicInviteRelation, }); - await invites - .filter((i) => i.isExpired()) - .forEachAsync(async (i) => { - await Invite.delete({ code: i.code }); - }); + await Promise.all( + invites + .filter((i) => i.isExpired()) + .map(async (i) => { + await Invite.delete({ code: i.code }); + }), + ); return res.json(invites.filter((i) => !i.isExpired())); }, diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts index a4b1a8996..74cceb769 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts @@ -19,7 +19,6 @@ declare global { interface Array { partition(filter: (elem: T) => boolean): [T[], T[]]; - forEachAsync(callback: (elem: T, index: number, array: T[]) => Promise): Promise; remove(item: T): void; distinct(): T[]; } @@ -33,10 +32,6 @@ export function arrayPartition(array: T[], filter: (elem: T) => boolean): [T[ return [pass, fail]; } -export async function arrayForEachAsync(array: T[], callback: (elem: T, index: number, array: T[]) => Promise): Promise { - await Promise.all(array.map(callback)); -} - export function arrayRemove(this: T[], item: T): void { const index = this.indexOf(item); if (index > -1) { @@ -54,11 +49,6 @@ if (!Array.prototype.partition) return arrayPartition(this, filter); }; -if (!Array.prototype.forEachAsync) - Array.prototype.forEachAsync = function (this: T[], callback: (elem: T, index: number, array: T[]) => Promise) { - return arrayForEachAsync(this, callback); - }; - if (!Array.prototype.remove) Array.prototype.remove = function (this: T[], item: T) { return arrayRemove.call(this, item);