Skip to content

Commit

Permalink
feat(chat): ui messages progress
Browse files Browse the repository at this point in the history
  • Loading branch information
maljuburi committed Jul 7, 2022
1 parent 496a97e commit bffd700
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
26 changes: 19 additions & 7 deletions components/views/chat/conversation/Conversation.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
<div id="conversation">
<!-- <UiLoadersMessage :count="3" v-if="loading" /> -->
<UiLoadersMessage :count="3" v-if="loading" />
<div class="group" v-for="message of messages">
<div v-if="message.type === 'direct'">
<div v-if="message.from === did">
<p>SELF:</p>
</div>
<div v-else>
<p>FRIEND:</p>
</div>
<span>
<UiUserName :username="message.from" :badge="badge" />
</span>
<TypographyText :text="message.at" data-cy="chat-timestamp" />
<p>{{message.body}}</p>
</div>
<p>--------</p>
</div>
<!-- <div class="group" v-for="group in messages" v-else>
<div v-if="group.type === 'group'">
<Group :group="group" :key="group.id" :groupId="groupId" />
<!--
<div class="group" v-for="message in messages">
<div v-if="message.type === 'direct'">
<Group :group="message" :key="message.id" :groupId="groupId" />
</div>
<div v-if="group.type === 'caret_divider'">
<div v-if="message.type === 'caret_divider'">
<UiCaretDivider text="New Messages" />
</div>
<div v-else-if="group.type === 'divider'">
<TypographyHorizontalRuleText :value="group.at.toString()" />
<div v-else-if="message.type === 'divider'">
<TypographyHorizontalRuleText :value="message.at.toString()" />
</div>
</div>
<div v-if="textile.messageLoading" data-cy="loading-indicator" class="zoop">
Expand Down
4 changes: 4 additions & 0 deletions components/views/chat/conversation/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default Vue.extend({
type: String,
default: '',
},
did: {
type: String,
default: '',
},
},
computed: {
...mapState({
Expand Down
13 changes: 8 additions & 5 deletions libraries/Iridium/chat/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,14 @@ export default class ChatManager extends Emitter<ConversationMessage> {
action: 'message',
message: messageCID,
})
await this.iridium.connector.send(conversation, {
to: await Promise.all(
conversation.participants.map((p) => Iridium.DIDToPeerId(p)),
),
})
await this.iridium.connector.send(
{ type: 'chat/message', conversationId: id, messageCID },
{
to: await Promise.all(
conversation.participants.map((p) => Iridium.DIDToPeerId(p)),
),
},
)
this.emit(`conversation/${id}`, {
action: 'message',
message: messageCID,
Expand Down
4 changes: 2 additions & 2 deletions pages/chat/direct/Direct.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="direct">
<!-- <UiChatEncrypted v-if="$route.params.address" /> -->
<Conversation :messages="messages" :loading="false" />
<UiChatEncrypted v-if="$route.params.address" />
<Conversation :did="did" :messages="messages" :loading="false" />
</div>
12 changes: 5 additions & 7 deletions pages/chat/direct/_address.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default Vue.extend({
data() {
return {
messages: [],
did: iridium.connector.id,
}
},
computed: {
Expand Down Expand Up @@ -91,13 +92,10 @@ export default Vue.extend({
this.messages.push(message)
})
await iridium.chat.subscribeToChannel(this.friend, async (event) => {
if (Object.keys(event.payload.message).length) {
const msgs = []
for (const msg in event.payload.message) {
msgs.push(await iridium.connector.load(msg))
}
console.log('in-coming chat messages...', msgs)
// todo: better append those messages to the UI
if (event.payload.messageCID && event.payload.type === 'chat/message') {
this.messages.push(
await iridium.connector.load(event.payload.messageCID),
)
}
})
}
Expand Down

0 comments on commit bffd700

Please sign in to comment.