Skip to content

Commit

Permalink
fix: stricter message data model validation + allow empty avatars and…
Browse files Browse the repository at this point in the history
… names
  • Loading branch information
valeriansaliou committed Jun 27, 2022
1 parent beccadb commit 96c10d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The messaging view exposes a programmatic API that lets applications manipulate
- Pull out a message from the store: `MessagingStore.retract(messageId<string>)<boolean>`
- Flush all content from the store: `MessagingStore.flush()<boolean>`

All inserted message objects are required to hold the following keys: `id`, `type`, `date`, `content` and `from`. When updating an existing message, only modified keys need to be passed.
All inserted message objects are required to hold the following keys: `id`, `type`, `date`, `content` and `from` (with at least `from.jid` set). When updating an existing message, only modified keys need to be passed.

**Text messages are formatted as such:**

Expand Down
4 changes: 4 additions & 0 deletions src/messaging/components/avatar/avatar.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
object-fit: cover;
display: block;
}

.avatar.avatar--placeholder {
box-shadow: none;
}
11 changes: 9 additions & 2 deletions src/messaging/messaging.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@
:key="entry.id + '@' + (entry.updatedAt || 0)"
>
<div class="message" v-if="message" v-scope="Message(message)">
<img class="avatar" v-scope="Avatar(user)" :src="avatarUrl" alt="" />
<img
v-if="user.avatar"
class="avatar"
v-scope="Avatar(user)"
:src="avatarUrl"
alt=""
/>
<span v-else class="avatar avatar--placeholder"></span>

<div class="message-inner" @vue:mounted="mounted">
<div class="message-origin">
<span class="message-origin-name">{{ user.name }}</span>
<span class="message-origin-name">{{ user.name || user.jid }}</span>

<span v-if="date" class="message-origin-date">{{ date }}</span>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/messaging/stores/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ function FeedStore() {
!message.type ||
!message.date ||
!message.content ||
!message.from
!message.from ||
!message.from.jid
) {
throw new Error(
"Message to insert is incomplete (missing attribute)"
Expand Down

0 comments on commit 96c10d0

Please sign in to comment.