From 0c7b940217541f8609829262911a01a653aef08f Mon Sep 17 00:00:00 2001 From: singularity43 <46550600+singularity43@users.noreply.github.com> Date: Sun, 10 Feb 2019 20:51:59 -0500 Subject: [PATCH 01/14] (Update) ChatController API Cache bot. --- app/Http/Controllers/API/ChatController.php | 27 +++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/API/ChatController.php b/app/Http/Controllers/API/ChatController.php index 6c933f1396..c7d7fc0136 100644 --- a/app/Http/Controllers/API/ChatController.php +++ b/app/Http/Controllers/API/ChatController.php @@ -153,7 +153,18 @@ public function createMessage(Request $request) return response('error', 401); } - $bots = Bot::where('active', '=', 1)->orderBy('position', 'asc')->get(); + $bot_dirty = 0; + $bots = cache()->get('bots'); + if (! $bots || ! is_array($bots) || count($bots) < 1) { + $bots = Bot::where('active', '=', 1)->orderBy('position', 'asc')->get(); + $bot_dirty = 1; + } + + if($bot_dirty == 1) { + $expiresAt = Carbon::now()->addMinutes(60); + cache()->put('bots', $bots, $expiresAt); + } + $which = null; $target = null; $runbot = null; @@ -186,14 +197,14 @@ public function createMessage(Request $request) if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '/'.$bot->command) { $which = 'echo'; } - if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '!'.$bot->command) { + else if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '!'.$bot->command) { $which = 'public'; } - if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '@'.$bot->command) { + else if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '@'.$bot->command) { $message = substr($message, 1 + strlen($bot->command), strlen($message)); $which = 'private'; } - if ($message && $receiver_id == 1 && $bot->id == $bot_id) { + else if ($message && $receiver_id == 1 && $bot->id == $bot_id) { if ($message && substr($message, 0, 1 + (strlen($bot->command))) == '/'.$bot->command) { $message = substr($message, 1 + strlen($bot->command), strlen($message)); } @@ -326,17 +337,19 @@ public function createMessage(Request $request) event(new Chatter('audible', $receiver_id, UserAudibleResource::collection($receiver_audibles))); } - $ignore = false; $room_id = 0; - if ($bot_id > 0) { + if ($bot_id > 0 && receiver_id == 1) { $ignore = true; + } else { + $ignore = null; } + $save = true; + $echo = true; $message = $this->chat->privateMessage($user_id, $room_id, $message, $receiver_id, null, $ignore); } else { $receiver_id = null; $bot_id = null; $message = $this->chat->message($user_id, $room_id, $message, $receiver_id, $bot_id); - $this->chat->ping('room', $room_id); } if (! $save) { From 66f0357c9de0aba3c01886ff3c4ab928932f015a Mon Sep 17 00:00:00 2001 From: singularity43 <46550600+singularity43@users.noreply.github.com> Date: Sun, 10 Feb 2019 20:52:25 -0500 Subject: [PATCH 02/14] (Update) ChatRepository Repository Update pm routine. --- app/Repositories/ChatRepository.php | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/app/Repositories/ChatRepository.php b/app/Repositories/ChatRepository.php index cd167f8e05..014606dbe1 100644 --- a/app/Repositories/ChatRepository.php +++ b/app/Repositories/ChatRepository.php @@ -94,7 +94,7 @@ public function echoes($user_id) ])->where(function ($query) use ($user_id) { $query->where('user_id', '=', $user_id); }) - ->latest() + ->orderBy('id','asc') ->get(); } @@ -185,19 +185,31 @@ public function botMessage($bot_id, $room_id, $message, $receiver = null) $message->delete(); } - public function privateMessage($user_id, $room_id, $message, $receiver = null, $bot = null, $ignore = false) + public function privateMessage($user_id, $room_id, $message, $receiver = null, $bot = null, $ignore = null) { if ($this->user->find($user_id)->censor) { $message = $this->censorMessage($message); } $message = $this->htmlifyMessage($message); - $save = $this->message->create([ - 'user_id' => $user_id, - 'chatroom_id' => 0, - 'message' => $message, - 'receiver_id' => $receiver, - 'bot_id' => $bot, - ]); + + if($bot != null) { + $save = $this->message->create([ + 'user_id' => $user_id, + 'chatroom_id' => 0, + 'message' => $message, + 'receiver_id' => $receiver, + 'bot_id' => $bot, + ]); + } + else { + $save = $this->message->create([ + 'user_id' => $user_id, + 'chatroom_id' => 0, + 'message' => $message, + 'receiver_id' => $receiver, + 'bot_id' => $bot, + ]); + } $message = Message::with([ 'bot', @@ -207,12 +219,14 @@ public function privateMessage($user_id, $room_id, $message, $receiver = null, $ 'receiver.chatStatus', ])->find($save->id); - if ($ignore != true) { + if ($ignore != null) { event(new Chatter('new.message', $user_id, new ChatMessageResource($message))); } event(new Chatter('new.message', $receiver, new ChatMessageResource($message))); - event(new Chatter('new.ping', $receiver, ['type' => 'target', 'id' => $user_id])); + if($receiver != 1) { + event(new Chatter('new.ping', $receiver, ['type' => 'target', 'id' => $user_id])); + } return $message; } @@ -252,8 +266,8 @@ public function botMessages($sender_id, $bot_id) 'receiver.group', 'receiver.chatStatus', ])->where(function ($query) use ($sender_id,$bot_id) { - $query->whereRaw('(user_id = ? and bot_id = ?)', [$sender_id, $bot_id])->orWhereRaw('(receiver_id = ? and bot_id = ?)', [$sender_id, $bot_id]); - }) + $query->whereRaw('(user_id = ? and receiver_id = ?)', [$sender_id, 1])->orWhereRaw('(user_id = ? and receiver_id = ?)', [1, $sender_id]); + })->where('bot_id','=',$bot_id) ->orderBy('id', 'desc') ->limit(config('chat.message_limit')) ->get(); From 00e3e3d313116b45b731f40aa387c90e0c6989ed Mon Sep 17 00:00:00 2001 From: singularity43 <46550600+singularity43@users.noreply.github.com> Date: Sun, 10 Feb 2019 20:52:49 -0500 Subject: [PATCH 03/14] (Update) Chatbox Vue Full screen, compact. --- resources/js/components/chat/Chatbox.vue | 1471 +++++++++++----------- 1 file changed, 761 insertions(+), 710 deletions(-) diff --git a/resources/js/components/chat/Chatbox.vue b/resources/js/components/chat/Chatbox.vue index 6992f8713b..d8e963222d 100644 --- a/resources/js/components/chat/Chatbox.vue +++ b/resources/js/components/chat/Chatbox.vue @@ -1,12 +1,12 @@ + created () { + this.startup = Date.now(); + this.auth = this.user; + this.activeRoom = this.auth.chatroom.name; + this.activeTarget = ''; + this.activeBot = ''; + this.fetchRooms(); + this.fetchBots(); + this.fetchStatuses(); + this.fetchAudibles(); + this.fetchEchoes(); + this.listenForChatter(); + this.attachAudible(); + this.scrollToBottom(true); + }, + } + \ No newline at end of file From 4a641a89f3888ef0495615e736a564398d6a17a9 Mon Sep 17 00:00:00 2001 From: singularity43 <46550600+singularity43@users.noreply.github.com> Date: Sun, 10 Feb 2019 20:53:06 -0500 Subject: [PATCH 04/14] (Update) ChatForm Vue Update for compact / fs. --- resources/js/components/chat/ChatForm.vue | 213 ++++++++++------------ 1 file changed, 101 insertions(+), 112 deletions(-) diff --git a/resources/js/components/chat/ChatForm.vue b/resources/js/components/chat/ChatForm.vue index 121178bbda..d03a6c345a 100644 --- a/resources/js/components/chat/ChatForm.vue +++ b/resources/js/components/chat/ChatForm.vue @@ -1,82 +1,71 @@ \ No newline at end of file From 8628911c1081d7d58eb3003fa1e14161c8b4a8e8 Mon Sep 17 00:00:00 2001 From: singularity43 <46550600+singularity43@users.noreply.github.com> Date: Sun, 10 Feb 2019 20:54:17 -0500 Subject: [PATCH 05/14] (Update) ChatMessages Vue Reduce bot size. --- resources/js/components/chat/ChatMessages.vue | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/resources/js/components/chat/ChatMessages.vue b/resources/js/components/chat/ChatMessages.vue index b60a8b2b51..12a0df373a 100644 --- a/resources/js/components/chat/ChatMessages.vue +++ b/resources/js/components/chat/ChatMessages.vue @@ -1,9 +1,8 @@