From cee635ff1db9ba7c9212547831287efe56c69a1f Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Wed, 15 Dec 2021 22:43:23 +0100 Subject: add working groups sender --- src/components/group/GroupSender.vue | 22 ++++++++++++++++++++-- src/components/group/Message.vue | 10 +++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/components') diff --git a/src/components/group/GroupSender.vue b/src/components/group/GroupSender.vue index 160ca76..ba36949 100644 --- a/src/components/group/GroupSender.vue +++ b/src/components/group/GroupSender.vue @@ -19,12 +19,13 @@ export default { data() { return { message: "", - messages: [] + messages: [], } }, props: { - group: Object + group: Object, + socket: Object }, methods: { @@ -35,6 +36,7 @@ export default { send_message(e) { e.preventDefault() console.log(this.message) + this.socket.emit("send_group_message", {message: this.message, group: this.group}) this.message = "" }, @@ -45,6 +47,11 @@ export default { if(status===200) this.messages = data.messages + }, + + push_message(message) { + if(message.receiver == this.group.id) + this.messages.push(message) } }, @@ -56,6 +63,10 @@ export default { this.$nextTick(function () { this.$refs.input.focus() + this.socket.emit("join_group", {group_id: this.group.id}) + this.socket.on("receive_group_message", ({message}) => { + this.push_message(message) + }) this.get_messages() }) } @@ -63,5 +74,12 @@ export default { diff --git a/src/components/group/Message.vue b/src/components/group/Message.vue index 56e2805..eedcc6e 100644 --- a/src/components/group/Message.vue +++ b/src/components/group/Message.vue @@ -1,5 +1,5 @@