-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathChatMessages.vue
63 lines (56 loc) · 1.6 KB
/
ChatMessages.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
61
62
63
<template>
<div>
<button class="btn btn-danger btn-sm float-right" @click="deleteMessages()">Delete Messages</button>
<br>
<br>
<ul class="chat">
<li class="left clearfix" v-for="(message, index) in messages.data" :key="index">
<div class="chat-body clearfix">
<div class="header">
<strong class="primary-font">{{ message.sender.name }}</strong>
</div>
<p>{{ message.body }}</p>
</div>
</li>
</ul>
</div>
</template>
<script>
export default {
props: ["conversation"],
data: () => ({
messages: []
}),
methods: {
fetchMessages() {
axios
.get(`/chat/conversations/${this.conversation}/messages?participant_id=${window.participant.id}&participant_type=${window.participant.type}`)
.then(response => {
this.messages = response.data;
});
},
deleteMessages() {
axios
.delete(`/chat/conversations/${this.conversation}/messages?participant_id=${window.participant.id}&participant_type=${window.participant.type}`)
.then(response => {
this.messages = response.data;
});
},
enablePusher() {
let pusher = new Pusher(process.env.MIX_PUSHER_APP_KEY, {
cluster: process.env.MIX_PUSHER_APP_CLUSTER
});
let channel = pusher.subscribe(
`mc-chat-conversation.${this.conversation}`
);
channel.bind("Musonza\\Chat\\Eventing\\MessageWasSent", data => {
this.messages.data.push(data.message);
});
}
},
created() {
this.fetchMessages();
//this.enablePusher();
}
};
</script>