fix chat view

This commit is contained in:
amazuecos
2025-04-02 22:24:32 +02:00
parent 69f6d6cbeb
commit 9cbbddcc1c
11 changed files with 62 additions and 54 deletions

View File

@ -151,7 +151,7 @@ class Users extends \App\Controllers\GoBaseController
foreach ($chatDepartments as $chatDepartment) { foreach ($chatDepartments as $chatDepartment) {
$this->chat_department_user_model->insert([ $this->chat_department_user_model->insert([
"user_id" => $id, "user_id" => $id,
"chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()["id"] "chat_department_id" => $this->chat_department_model->where("name", $chatDepartment)->first()->id
]); ]);
} }

View File

@ -72,13 +72,15 @@ class ChatService extends BaseService
$cliente_contacto = $this->clienteContactoModel->find($data["client"]); $cliente_contacto = $this->clienteContactoModel->find($data["client"]);
if ($cliente_contacto) { if ($cliente_contacto) {
$userClienteContacto = $cliente_contacto->cliente()->user(); $userClienteContacto = $cliente_contacto->cliente()->user();
$cliente_in_department = $this->chatDepartmentUserModel if ($userClienteContacto) {
->where('chat_department_id', $chatDepartmentId) $cliente_in_department = $this->chatDepartmentUserModel
->where('user_id', $userClienteContacto->id) ->where('chat_department_id', $chatDepartmentId)
->where($this->modelFkMap[$model], $modelId) ->where('user_id', $userClienteContacto->id)
->first(); ->where($this->modelFkMap[$model], $modelId)
if ($cliente_in_department == null) { ->first();
$this->chatDepartmentUserModel->insert(['chat_department_id' => $chatDepartmentId, 'user_id' => $userClienteContacto->id, $this->modelFkMap[$model] => $modelId]); if ($cliente_in_department == null) {
$this->chatDepartmentUserModel->insert(['chat_department_id' => $chatDepartmentId, 'user_id' => $userClienteContacto->id, $this->modelFkMap[$model] => $modelId]);
}
} }
} }
} }
@ -165,7 +167,7 @@ class ChatService extends BaseService
); );
return true; return true;
} }
public function getHebras(string $model, int $modelId): array public function getHebras(string $model, int $modelId): array
{ {
$chats = $this->chatModel->where('chat_department_id', null) $chats = $this->chatModel->where('chat_department_id', null)

View File

@ -1,6 +1,6 @@
<div class="col-md-12" id="chat-factura" data-id="<?= $modelId ?>"> <div class="container-xxl flex-grow-1 container-p-y" id="chat-factura" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden"> <div class="app-chat card overflow-hidden border">
<div class="row g-0"> <div class="row g-0">
<!-- Chat & Contacts --> <!-- Chat & Contacts -->

View File

@ -13,19 +13,19 @@
<div class="nav-align-top"> <div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist"> <ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item"> <li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button> <button type="button" class="nav-link <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
</li> </li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?> <?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item"> <li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button> <button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel"> <div class="tab-pane fade <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_factura", data: ["modelId" => $modelId,"type" => "factura"]) ?> <?= view("themes/vuexy/components/chat_factura", data: ["modelId" => $modelId,"type" => "factura"]) ?>
</div> </div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?> <?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel"> <div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId,"type" => "factura"]) ?> <?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId,"type" => "factura"]) ?>
</div> </div>

View File

@ -13,19 +13,19 @@
<div class="nav-align-top"> <div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist"> <ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item"> <li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button> <button type="button" class="nav-link <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button>
</li> </li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?> <?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item"> <li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button> <button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
</li> </li>
<?php } ?> <?php } ?>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel"> <div class="tab-pane fade <?=!auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_pedido", data: ["modelId" => $modelId, "type" => "pedido"]) ?> <?= view("themes/vuexy/components/chat_pedido", data: ["modelId" => $modelId, "type" => "pedido"]) ?>
</div> </div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?> <?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel"> <div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "pedido"]) ?> <?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "pedido"]) ?>
</div> </div>

