Skip to content

Commit

Permalink
render identicon if user avatar image is null
Browse files Browse the repository at this point in the history
  • Loading branch information
slatinsky committed Jun 30, 2023
1 parent 19e1d1a commit 6059ec4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"type": "module",
"dependencies": {
"axios": "^1.2.6",
"identicons": "^0.1.0",
"lodash-es": "^4.17.21",
"moment": "^2.29.4"
},
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/components/messages/NewMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import MessageStickers from './MessageStickers.svelte';
import { guildId } from 'src/js/stores';
import identicons from 'identicons'
export let message: Message;
export let previousMessage: Message | null = null;
export let referencedMessage: Message | null = null;
Expand Down Expand Up @@ -198,7 +200,11 @@

{#if !mergeWithPrevious}
{#if message.type != 'ThreadCreated'}
<ImageGallery asset={message.author?.avatar} imgclass={"chatlog__avatar"} />
{#if message.author?.avatar}
<ImageGallery asset={message.author?.avatar} imgclass={"chatlog__avatar"} />
{:else}
<img class="chatlog__avatar" src={identicons.generateSVGDataURIString(message.author._id, { width: 200, size: 3 })} />
{/if}
{/if}
{/if}
</div>
Expand Down Expand Up @@ -427,4 +433,9 @@
font-size: 12px;
white-space: nowrap; /* never break the line */
}
.chatlog__avatar {
image-rendering: crisp-edges;
background-color: white; /*For identicons*/
}
</style>

0 comments on commit 6059ec4

Please sign in to comment.