mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix : mensajes internos, arreglar total numero mensajes
This commit is contained in:
@ -178,20 +178,21 @@ class ChatController extends BaseController
|
||||
"receiver_id" => $data["receiver_id"],
|
||||
]
|
||||
);
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id,"user_id" => auth()->user()->id]);
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id,"user_id" =>$data["receiver_id"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function get_chat_internal_contacts()
|
||||
{
|
||||
if (auth()->user()->cliente_id) {
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
$users = $this->userModel->builder()
|
||||
->where("cliente_id", null)
|
||||
->whereNotIn("id", [auth()->user()->id])
|
||||
$auth_user = auth()->user();
|
||||
if ($auth_user->cliente_id) {
|
||||
$users = $this->chatModel->getOpenChatCliente($auth_user->id);
|
||||
}else{
|
||||
$users = $this->userModel->builder()
|
||||
->whereNotIn("id", [$auth_user->id])
|
||||
->where("deleted_at", null)
|
||||
->get()->getResultObject();
|
||||
}
|
||||
foreach ($users as $user) {
|
||||
$user->unreadMessages = $this->chatMessageModel->get_chat_messages_count($user->id);
|
||||
}
|
||||
@ -200,11 +201,11 @@ class ChatController extends BaseController
|
||||
}
|
||||
public function get_chat_internal_contact(int $user_id)
|
||||
{
|
||||
if (auth()->user()->cliente_id) {
|
||||
return $this->response->setJSON([]);
|
||||
}
|
||||
$auth_user = auth()->user();
|
||||
// if ($auth_user->cliente_id) {
|
||||
// return $this->response->setJSON([]);
|
||||
// }
|
||||
$users = $this->userModel->builder()
|
||||
->where("cliente_id", null)
|
||||
->where("deleted_at", null)
|
||||
->where("id", $user_id)
|
||||
->get()->getFirstRow();
|
||||
@ -224,6 +225,8 @@ class ChatController extends BaseController
|
||||
$data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
|
||||
$response["totalMessages"] = 0;
|
||||
$response["chatFacturas"] = $this->chatModel->getClienteChatFacturas($data["facturas"]);
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
|
||||
foreach ($response["chatFacturas"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
@ -231,6 +234,10 @@ class ChatController extends BaseController
|
||||
foreach ($response["chatPresupuestos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
foreach ($mensajes_directos as $value) {
|
||||
$response["internals"][] = $value;
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
$response["chatPedidos"] = $this->chatModel->getClienteChatPedidos($data["pedidos"]);
|
||||
foreach ($response["chatPedidos"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
|
||||
@ -55,7 +55,7 @@ class ChatDeparmentModel extends Model
|
||||
$userModel = model(UserModel::class);
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
|
||||
$query = $this->db->table('chat_departments')
|
||||
$query = $this->builder()
|
||||
->select(
|
||||
[
|
||||
|
||||
@ -82,6 +82,7 @@ class ChatDeparmentModel extends Model
|
||||
"left"
|
||||
)
|
||||
->where("chat_departments.type", $type);
|
||||
|
||||
// if (auth()->user()->cliente_id == null) {
|
||||
// $query->where("chat_department_users.user_id", auth()->user()->id);
|
||||
// }
|
||||
@ -89,16 +90,22 @@ class ChatDeparmentModel extends Model
|
||||
$results = $query->get()->getResultArray();
|
||||
// Create the desired structure
|
||||
$departments = [];
|
||||
|
||||
foreach ($results as $row) {
|
||||
$departmentName = $row['name'];
|
||||
$totalMessages = 0;
|
||||
|
||||
// If the department is not yet added to the array, initialize it
|
||||
if (!isset($departments[$departmentName])) {
|
||||
if($row['chatId']){
|
||||
$data["messages"] = $chatMessageModel->get_chat_messages($row['chatId']);
|
||||
$totalMessages = count($data["messages"]);
|
||||
|
||||
}
|
||||
$departments[$departmentName] = [
|
||||
'id' => $row['id'],
|
||||
'name' => $row['name'],
|
||||
'display' => $row['display'],
|
||||
'totalMessages' => $totalMessages,
|
||||
'users' => [] // Initialize users as an empty array
|
||||
];
|
||||
}
|
||||
|
||||
@ -115,6 +115,13 @@ class ChatMessageModel extends Model
|
||||
->where("receiver_id", auth()->user()->id)->countAllResults();
|
||||
return $messagesFromReceiver;
|
||||
}
|
||||
public function get_chat_department_messages_count(int $chat_id) : int
|
||||
{
|
||||
$chatDepartmentMessagesCount = $this->builder()
|
||||
->where("id",$chat_id)
|
||||
->countAllResults();
|
||||
return $chatDepartmentMessagesCount;
|
||||
}
|
||||
public function get_chat_messages_count(int $sender_id): int
|
||||
{
|
||||
$messagesFromReceiver = $this->builder()
|
||||
|
||||
@ -599,6 +599,17 @@ class ChatModel extends Model
|
||||
$userModel = model(UserModel::class);
|
||||
return $userModel->find($first_message->sender_id);
|
||||
}
|
||||
public function getOpenChatCliente(int $user_id) : array
|
||||
{
|
||||
$q = $this->builder()->distinct()->select([
|
||||
"users.*"
|
||||
])
|
||||
->join("chat_messages","chat_messages.chat_id = chats.id","left")
|
||||
->join("users","users.id = chat_messages.sender_id","left")
|
||||
->where("chat_messages.receiver_id",$user_id);
|
||||
|
||||
return $q->get()->getResultObject();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
<hr class="container-m-nx m-0" />
|
||||
<div class="sidebar-body">
|
||||
|
||||
<!-- Contacts -->
|
||||
<!-- CLIENTES -->
|
||||
<ul class="list-unstyled chat-contact-list mb-0" id="contact-list">
|
||||
<li class="chat-contact-list-item chat-contact-list-item-title">
|
||||
<h5 class="text-primary mb-0">Contactos</h5>
|
||||
@ -54,6 +54,7 @@
|
||||
</li> -->
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- /Chat contacts -->
|
||||
@ -83,13 +84,13 @@
|
||||
aria-expanded="false">
|
||||
<i class="ti ti-dots-vertical"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end"
|
||||
<!-- <div class="dropdown-menu dropdown-menu-end"
|
||||
aria-labelledby="chat-header-actions">
|
||||
<a class="dropdown-item" href="javascript:void(0);">Silenciar
|
||||
Conversacion</a>
|
||||
<a class="dropdown-item" href="javascript:void(0);">Limpiar
|
||||
Conversacion</a>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MENU CLIENTES
|
||||
*/
|
||||
if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente-editor')) {
|
||||
|
||||
if (auth()->user()->can('perfil.edit') || auth()->user()->can('direcciones.menu')) {
|
||||
?>
|
||||
?>
|
||||
<!-- Clientes -->
|
||||
<li class="menu-item">
|
||||
<a href="javascript:void(0);" class="menu-link menu-toggle">
|
||||
@ -27,14 +28,17 @@ if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
if (auth()->user()->can('clientes.menu') ||
|
||||
auth()->user()->can('plantilla-tarifa.menu')) {
|
||||
?>
|
||||
if (
|
||||
auth()->user()->can('clientes.menu') ||
|
||||
auth()->user()->can('plantilla-tarifa.menu')
|
||||
) {
|
||||
?>
|
||||
<!-- Clientes -->
|
||||
<li class="menu-item">
|
||||
<a href="javascript:void(0);" class="menu-link menu-toggle">
|
||||
@ -56,12 +60,10 @@ if (auth()->user()->inGroup('cliente-admin') || auth()->user()->inGroup('cliente
|
||||
</a>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
* MENU MENSAJES
|
||||
*/
|
||||
if (auth()->user()->inGroup('beta')) {
|
||||
if (auth()->user()->inGroup('beta') || auth()->user()->inGroup('cliente-editor')) {
|
||||
?>
|
||||
<!-- Messages -->
|
||||
<li class="menu-item">
|
||||
|
||||
@ -215,7 +215,7 @@ class Chat {
|
||||
${row.display}
|
||||
</p>
|
||||
</div>
|
||||
<span class="badge badge-center rounded-pill bg-danger messages-unread-contact">0</span>
|
||||
<span class="badge badge-center rounded-pill bg-danger messages-unread-contact">${row.totalMessages}</span>
|
||||
</a>
|
||||
</li>
|
||||
`
|
||||
@ -344,7 +344,6 @@ class Chat {
|
||||
try {
|
||||
|
||||
if (contacts.length) {
|
||||
console.log(contacts)
|
||||
|
||||
contacts.map((c, index) => {
|
||||
this._addContactToList(c)
|
||||
@ -469,7 +468,7 @@ class Chat {
|
||||
<h6 class="chat-contact-name text-truncate m-0">${contact?.first_name ?? "" + " " +
|
||||
contact?.last_name ?? ""}</h6>
|
||||
<p class="chat-contact-status text-muted text-truncate mb-0">
|
||||
${contact.username}
|
||||
${contact?.cliente_id ? "[CLIENTE]" : ""}${contact.username}
|
||||
</p>
|
||||
</div>
|
||||
${contact.unreadMessages ? `<span
|
||||
|
||||
Reference in New Issue
Block a user