View File

@ -13,19 +13,19 @@
<div class="nav-align-top"> <div class="nav-align-top">
<ul class="nav nav-pills mb-4" role="tablist"> <ul class="nav nav-pills mb-4" role="tablist">
<li class="nav-item"> <li class="nav-item">
<button type="button" class="nav-link <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?=lang('Chat.messages_client')?></button> <button type="button" class="nav-link <?= !auth()->user()->inGroup('cliente-editor','cliente') ? "" : "active" ?>" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-chat" aria-controls="navs-pills-top-internal-chat" aria-selected="false"><?= lang('Chat.messages_client') ?></button>
</li>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?=lang('Chat.messages_internal')?></button>
</li> </li>
<?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<li class="nav-item">
<button type="button" class="nav-link active" role="tab" data-bs-toggle="tab" data-bs-target="#navs-pills-top-internal-messages" aria-controls="navs-pills-top-internal-messages" aria-selected="false"><?= lang('Chat.messages_internal') ?></button>
</li>
<?php } ?> <?php } ?>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane fade <?=auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel"> <div class="tab-pane fade <?= !auth()->user()->inGroup('cliente-editor','cliente') ? "" : "show active" ?>" id="navs-pills-top-chat" role="tabpanel">
<?= view("themes/vuexy/components/chat_presupuesto", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?> <?= view("themes/vuexy/components/chat_presupuesto", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?>
</div> </div>
<?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('beta')) { ?> <?php if (!auth()->user()->inGroup('cliente-editor','cliente')) { ?>
<div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel"> <div class="tab-pane fade show active" id="navs-pills-top-internal-messages" role="tabpanel">
<?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?> <?= view("themes/vuexy/components/internal_messages", data: ["modelId" => $modelId, "type" => "presupuesto"]) ?>
</div> </div>

View File

@ -1,6 +1,6 @@
<div class="col-md-12" id="chat-pedido" data-id="<?= $modelId ?>"> <div class="container-xxl flex-grow-1 container-p-y" id="chat-pedido" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden"> <div class="app-chat card overflow-hidden border">
<div class="row g-0"> <div class="row g-0">
<!-- Chat & Contacts --> <!-- Chat & Contacts -->

View File

@ -1,4 +1,4 @@
<div class="col-md-12" id="chat-presupuesto" data-id="<?= $modelId ?>"> <div class="container-xxl flex-grow-1 container-p-y" id="chat-presupuesto" data-id="<?= $modelId ?>">
<div class="app-chat card overflow-hidden border"> <div class="app-chat card overflow-hidden border">
<div class="row g-0"> <div class="row g-0">
@ -96,7 +96,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="chat-history-body bg-body "> <div class="chat-history-body bg-body">
<div class="d-flex justify-content-center chat-loader"> <div class="d-flex justify-content-center chat-loader">
<div class="sk-wave sk-primary "> <div class="sk-wave sk-primary ">
<div class="sk-wave-rect"></div> <div class="sk-wave-rect"></div>

View File

@ -15,14 +15,16 @@ const chatContactsBody = $('.app-chat-contacts .sidebar-body'),
if (chatContactsBody.length) { if (chatContactsBody.length) {
new PerfectScrollbar(chatContactsBody[0], { new PerfectScrollbar(chatContactsBody[0], {
wheelPropagation: false, wheelPropagation: false,
suppressScrollX: true suppressScrollX: true,
scrollingThreshold : 200,
}); });
} }
if (chatHistoryBody.length) { if (chatHistoryBody.length) {
new PerfectScrollbar(chatHistoryBody[0], { new PerfectScrollbar(document.querySelector('.chat-history-body'), {
wheelPropagation: false, wheelPropagation: false,
suppressScrollX: true suppressScrollX: true,
scrollingThreshold : 200,
}); });
} }

View File

@ -68,12 +68,16 @@ class Chat {
} }
if (this.chatHistoryBody[0]) { if (this.chatHistoryBody[0]) {
console.log("History body");
this.scrollbarChatHistory = new PerfectScrollbar(this.chatHistoryBody[0], { this.scrollbarChatHistory = new PerfectScrollbar(this.chatHistoryBody[0], {
wheelPropagation: false, wheelPropagation: false,
suppressScrollX: true, suppressScrollX: true,
}); });
} }
if (this.chatHistoryBody.length) {
this.chatHistoryBody.scrollTop(0,this.chatHistoryBody[0].scrollHeight);
}
} }
initDirectMessage() { initDirectMessage() {
@ -148,7 +152,7 @@ class Chat {
this._handleGetChatList() this._handleGetChatList()
this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this)) this.sendBtnMessageDepartment.on("click", this._sendMessage.bind(this))
this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this)) this.sendBtnMessageDepartmentClient.on("click", this._sendMessage.bind(this))
this.scrollbarChatHistory.update()
this.messageInput.on("keypress", this._sendMessagePressKey.bind(this)) this.messageInput.on("keypress", this._sendMessagePressKey.bind(this))
this.initSelectClient() this.initSelectClient()
// setInterval(this._getChatMessage.bind(this), 10000) // setInterval(this._getChatMessage.bind(this), 10000)

