-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Avatar and Username example in iframe playground (#26)
* Update pattern for fetching avatars and usernames * Wrap user id in Math.abs before modulo * Patch usage in react-colyseus * cleanup iframe plaground
- Loading branch information
Showing
14 changed files
with
138 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
examples/iframe-playground/packages/client/src/utils/fetchGuildsUserAvatarAndNickname.tsx
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
examples/iframe-playground/packages/client/src/utils/getUserAvatarUri.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
interface GetUserAvatarArgs { | ||
userId: string; | ||
avatarHash?: string | null; | ||
guildId?: string | null; | ||
guildAvatarHash?: string | null; | ||
cdn?: string | null; | ||
size?: number; | ||
} | ||
export function getUserAvatarUri({ | ||
userId, | ||
avatarHash, | ||
guildId, | ||
guildAvatarHash, | ||
cdn = `https://cdn.discordapp.com`, | ||
size = 256, | ||
}: GetUserAvatarArgs): string { | ||
if (guildId != null && guildAvatarHash != null) { | ||
return `${cdn}/guilds/${guildId}/users/${userId}/avatars/${guildAvatarHash}.png?size=${size}`; | ||
} | ||
if (avatarHash != null) { | ||
return `${cdn}/avatars/${userId}/${avatarHash}.png?size=${size}`; | ||
} | ||
|
||
const defaultAvatarIndex = Math.abs(Number(userId) >> 22) % 6; | ||
return `${cdn}/embed/avatars/${defaultAvatarIndex}.png?size=${size}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.