diff --git a/plugins/tps/birzha/components/Messages.php b/plugins/tps/birzha/components/Messages.php index 17578a7dc..8011119ef 100644 --- a/plugins/tps/birzha/components/Messages.php +++ b/plugins/tps/birzha/components/Messages.php @@ -122,4 +122,26 @@ class Messages extends ComponentBase 'latest_message_area' => $this->renderPartial('@latest_message') ]; } + + public function onDeleteChat() + { + $chatRoomId = Input::get('chatroom_id'); + + $chatroom = Chatroom::with(['messages', 'users'])->find($chatRoomId); + if($chatroom) { + \DB::beginTransaction(); + + try { + $chatroom->messages()->delete(); + $chatroom->users()->detach(); + $chatroom->delete(); + } catch (\Throwable $th) { + return \Redirect::to('/error'); + } + + \DB::commit(); + } + + return \Redirect::back(); + } } diff --git a/plugins/tps/birzha/components/messages/default.htm b/plugins/tps/birzha/components/messages/default.htm index 5c46e01e8..710d2b1c7 100644 --- a/plugins/tps/birzha/components/messages/default.htm +++ b/plugins/tps/birzha/components/messages/default.htm @@ -54,6 +54,9 @@ {{chatroom.count_unread_messages}} {% endif %} + {% endfor %} @@ -79,6 +82,27 @@ + +