View File

@ -1,13 +1,13 @@
.app-chat { .app-chat {
position: relative; position: relative;
height: calc(100vh - 11.5rem) !important; height: calc(75vh - 11.5rem) !important;
} }
a.send-msg-btn { a.send-msg-btn {
color: white color: white
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat { .layout-horizontal .app-chat {
height: calc(100vh - 20rem - 2.2rem) !important; height: calc(75vh - 20rem - 2.2rem) !important;
} }
} }
@media (max-width: 992px) { @media (max-width: 992px) {
@ -28,14 +28,14 @@ a.send-msg-btn {
.app-chat .app-chat-contacts { .app-chat .app-chat-contacts {
position: absolute; position: absolute;
left: calc(-21rem - 1rem); left: calc(-21rem - 1rem);
height: calc(100vh - 11.5rem); height: calc(75vh - 11.5rem);
width: 21rem; width: 21rem;
flex-basis: 21rem; flex-basis: 21rem;
transition: all 0.25s ease; transition: all 0.25s ease;
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-contacts { .layout-horizontal .app-chat .app-chat-contacts {
height: calc(100vh - 20rem - 2.2rem); height: calc(75vh - 20rem - 2.2rem);
} }
} }
@media (min-width: 992px) { @media (min-width: 992px) {
@ -47,17 +47,17 @@ a.send-msg-btn {
left: 0rem; left: 0rem;
} }
.app-chat .app-chat-contacts .sidebar-body { .app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 3.9rem); height: calc(calc(75vh - 11.5rem) - 3.9rem);
height: calc(calc(100vh - 11.5rem) - 3.5rem); height: calc(calc(75vh - 11.5rem) - 3.5rem);
} }
@media (min-width: 992px) { @media (min-width: 992px) {
.layout-horizontal .app-chat .app-chat-contacts .sidebar-body { .layout-horizontal .app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 5rem + calc(2.2rem / 2)); height: calc(calc(75vh - 11.5rem) - 5rem + calc(2.2rem / 2));
} }
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-contacts .sidebar-body { .layout-horizontal .app-chat .app-chat-contacts .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 5rem - 2.2rem); height: calc(calc(75vh - 11.5rem) - 5rem - 2.2rem);
} }
} }
@ -90,14 +90,14 @@ a.send-msg-btn {
top: 0; top: 0;
left: calc(-21rem - 1rem); left: calc(-21rem - 1rem);
width: 21rem; width: 21rem;
height: calc(100vh - 11.5rem); height: calc(75vh - 11.5rem);
opacity: 0; opacity: 0;
z-index: 5; z-index: 5;
transition: all 0.25s ease; transition: all 0.25s ease;
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-left { .layout-horizontal .app-chat .app-chat-sidebar-left {
height: calc(100vh - 20rem - 2.2rem); height: calc(75vh - 20rem - 2.2rem);
} }
} }
.app-chat .app-chat-sidebar-left.show { .app-chat .app-chat-sidebar-left.show {
@ -105,21 +105,21 @@ a.send-msg-btn {
opacity: 1; opacity: 1;
} }
.app-chat .app-chat-sidebar-left .sidebar-body { .app-chat .app-chat-sidebar-left .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.5rem); height: calc(calc(75vh - 11.5rem) - 11.5rem);
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-left .sidebar-body { .layout-horizontal .app-chat .app-chat-sidebar-left .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 10.9rem - 2.2rem); height: calc(calc(75vh - 11.5rem) - 10.9rem - 2.2rem);
} }
} }
.app-chat .app-chat-history { .app-chat .app-chat-history {
position: relative; position: relative;
height: calc(100vh - 11.5rem); height: calc(75vh - 11.5rem);
transition: all 0.25s ease; transition: all 0.25s ease;
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-history { .layout-horizontal .app-chat .app-chat-history {
height: calc(100vh - 20rem - 2.2rem); height: calc(75vh - 20rem - 2.2rem);
} }
} }
.app-chat .app-chat-history .chat-history-header { .app-chat .app-chat-history .chat-history-header {
@ -129,13 +129,13 @@ a.send-msg-btn {
margin-bottom: 0.1rem; margin-bottom: 0.1rem;
} }
.app-chat .app-chat-history .chat-history-body { .app-chat .app-chat-history .chat-history-body {
height: calc(100vh - 20.5rem); height: calc(75vh - 20.5rem);
padding: 2rem 1.5rem; padding: 2rem 1.5rem;
overflow: hidden; overflow: hidden;
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-history .chat-history-body { .layout-horizontal .app-chat .app-chat-history .chat-history-body {
height: calc(100vh - 20.5rem - 2.2rem); height: calc(75vh - 20.5rem - 2.2rem);
} }
} }
.app-chat .app-chat-history .chat-history-body .chat-history .chat-message { .app-chat .app-chat-history .chat-history-body .chat-history .chat-message {
@ -175,14 +175,14 @@ a.send-msg-btn {
top: 0; top: 0;
right: calc(-21rem - 1rem); right: calc(-21rem - 1rem);
width: 21rem; width: 21rem;
height: calc(100vh - 11.5rem); height: calc(75vh - 11.5rem);
opacity: 0; opacity: 0;
z-index: 5; z-index: 5;
transition: all 0.25s ease; transition: all 0.25s ease;
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-right { .layout-horizontal .app-chat .app-chat-sidebar-right {
height: calc(100vh - 20rem - 2.2rem); height: calc(75vh - 20rem - 2.2rem);
} }
} }
.app-chat .app-chat-sidebar-right.show { .app-chat .app-chat-sidebar-right.show {
@ -190,11 +190,11 @@ a.send-msg-btn {
right: 0; right: 0;
} }
.app-chat .app-chat-sidebar-right .sidebar-body { .app-chat .app-chat-sidebar-right .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.75rem); height: calc(calc(75vh - 11.5rem) - 11.75rem);
} }
@media (min-width: 1200px) { @media (min-width: 1200px) {
.layout-horizontal .app-chat .app-chat-sidebar-right .sidebar-body { .layout-horizontal .app-chat .app-chat-sidebar-right .sidebar-body {
height: calc(calc(100vh - 11.5rem) - 11.1rem - 2.2rem); height: calc(calc(75vh - 11.5rem) - 11.1rem - 2.2rem);
} }
} }