Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ Vue.use(Chat)
:alwaysScrollToBottom="alwaysScrollToBottom"
:messageStyling="messageStyling"
@onType="handleOnType"
@edit="editMessage" />
@edit="editMessage"
:authorId="'me'"
/>
</div>
</template>
```
Expand Down Expand Up @@ -198,6 +200,7 @@ For more detailed examples see the demo folder.
| showTypingIndicator | Boolean | A bool indicating whether or not to show the `typing` indicator
| colors | Object | An object containing the specs of the colors used to paint the component. [See here](#faq)
| messageStyling | Boolean | A bool indicating whether or not to enable `msgdown` support for message formatting in chat. [See here](#faq)
| authorId | String | Current user id used to compare message authors.

#### Events

Expand Down
1 change: 1 addition & 0 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@onType="handleOnType"
@edit="editMessage"
@remove="removeMessage"
:authorId="'me'"
>
<template v-slot:text-message-toolbox="scopedProps">
<button v-if="!scopedProps.me && scopedProps.message.type==='text'" @click.prevent="like(scopedProps.message.id)">
Expand Down
5 changes: 5 additions & 0 deletions src/ChatWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<MessageList
v-if="!showUserList"
:messages="messages"
:authorId="authorId"
:participants="participants"
:showTypingIndicator="showTypingIndicator"
:colors="colors"
Expand Down Expand Up @@ -131,6 +132,10 @@ export default {
disableUserListToggle: {
type: Boolean,
default: false
},
authorId: {
type: String,
required: false
}
},
data() {
Expand Down
5 changes: 5 additions & 0 deletions src/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@onType="$emit('onType')"
@edit="$emit('edit', $event)"
@remove="$emit('remove', $event)"
:authorId="authorId"
>
<template v-slot:header>
<slot name="header">
Expand Down Expand Up @@ -185,6 +186,10 @@ export default {
disableUserListToggle: {
type: Boolean,
default: false
},
authorId: {
type: String,
required: true
}
},
computed: {
Expand Down
14 changes: 10 additions & 4 deletions src/Message.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="sc-message">
<div class="sc-message--content" :class="{
sent: message.author === 'me',
received: message.author !== 'me' && message.type !== 'system',
sent: message.author === authorId,
received: message.author !== authorId && message.type !== 'system',
system: message.type === 'system'
}">
<slot
Expand All @@ -19,7 +19,9 @@
:message="message"
:messageColors="determineMessageColors()"
:messageStyling="messageStyling"
@remove="$emit('remove')">
@remove="$emit('remove')"
:authorId="authorId"
>
<template v-slot:default="scopedProps">
<slot name="text-message-body" :message="scopedProps.message" :messageText="scopedProps.messageText" :messageColors="scopedProps.messageColors" :me="scopedProps.me">
</slot>
Expand Down Expand Up @@ -78,6 +80,10 @@ export default {
user: {
type: Object,
required: true
},
authorId: {
type: String,
required: false
}
},
methods: {
Expand All @@ -94,7 +100,7 @@ export default {
}
},
determineMessageColors() {
return this.message.author === 'me' ? this.sentColorsStyle() : this.receivedColorsStyle()
return this.message.author === this.authorId ? this.sentColorsStyle() : this.receivedColorsStyle()
}
},
computed:{
Expand Down
6 changes: 5 additions & 1 deletion src/MessageList.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="sc-message-list" ref="scrollList" :style="{backgroundColor: colors.messageList.bg}" @scroll="handleScroll">
<Message v-for="(message, idx) in messages" :message="message" :user="profile(message.author)" :key="idx" :colors="colors" :messageStyling="messageStyling" @remove="$emit('remove', message)">
<Message v-for="(message, idx) in messages" :message="message" :authorId="authorId" :user="profile(message.author)" :key="idx" :colors="colors" :messageStyling="messageStyling" @remove="$emit('remove', message)">
<template v-slot:user-avatar="scopedProps">
<slot name="user-avatar" :user="scopedProps.user" :message="scopedProps.message">
</slot>
Expand Down Expand Up @@ -49,6 +49,10 @@ export default {
messageStyling: {
type: Boolean,
required: true
},
authorId: {
type: String,
required: true
}
},
methods: {
Expand Down
6 changes: 5 additions & 1 deletion src/messages/TextMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export default {
messageStyling: {
type: Boolean,
required: true
},
authorId: {
type: String,
required: true
}
},
computed: {
Expand All @@ -67,7 +71,7 @@ export default {
})
},
me(){
return this.message.author === 'me';
return this.message.author === this.authorId;
},
isEditing() {
return (store.editMessage && store.editMessage.id) == this.message.id;
Expand Down