Permalink
Browse files

fix: message sending error, added some logic of typing indicator

  • Loading branch information...
akazorg committed Nov 14, 2018
1 parent b5d8aa9 commit 07f9323863ec7f418efe814aeed2a42fad3751ea
@@ -27,6 +27,7 @@
"search_messages": "Search messages",
"msg_sent": "Sent",
"msg_seen_at": "Seen at",
"is_typing": "Is typing...",
"type_message": "Type message...",
"new_message": "New message",
"to_message": "To",

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -91,31 +91,31 @@
<title>animation dots</title>
<circle cx="15" cy="15" r="15">
<animate attributeName="r" from="15" to="15"
begin="0s" dur="1.5s"
begin="0s" dur="1.2s"
values="15;9;15" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="fill-opacity" from="1" to="1"
begin="0s" dur="1.5s"
begin="0s" dur="1.2s"
values="1;.5;1" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="60" cy="15" r="15">
<animate attributeName="r" from="15" to="15"
begin="0.5s" dur="1.5s"
begin="0.4s" dur="1.2s"
values="15;9;15" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="fill-opacity" from="1" to="1"
begin="0.5s" dur="1.5s"
begin="0.4s" dur="1.2s"
values="1;.5;1" calcMode="linear"
repeatCount="indefinite" />
</circle>
<circle cx="105" cy="15" r="15">
<animate attributeName="r" from="15" to="15"
begin="1s" dur="1.5s"
begin="0.8s" dur="1.2s"
values="15;9;15" calcMode="linear"
repeatCount="indefinite" />
<animate attributeName="fill-opacity" from="1" to="1"
begin="1s" dur="1.5s"
begin="0.8s" dur="1.2s"
values="1;.5;1" calcMode="linear"
repeatCount="indefinite" />
</circle>
@@ -50,8 +50,8 @@ module.exports = {
*/
listen() {
Echo.private('mercurius.'+this.user.slug)
.listen('.mercurius.message.sent', e => this.onMessageReceived(e))
.listen('.mercurius.user.status.changed', user => this.onUserStatusChanged(user));
.listen('.mercurius.message.sent', this.onMessageReceived)
.listen('.mercurius.user.status.changed', this.onUserStatusChanged);
},


@@ -10,6 +10,28 @@
@handle-scroll="onScroll"
>
<div class="messages">

<!-- Typing indicator -->
<div class="mt-2" v-if="isTyping">
<div class="message_row msg_received">
<div class="message">
<img
class="message__avatar"
:alt="conversation.user"
:src="conversation.avatar"
/>
<div
class="message__body"
v-b-tooltip.show.right
:title="'is_typing' | __"
>
<svg class="ic"><use xlink:href="#icon-ani-dots"></use></svg>
</div>
</div>
</div>
</div>


<template v-for="(msg, idx) in messages">
<div
class="message_row"
@@ -89,6 +111,7 @@ export default {
data() {
return {
isTyping: false,
ops: {
scrollPanel: {
initialScrollY: 100,
@@ -1,6 +1,3 @@
/**
* Handles event listener for WebSockets using Pusher.
*/
module.exports = {
methods: {
/**
@@ -33,9 +33,8 @@ public function send(Request $request, MessageRepository $msg, UserRepository $u
'recipient' => 'required|string',
'message' => 'required|string',
]);
$slug = config('mercurius.fields.slug');
$from = $request->user()->{$slug};
$receiver = $user->find($request->recipient)->{$slug};
$from = $request->user();
$receiver = $user->find($request->recipient);
$message = $request->message;
return response($msg->send($from, $receiver, $message));
@@ -12,24 +12,29 @@ class MessageRepository
*
* Message is broadcast to WebSocket using Pusher.
*
* @param int $senderId
* @param int $receiverId
* @param string $message
* @param App\User $sender
* @param App\User $receiver
* @param string $message
*
* @return \Illuminate\Support\Collection
*/
public function send(int $senderId, int $receiverId, string $message)
public function send($sender, $receiver, string $message)
{
try {
$msg = Mercurius::model('message');
$slug = config('mercurius.fields.slug');
$msg->sender_id = $senderId;
$msg->receiver_id = $receiverId;
$msg->sender_id = $sender->id;
$msg->receiver_id = $receiver->id;
$msg->message = $message;
$msg->save();
broadcast(new MessageSent($msg->receiver, $msg->sender, $msg))->toOthers();
broadcast(new MessageSent(
$msg->receiver->{$slug},
$msg->sender,
$msg
))->toOthers();
$out = [
'id' => $msg->id,

0 comments on commit 07f9323

Please sign in to comment.