-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathChatForm.vue
60 lines (55 loc) · 1.81 KB
/
ChatForm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<div>
<div class="input-group" v-if="isParticipant()">
<input
id="btn-input"
type="text"
name="message"
class="form-control input-sm"
placeholder="Type your message here..."
v-model="newMessage"
@keyup.enter="sendMessage"
>
<span class="input-group-btn">
<button class="btn btn-primary btn-sm" id="btn-chat" @click="sendMessage">Send</button>
</span>
</div>
<div v-else>
<button class="btn btn-success btn-sm" @click="joinConversation()">Join Conversation</button>
</div>
</div>
</template>
<script>
export default {
props: ["user", "conversation"],
data() {
return {
newMessage: ""
};
},
methods: {
isParticipant() {
return window.conversations.indexOf(this.conversation) !== -1;
},
joinConversation() {
axios.post(`/chat/conversations/${this.conversation}/participants`).then(response => {
location.reload();
});
},
sendMessage() {
axios.post(`/chat/conversations/${this.conversation}/messages`, {
message: {
body: this.newMessage,
},
participant_id: window.participant.id,
participant_type: window.participant.type,
})
.then(() => {
this.newMessage = "";
location.reload(); // comment this out if you are broadcasting
});
}
}
};
</script>