Skip to content

Commit 309917c

Browse files
Added ability to specify user ID in chat json instead of 'me'.
1 parent 430b8bb commit 309917c

File tree

8 files changed

+61
-17
lines changed

8 files changed

+61
-17
lines changed

demo/src/App.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ export default {
144144
alwaysScrollToBottom: true,
145145
messageStyling: true,
146146
userIsTyping: false,
147-
placeholder: "Write something...",
147+
placeholder: 'Write something...',
148148
multipleChatsEnabled: true,
149149
currentChatID: Object.keys(chatHistory)[0],
150-
chatListTitle: "My chats",
150+
chatListTitle: 'My chats'
151151
}
152152
},
153153
created() {
@@ -171,7 +171,7 @@ export default {
171171
: ''
172172
},
173173
onMessageWasSent(message, chatID) {
174-
const msg = Object.assign({}, message, {id: Math.random(), read: (message.author === 'me')})
174+
const msg = Object.assign({}, message, {id: Math.random(), read: (message.author === this.myId)})
175175
if (chatID !== undefined) {
176176
this.chatMessageList(chatID).push(msg)
177177
} else {
@@ -241,7 +241,11 @@ export default {
241241
})
242242
},
243243
chatMessageList(chatID) {
244-
return this.chatHistory[chatID]["messages"]
244+
const chat = this.chatHistory[chatID];
245+
if (chat === undefined) {
246+
return [];
247+
}
248+
return chat["messages"];
245249
},
246250
},
247251
computed: {
@@ -254,10 +258,18 @@ export default {
254258
return this.chosenColor === 'dark' ? this.colors.messageList.bg : '#fff'
255259
},
256260
messageList() {
257-
return this.chatHistory[this.currentChatID]["messages"]
261+
const chat = this.chatHistory[this.currentChatID];
262+
if (chat === undefined) {
263+
return [];
264+
}
265+
return chat["messages"];
258266
},
259267
participants() {
260-
return this.chatHistory[this.currentChatID]["participants"]
268+
const chat = this.chatHistory[this.currentChatID];
269+
if (chat === undefined) {
270+
return [];
271+
}
272+
return chat["participants"];
261273
},
262274
chatList() {
263275
var chats = []

src/ChatWindow.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
:show-edition="showEdition"
3535
:show-deletion="showDeletion"
3636
:message-styling="messageStyling"
37+
:myId="myId"
3738
@scrollToTop="$emit('scrollToTop')"
3839
@remove="$emit('remove', $event)"
3940
@messageListMountedUpdated="$emit('messageListMountedUpdated')"
@@ -67,6 +68,7 @@
6768
:show-file="showFile"
6869
:placeholder="placeholder"
6970
:colors="colors"
71+
:myId="myId"
7072
@onType="$emit('onType')"
7173
@edit="$emit('edit', $event)"
7274
/>
@@ -182,6 +184,10 @@ export default {
182184
showDeletion: {
183185
type: Boolean,
184186
required: true
187+
},
188+
myId: {
189+
type: String,
190+
required: true
185191
}
186192
},
187193
data() {

src/Header.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default {
9898
flex: 1;
9999
user-select: none;
100100
font-size: 20px;
101+
text-align: left;
101102
}
102103
103104
.sc-header--title.enabled {

src/Launcher.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
:multiple-chats-enabled="multipleChatsEnabled"
3838
:chat-list="chatList"
3939
:chat-list-title="chatListTitle"
40+
:myId="myId"
4041
@scrollToTop="$emit('scrollToTop')"
4142
@onType="$emit('onType')"
4243
@edit="$emit('edit', $event)"
@@ -238,6 +239,10 @@ export default {
238239
chatListTitle: {
239240
type: String,
240241
default: () => ''
242+
},
243+
myId: {
244+
type: String,
245+
default: 'me'
241246
}
242247
},
243248
computed: {

src/Message.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<div
44
class="sc-message--content"
55
:class="{
6-
sent: message.author === 'me',
7-
received: message.author !== 'me' && message.type !== 'system',
6+
sent: message.author === this.myId,
7+
received: message.author !== this.myId && message.type !== 'system',
88
system: message.type === 'system'
99
}"
1010
>
1111
<slot name="user-avatar" :message="message" :user="user">
1212
<div
13-
v-if="message.type !== 'system' && authorName && authorName !== 'me'"
13+
v-if="message.type !== 'system' && authorName && authorName !== this.myId"
1414
v-tooltip="authorName"
1515
:title="authorName"
1616
class="sc-message--avatar"
@@ -27,6 +27,7 @@
2727
:message-styling="messageStyling"
2828
:show-edition="showEdition"
2929
:show-deletion="showDeletion"
30+
:myId="myId"
3031
@remove="$emit('remove')"
3132
>
3233
<template v-slot:default="scopedProps">
@@ -103,6 +104,10 @@ export default {
103104
showDeletion: {
104105
type: Boolean,
105106
required: true
107+
},
108+
myId: {
109+
type: String,
110+
required: true
106111
}
107112
},
108113
computed: {
@@ -113,7 +118,7 @@ export default {
113118
return (this.user && this.user.imageUrl) || chatIcon
114119
},
115120
messageColors() {
116-
return this.message.author === 'me' ? this.sentColorsStyle : this.receivedColorsStyle
121+
return this.message.author === this.myId ? this.sentColorsStyle : this.receivedColorsStyle
117122
},
118123
receivedColorsStyle() {
119124
return {

src/MessageList.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
:message-styling="messageStyling"
1515
:show-edition="showEdition"
1616
:show-deletion="showDeletion"
17+
:myId="myId"
1718
@remove="$emit('remove', message)"
1819
>
1920
<template v-slot:user-avatar="scopedProps">
@@ -45,6 +46,7 @@
4546
:message-styling="messageStyling"
4647
:show-edition="showEdition"
4748
:show-deletion="showDeletion"
49+
:myId="myId"
4850
/>
4951
</div>
5052
</template>
@@ -89,6 +91,10 @@ export default {
8991
showDeletion: {
9092
type: Boolean,
9193
required: true
94+
},
95+
myId: {
96+
type: String,
97+
required: true
9298
}
9399
},
94100
computed: {

src/UserInput.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export default {
139139
colors: {
140140
type: Object,
141141
required: true
142+
},
143+
myId: {
144+
type: String,
145+
required: true
142146
}
143147
},
144148
data() {
@@ -203,7 +207,7 @@ export default {
203207
})
204208
},
205209
_submitSuggestion(suggestion) {
206-
this.onSubmit({author: 'me', type: 'text', data: {text: suggestion}})
210+
this.onSubmit({author: this.myId, type: 'text', data: {text: suggestion}})
207211
},
208212
_checkSubmitSuccess(success) {
209213
if (Promise !== undefined) {
@@ -229,7 +233,7 @@ export default {
229233
if (text && text.length > 0) {
230234
this._checkSubmitSuccess(
231235
this.onSubmit({
232-
author: 'me',
236+
author: this.myId,
233237
type: 'text',
234238
data: {text}
235239
})
@@ -241,15 +245,15 @@ export default {
241245
if (text && text.length > 0) {
242246
this._checkSubmitSuccess(
243247
this.onSubmit({
244-
author: 'me',
248+
author: this.myId,
245249
type: 'file',
246250
data: {text, file}
247251
})
248252
)
249253
} else {
250254
this._checkSubmitSuccess(
251255
this.onSubmit({
252-
author: 'me',
256+
author: this.myId,
253257
type: 'file',
254258
data: {file}
255259
})
@@ -260,7 +264,7 @@ export default {
260264
const text = this.$refs.userInput.textContent
261265
if (text && text.length) {
262266
this.$emit('edit', {
263-
author: 'me',
267+
author: this.myId,
264268
type: 'text',
265269
id: store.editMessage.id,
266270
data: {text}
@@ -271,7 +275,7 @@ export default {
271275
_handleEmojiPicked(emoji) {
272276
this._checkSubmitSuccess(
273277
this.onSubmit({
274-
author: 'me',
278+
author: this.myId,
275279
type: 'emoji',
276280
data: {emoji}
277281
})
@@ -320,6 +324,7 @@ export default {
320324
bottom: 0;
321325
overflow-x: hidden;
322326
overflow-y: auto;
327+
text-align: left;
323328
}
324329
325330
.sc-user-input--text:empty:before {

src/messages/TextMessage.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export default {
7272
showDeletion: {
7373
type: Boolean,
7474
required: true
75+
},
76+
myId: {
77+
type: String,
78+
required: true
7579
}
7680
},
7781
data() {
@@ -89,7 +93,7 @@ export default {
8993
})
9094
},
9195
me() {
92-
return this.message.author === 'me'
96+
return this.message.author === this.myId
9397
},
9498
isEditing() {
9599
return (store.editMessage && store.editMessage.id) == this.message.id

0 commit comments

Comments
 (0)