mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
message refactor
This commit is contained in:
@ -14,6 +14,7 @@ use App\Models\Facturas\FacturaModel;
|
||||
use App\Models\Pedidos\PedidoModel;
|
||||
use App\Models\Presupuestos\PresupuestoModel;
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use App\Services\ChatService;
|
||||
use App\Services\MessageService;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
@ -34,7 +35,7 @@ class ChatController extends BaseController
|
||||
protected ChatUser $chatUserModel;
|
||||
protected ChatNotification $chatNotificationModel;
|
||||
protected Validation $validation;
|
||||
|
||||
protected ChatService $chatService;
|
||||
protected array $viewData;
|
||||
protected static $viewPath = 'themes/vuexy/form/mensajes/';
|
||||
|
||||
@ -56,12 +57,15 @@ class ChatController extends BaseController
|
||||
$this->chatUserModel = model(ChatUser::class);
|
||||
$this->chatNotificationModel = model(ChatNotification::class);
|
||||
$this->validation = service("validation");
|
||||
$this->chatService = service("chat");
|
||||
|
||||
}
|
||||
public function index() {}
|
||||
public function get_chat_departments()
|
||||
public function get_chat_departments(string $model,int $modelId)
|
||||
{
|
||||
|
||||
$data = $this->chatDeparmentModel->getChatDepartments();
|
||||
$data = $this->chatService->getChatDepartments($model,$modelId);
|
||||
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_select()
|
||||
@ -73,6 +77,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -82,6 +87,7 @@ class ChatController extends BaseController
|
||||
$data["messages"] = $this->chatMessageModel->get_chat_messages($chat->id);
|
||||
$this->chatMessageModel->set_chat_department_messages_as_read($chat->id);
|
||||
$this->chatModel->setAsViewedChatUserNotifications($chat->id, auth()->user()->id);
|
||||
|
||||
$data["count"] = count($data["messages"]);
|
||||
}
|
||||
$data["chat"] = $chat;
|
||||
@ -91,6 +97,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -110,6 +117,7 @@ class ChatController extends BaseController
|
||||
{
|
||||
|
||||
$data = [
|
||||
"department" => $this->chatDeparmentModel->find($chat_department_id),
|
||||
"chat" => null,
|
||||
"messages" => null,
|
||||
"count" => 0,
|
||||
@ -200,115 +208,15 @@ class ChatController extends BaseController
|
||||
$data = $this->chatModel->getChat($chat_id);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function store_chat_message_presupuesto()
|
||||
public function store_message($model)
|
||||
{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
// $data = $this->chatModel->createChatPresupuesto();
|
||||
$existChat = $this->chatModel->existChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatPresupuesto($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
if (auth()->user()->inGroup('admin')) {
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('presupuesto_id', $data['model_id'])->countAllResults();
|
||||
if ($cliente_in_department_count == 0) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'presupuesto_id' => $data['model_id']]);
|
||||
}
|
||||
}
|
||||
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($data["chat_department_id"], $data["model_id"]);
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
|
||||
$chatMessageEntity = $this->chatService->storeChatMessage($data["chat_department_id"],$model,$data["model_id"],$data);
|
||||
return $this->response->setJSON($chatMessageEntity);
|
||||
|
||||
if ($auth_user_in_department_count) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'presupuesto_id' => $data['model_id']]);
|
||||
}
|
||||
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
foreach ($chatExternalUsers as $user) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_pedido()
|
||||
{
|
||||
|
||||
$data = $this->request->getPost();
|
||||
$existChat = $this->chatModel->existChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
if (auth()->user()->inGroup('admin')) {
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('pedido_id', $data['model_id'])->countAllResults();
|
||||
if ($cliente_in_department_count == 0) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'pedido_id' => $data['model_id']]);
|
||||
}
|
||||
}
|
||||
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"], $data["model_id"]);
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
|
||||
if ($auth_user_in_department_count == 0) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'pedido_id' => $data['model_id']]);
|
||||
}
|
||||
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
foreach ($chatExternalUsers as $user) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_factura()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
$existChat = $this->chatModel->existChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
if ($existChat == false) {
|
||||
$chatId = $this->chatModel->createChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
} else {
|
||||
$chat = $this->chatModel->getChatPedido($data["chat_department_id"], $data["model_id"]);
|
||||
$chatId = $chat->id;
|
||||
}
|
||||
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $data["message"]]);
|
||||
$dataResponse = $this->chatMessageModel->find($chat_message_id);
|
||||
$chatDepartmentUsers = $this->chatDeparmentModel->getChatDepartmentUsers($data["chat_department_id"]);
|
||||
if (auth()->user()->inGroup('admin')) {
|
||||
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', $data['client'])->where('pedido_id', $data['model_id'])->countAllResults();
|
||||
if ($cliente_in_department_count == 0) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => $data['client'], 'factura_id' => $data['model_id']]);
|
||||
}
|
||||
}
|
||||
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"], $data["model_id"]);
|
||||
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id', $data["chat_department_id"])->where('user_id', auth()->user()->id)->countAllResults();
|
||||
if ($auth_user_in_department_count == 0) {
|
||||
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"], 'user_id' => auth()->user()->id, 'pedido_id' => $data['model_id']]);
|
||||
}
|
||||
|
||||
foreach ($chatDepartmentUsers as $user) {
|
||||
if ($user->id != auth()->user()->id) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
}
|
||||
foreach ($chatExternalUsers as $user) {
|
||||
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
|
||||
}
|
||||
return $this->response->setJSON($dataResponse);
|
||||
}
|
||||
public function store_chat_message_single()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
@ -369,68 +277,24 @@ class ChatController extends BaseController
|
||||
public function get_chat_cliente()
|
||||
{
|
||||
$cliente_id = auth()->user()->cliente_id;
|
||||
$response = [];
|
||||
if ($cliente_id) {
|
||||
// $data = $this->clienteModel->getClienteDataPresupuestoPedidoFactura($cliente_id);
|
||||
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
|
||||
$response["totalMessages"] = 0;
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
// $response["chatFacturas"] = $this->chatModel->getClienteChatFacturas($data["facturas"]);
|
||||
// foreach ($response["chatFacturas"] as $key => $value) {
|
||||
// $response["totalMessages"] += $value->unreadMessages;
|
||||
// }
|
||||
// $response["chatPresupuestos"] = $this->chatModel->getClienteChatPresupuestos($data["presupuestos"]);
|
||||
// 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;
|
||||
// }
|
||||
// $response["data"] = $data;
|
||||
$response["totalMessages"] = 0;
|
||||
foreach ($response["internals"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
} else {
|
||||
$response["internals"] = $this->chatModel->getChatDepartmentNotifications();
|
||||
$internal_notifications = $this->chatModel->getChatInternalNotifications();
|
||||
$mensajes_directos = $this->chatModel->getChatDirectMessageNotifications();
|
||||
foreach ($internal_notifications as $value) {
|
||||
$response["internals"][] = $value;
|
||||
}
|
||||
foreach ($mensajes_directos as $value) {
|
||||
$response["internals"][] = $value;
|
||||
}
|
||||
$response["totalMessages"] = 0;
|
||||
foreach ($response["internals"] as $key => $value) {
|
||||
$response["totalMessages"] += $value->unreadMessages;
|
||||
}
|
||||
}
|
||||
$response = $this->chatService->getAuthUserNotifications();
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
public function get_chat_department_presupuesto_users(int $chat_department_id, int $presupuesto_id)
|
||||
{
|
||||
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
|
||||
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($chat_department_id, $presupuesto_id);
|
||||
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($presupuesto_id, 'presupuesto');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_pedido_users(int $chat_department_id, $pedido_id)
|
||||
{
|
||||
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
|
||||
$externalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($chat_department_id, $pedido_id);
|
||||
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($pedido_id, 'pedido');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_department_factura_users(int $chat_department_id, $factura_id)
|
||||
{
|
||||
$adminUsers = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
|
||||
$externalUsers = $this->chatDeparmentModel->getChatDeparmentFacturaUsers($chat_department_id, $factura_id);
|
||||
return $this->response->setJSON(['admin_users' => $adminUsers, 'external_users' => $externalUsers]);
|
||||
$data = $this->chatDeparmentModel->find($chat_department_id)->withUsers($factura_id, 'factura');
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_chat_users_internal()
|
||||
{
|
||||
@ -536,80 +400,14 @@ class ChatController extends BaseController
|
||||
|
||||
return $this->response->setJSON($query->get()->getResultObject());
|
||||
}
|
||||
public function store_hebra_presupuesto()
|
||||
public function store_hebra(string $model)
|
||||
{
|
||||
$auth_user = auth()->user();
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"presupuesto_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => $auth_user->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$bodyData["users"][] = $auth_user->id;
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
$status = $this->chatService->storeHebra($model,$bodyData['modelId'],$bodyData);
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => $status]);
|
||||
}
|
||||
|
||||
public function store_hebra_pedido()
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"pedido_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => auth()->user()->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
}
|
||||
|
||||
public function store_hebra_factura()
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
$chat_id = $this->chatModel->insert([
|
||||
"factura_id" => $bodyData["modelId"],
|
||||
"title" => $bodyData["title"]
|
||||
]);
|
||||
$chatMessageId = $this->chatMessageModel->insert([
|
||||
"chat_id" => $chat_id,
|
||||
"message" => $bodyData["message"],
|
||||
"sender_id" => auth()->user()->id
|
||||
]);
|
||||
if (isset($bodyData["users"])) {
|
||||
$chatUserData = array_map(fn($x) => ["user_id" => $x, "chat_id" => $chat_id], $bodyData["users"]);
|
||||
$this->chatUserModel->insertBatch($chatUserData);
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $userId]
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra creada correctamente", "status" => true]);
|
||||
}
|
||||
public function update_hebra($chat_id)
|
||||
{
|
||||
$bodyData = $this->request->getPost();
|
||||
@ -620,11 +418,7 @@ class ChatController extends BaseController
|
||||
]);
|
||||
$actualUsers = $this->chatUserModel->builder()->select("user_id")->where("chat_id", $chat_id)->get()->getResultArray();
|
||||
$actualUsersArray = array_map(fn($x) => $x["user_id"], $actualUsers);
|
||||
foreach ($actualUsersArray as $key => $user_id) {
|
||||
$this->chatNotificationModel->insert(
|
||||
["chat_message_id" => $chatMessageId, "user_id" => $user_id]
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($bodyData["users"])) {
|
||||
foreach ($bodyData["users"] as $userId) {
|
||||
if (in_array($userId, $actualUsersArray) == false) {
|
||||
@ -638,55 +432,13 @@ class ChatController extends BaseController
|
||||
}
|
||||
return $this->response->setJSON(["message" => "Hebra actualizada correctamente", "status" => true]);
|
||||
}
|
||||
public function get_hebra_presupuesto($presupuesto_id)
|
||||
public function get_hebra(string $model,int $modelId)
|
||||
{
|
||||
$data = $this->chatModel->getPresupuestoHebras($presupuesto_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.presupuesto_id", $presupuesto_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_hebra_pedido($pedido_id)
|
||||
{
|
||||
$data = $this->chatModel->getPedidoHebras($pedido_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.pedido_id", $pedido_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function get_hebra_factura($factura_id)
|
||||
{
|
||||
$data = $this->chatModel->getFacturaHebras($factura_id);
|
||||
$notifications = $this->chatModel->builder()->select([
|
||||
"chat_notifications.id"
|
||||
])
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chats.factura_id", $factura_id)
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->get()->getResultArray();
|
||||
foreach ($notifications as $notification) {
|
||||
$this->chatNotificationModel->update($notification["id"], ["viewed" => true]);
|
||||
}
|
||||
$data = $this->chatService->getHebras($model,$modelId);
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
|
||||
|
||||
public function datatable_messages()
|
||||
{
|
||||
$auth_user_id = auth()->user()->id;
|
||||
@ -716,9 +468,9 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "presupuesto", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("action", fn($q) => ["type" => "presupuesto", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
@ -732,9 +484,9 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "pedido", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->add("action", fn($q) => ["type" => "pedido", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
@ -749,27 +501,26 @@ class ChatController extends BaseController
|
||||
return DataTable::of($query)
|
||||
->edit('created_at', fn($q) => $q->created_at ? Time::createFromFormat('Y-m-d H:i:s', $q->created_at)->format("d/m/Y H:i") : "")
|
||||
->edit('updated_at', fn($q) => $q->updated_at ? Time::createFromFormat('Y-m-d H:i:s', $q->updated_at)->format("d/m/Y H:i") : "")
|
||||
->add("creator", fn($q) => $this->chatModel->getChatFirstUser($q->id)->userFullName)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->id, $auth_user_id))
|
||||
->add("action", fn($q) => ["type" => "factura", "modelId" => $q->id, "isAdmin" => $isAdmin, "lang" => [
|
||||
->edit("creator",fn($q) => $q->userId == $auth_user_id ? '<span class="badge text-bg-success w-100">'.lang("App.me").'</span>' : $q->creator)
|
||||
->add("viewed", fn($q) => $this->chatModel->isMessageChatViewed($q->chatMessageId))
|
||||
->add("action", fn($q) => ["type" => "factura", "modelId" => $q->id, "isAdmin" => $isAdmin,"chatMessageId" => $q->chatMessageId, "lang" => [
|
||||
"view_chat" => lang('Chat.view_chat'),
|
||||
"view_by_alt_message" => lang('Chat.view_by_alt_message')
|
||||
]])
|
||||
|
||||
->toJson(true);
|
||||
}
|
||||
public function get_notifications_not_viewed_from_chat(int $chat_id)
|
||||
public function get_notifications_not_viewed_from_message(int $chat_message_id)
|
||||
{
|
||||
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_id);
|
||||
$viewedNotifications = $this->chatModel->getUsersNotificationViewedFromChat($chat_id);
|
||||
$unviewedNotifications = $this->chatModel->getUsersNotificationNotViewedFromChat($chat_message_id);
|
||||
// $viewedNotifications = $this->chatModel->getUsersNotificationViewedFromChat($chat_message_id);
|
||||
|
||||
return $this->response->setJSON(
|
||||
[
|
||||
"data" => [
|
||||
"unviewedNotifications" => $unviewedNotifications,
|
||||
"viewedNotifications" => $viewedNotifications
|
||||
"notifications" => $unviewedNotifications,
|
||||
],
|
||||
"chat_id" => $chat_id
|
||||
"chat_message_id" => $chat_message_id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user