Users who have linked their Discord account can enable a ping preference in Settings > Notifications. When enabled, their bracket username is replaced with a Discord @mention (<@userId>) in league standings update messages, sending them a push notification and showing their Discord display name. Adds discordPingEnabled column to users, a findDiscordIdsByUserIds model helper, allowed_mentions support to the Discord webhook payload, and a NotificationsSection settings component. https://claude.ai/code/session_01NUv93WRrufHhpZSMyY4bjs
26 lines
968 B
TypeScript
26 lines
968 B
TypeScript
import { eq, inArray, and } from "drizzle-orm";
|
|
import { database } from "~/database/context";
|
|
import * as schema from "~/database/schema";
|
|
|
|
export type LinkedAccount = {
|
|
id: string;
|
|
providerId: string;
|
|
};
|
|
|
|
export async function findLinkedAccountsByUserId(userId: string): Promise<LinkedAccount[]> {
|
|
const db = database();
|
|
return db
|
|
.select({ id: schema.accounts.id, providerId: schema.accounts.providerId })
|
|
.from(schema.accounts)
|
|
.where(eq(schema.accounts.userId, userId));
|
|
}
|
|
|
|
export async function findDiscordIdsByUserIds(userIds: string[]): Promise<Map<string, string>> {
|
|
if (userIds.length === 0) return new Map();
|
|
const db = database();
|
|
const rows = await db
|
|
.select({ userId: schema.accounts.userId, accountId: schema.accounts.accountId })
|
|
.from(schema.accounts)
|
|
.where(and(inArray(schema.accounts.userId, userIds), eq(schema.accounts.providerId, "discord")));
|
|
return new Map(rows.map((r) => [r.userId, r.accountId]));
|
|
}
|