Save discord avatar uri on link (#3059)

* Initial avatars

* Only store hash

* avatarHash -> discordAvatar
This commit is contained in:
Bruce Berrios 2022-06-01 15:36:22 -04:00 committed by GitHub
parent 4e0a545f12
commit defa9a3f55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 5 deletions

View file

@ -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);

View file

@ -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: "" } }
);
}

View file

@ -92,6 +92,7 @@ declare namespace MonkeyTypes {
canManageApeKeys?: boolean;
favoriteQuotes?: Record<string, string[]>;
needsToChangeName?: boolean;
discordAvatar?: string;
}
type UserQuoteRatings = Record<string, Record<string, number>>;

View file

@ -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,

View file

@ -463,6 +463,7 @@ declare namespace MonkeyTypes {
config?: Config;
favoriteQuotes: FavoriteQuotes;
needsToChangeName?: boolean;
discordAvatar?: string;
}
type FavoriteQuotes = Record<string, string[]>;