mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-26 07:44:01 +08:00
Save discord avatar uri on link (#3059)
* Initial avatars * Only store hash * avatarHash -> discordAvatar
This commit is contained in:
parent
4e0a545f12
commit
defa9a3f55
5 changed files with 12 additions and 5 deletions
|
@ -137,7 +137,7 @@ export async function linkDiscord(
|
|||
throw new MonkeyError(403, "Banned accounts cannot link with Discord");
|
||||
}
|
||||
|
||||
const { id: discordId } = await linkAccount(tokenType, accessToken);
|
||||
const { id: discordId, avatar } = await linkAccount(tokenType, accessToken);
|
||||
|
||||
if (!discordId) {
|
||||
throw new MonkeyError(
|
||||
|
@ -155,7 +155,7 @@ export async function linkDiscord(
|
|||
);
|
||||
}
|
||||
|
||||
await UserDAL.linkDiscord(uid, discordId);
|
||||
await UserDAL.linkDiscord(uid, discordId, avatar);
|
||||
|
||||
George.linkDiscord(discordId, uid);
|
||||
Logger.logToDb("user_discord_link", `linked to ${discordId}`, uid);
|
||||
|
|
|
@ -389,10 +389,14 @@ export async function updateTypingStats(
|
|||
|
||||
export async function linkDiscord(
|
||||
uid: string,
|
||||
discordId: string
|
||||
discordId: string,
|
||||
discordAvatar?: string
|
||||
): Promise<UpdateResult> {
|
||||
await getUser(uid, "link discord");
|
||||
return await getUsersCollection().updateOne({ uid }, { $set: { discordId } });
|
||||
|
||||
const updates = _.pickBy({ discordId, discordAvatar }, _.identity);
|
||||
|
||||
return await getUsersCollection().updateOne({ uid }, { $set: updates });
|
||||
}
|
||||
|
||||
export async function unlinkDiscord(uid: string): Promise<UpdateResult> {
|
||||
|
@ -400,7 +404,7 @@ export async function unlinkDiscord(uid: string): Promise<UpdateResult> {
|
|||
|
||||
return await getUsersCollection().updateOne(
|
||||
{ uid },
|
||||
{ $set: { discordId: undefined } }
|
||||
{ $unset: { discordId: "", discordAvatar: "" } }
|
||||
);
|
||||
}
|
||||
|
||||
|
|
1
backend/src/types/types.d.ts
vendored
1
backend/src/types/types.d.ts
vendored
|
@ -92,6 +92,7 @@ declare namespace MonkeyTypes {
|
|||
canManageApeKeys?: boolean;
|
||||
favoriteQuotes?: Record<string, string[]>;
|
||||
needsToChangeName?: boolean;
|
||||
discordAvatar?: string;
|
||||
}
|
||||
|
||||
type UserQuoteRatings = Record<string, Record<string, number>>;
|
||||
|
|
|
@ -80,6 +80,7 @@ export async function initSnapshot(): Promise<
|
|||
snap.banned = userData.banned;
|
||||
snap.verified = userData.verified;
|
||||
snap.discordId = userData.discordId;
|
||||
snap.discordAvatar = userData.discordAvatar;
|
||||
snap.needsToChangeName = userData.needsToChangeName;
|
||||
snap.globalStats = {
|
||||
time: userData.timeTyping,
|
||||
|
|
1
frontend/src/ts/types/types.d.ts
vendored
1
frontend/src/ts/types/types.d.ts
vendored
|
@ -463,6 +463,7 @@ declare namespace MonkeyTypes {
|
|||
config?: Config;
|
||||
favoriteQuotes: FavoriteQuotes;
|
||||
needsToChangeName?: boolean;
|
||||
discordAvatar?: string;
|
||||
}
|
||||
|
||||
type FavoriteQuotes = Record<string, string[]>;
|
||||
|
|
Loading…
Reference in a new issue