mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix uri chat notifications
This commit is contained in:
@ -321,65 +321,73 @@ class ChatModel extends Model
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
|
||||
$q = $this->db->table("chats")
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
"chats.pedido_id as pedidoId",
|
||||
"chats.presupuesto_id as presupuestoId",
|
||||
"chats.factura_id as facturaId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
"chat_departments.display as chatDisplay",
|
||||
"chats.title as chatDisplay",
|
||||
])
|
||||
->join("chat_departments", "chat_departments.id = chats.chat_department_id", "left")
|
||||
->join("chat_department_users", "chat_department_users.chat_department_id = chats.chat_department_id", "left")
|
||||
->where("chat_department_users.user_id", auth()->user()->id);
|
||||
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||
->where("chat_notifications.user_id", auth()->user()->id)
|
||||
->where("chat_notifications.viewed", false)
|
||||
->where("chats.chat_department_id is NOT NULL",NULL,FALSE);
|
||||
|
||||
$rows = $q->get()->getResultObject();
|
||||
$auth_user = auth()->user();
|
||||
$rows_new = [];
|
||||
foreach ($rows as $row) {
|
||||
$messages = $chatMessageModel->get_chat_messages($row->chatId);
|
||||
$count = 0;
|
||||
$chatDeparmentUsers = $chatDeparmentModel->getChatDepartmentUsers($row->chatDepartmentId);
|
||||
$chatDeparmentUsersId = array_map(fn($x) => $x->id, $chatDeparmentUsers);
|
||||
foreach ($messages as $m) {
|
||||
if ($m->viewed == false && $m->sender_id != auth()->user()->id && in_array($m->sender_id, $chatDeparmentUsersId) == false)
|
||||
$count++;
|
||||
}
|
||||
$row->unreadMessages = 0;
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if($auth_user->cliente_id){
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}else{
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay = $row->model->titulo;
|
||||
}else{
|
||||
$row->chatDisplay .="[INTERNAL]";
|
||||
}
|
||||
$row->avatar = "PRE";
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||
$row->title = $row->pedidoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->avatar = "P";
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/chat/factura/" . $row->chatId;
|
||||
$row->avatar = "F";
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
}
|
||||
$row->title = $row->facturaId;
|
||||
$row->unreadMessages = $count;
|
||||
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
|
||||
$rows_new[] = $row;
|
||||
}
|
||||
}
|
||||
return $rows;
|
||||
return $rows_new;
|
||||
}
|
||||
public function getChatInternalNotifications()
|
||||
{
|
||||
$chatMessageModel = model(ChatMessageModel::class);
|
||||
$presupuestoModel = model(PresupuestoModel::class);
|
||||
$facturaModel = model(FacturaModel::class);
|
||||
$pedidoModel = model(PedidoModel::class);
|
||||
$chatNotificationModel = model(ChatNotification::class);
|
||||
|
||||
$q = $this->db->table("chats")
|
||||
$q = $this->builder()
|
||||
->select([
|
||||
"chats.id as chatId",
|
||||
"chats.chat_department_id as chatDepartmentId",
|
||||
@ -401,9 +409,9 @@ class ChatModel extends Model
|
||||
if ($row->presupuestoId) {
|
||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||
if($auth_user->cliente_id){
|
||||
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId;
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}else{
|
||||
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId;
|
||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||
}
|
||||
$row->title = $row->presupuestoId;
|
||||
if($row->chatDepartmentId){
|
||||
@ -416,7 +424,7 @@ class ChatModel extends Model
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->pedidoId) {
|
||||
$row->model = $pedidoModel->find($row->pedidoId);
|
||||
$row->uri = "/pedidos/edit/" . $row->pedidoId;
|
||||
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||
$row->title = $row->pedidoId;
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
@ -426,7 +434,7 @@ class ChatModel extends Model
|
||||
$rows_new[] = $row;
|
||||
} elseif ($row->facturaId) {
|
||||
$row->model = $facturaModel->find($row->facturaId);
|
||||
$row->uri = "/facturas/edit/" . $row->facturaId;
|
||||
$row->uri = "/chat/factura/" . $row->chatId;
|
||||
$row->avatar = "F";
|
||||
if($row->chatDepartmentId){
|
||||
$row->chatDisplay .= "[INTERNAL]";
|
||||
|
||||
@ -14,7 +14,7 @@ class Chat {
|
||||
this.sendBtnMessageDepartment = this.domItem.find("#send-msg-btn-deparment")
|
||||
this.sendBtnMessageInternal = this.domItem.find("#send-msg-btn-internal")
|
||||
this.chatSidebarLeftUserAbout = this.domItem.find('.chat-sidebar-left-user-about'),
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.messageInput = this.domItem.find(".message-input")
|
||||
this.sideBar = this.domItem.find(".sidebar-body")
|
||||
this.chatDeparmentId = undefined
|
||||
this.searchInput = this.domItem.find(".chat-search-input")
|
||||
@ -78,6 +78,8 @@ class Chat {
|
||||
this.btnUpdateMessagesUnviewed = this.domItem.find("#update-message-unviewed")
|
||||
this.btnDirectMessageSubmit = this.domItem.find("#send-msg-btn-direct")
|
||||
this.btnDirectMessageSubmit.on("click", this._handleStoreChatDirectMessage.bind(this))
|
||||
this.messageInput.on("keypress", this._sendDirectMessagePressKey.bind(this))
|
||||
|
||||
this.selectParticipants = new ClassSelect(this.modalNewParticipant.item.find("#select-users"), `/chat/direct/users/select/${this.modelId}`, this.selectPlaceholder, true)
|
||||
this.authUserId = this.domItem.data("user-id")
|
||||
this.checkboxNotificationMessage = this.modalNewParticipant.item.find("#checkbox-notification-chat")
|
||||
@ -157,6 +159,7 @@ class Chat {
|
||||
this.sendBtnMessageDepartment.removeClass("d-none")
|
||||
this.sendBtnMessageInternal.addClass("d-none")
|
||||
}
|
||||
|
||||
/**============================================
|
||||
* PRESUPUESTOS
|
||||
*=============================================**/
|
||||
@ -380,6 +383,13 @@ class Chat {
|
||||
this._sendMessage()
|
||||
}
|
||||
|
||||
}
|
||||
_sendDirectMessagePressKey(e) {
|
||||
if (e.which == 13) {
|
||||
e.preventDefault();
|
||||
this._handleStoreChatDirectMessage()
|
||||
}
|
||||
|
||||
}
|
||||
_sendMessage() {
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import Chat from '../components/chat.js'
|
||||
import InternalMessages from "../components/internalMessagesSection.js"
|
||||
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
||||
|
||||
$(document).ready(() => {
|
||||
$(() => {
|
||||
let chat = new Chat($("#chat-factura"))
|
||||
chat.init()
|
||||
chat.initFactura()
|
||||
@ -10,9 +10,12 @@ $(document).ready(() => {
|
||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||
internalMessages.init()
|
||||
}
|
||||
let modalDirectMessageClient = new ModalDirectMessageClient("factura", $("#modalNewDirectMessageClient"))
|
||||
modalDirectMessageClient.init()
|
||||
$("#direct-message-cliente").on("click",() => {
|
||||
modalDirectMessageClient.modal.show()
|
||||
})
|
||||
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||
|
||||
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||
modalDirectMessageClient.init()
|
||||
$("#direct-message-cliente").on("click", () => {
|
||||
modalDirectMessageClient.modal.show()
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -2,7 +2,7 @@ import Chat from '../components/chat.js'
|
||||
import InternalMessages from "../components/internalMessagesSection.js"
|
||||
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
||||
|
||||
$(document).ready(() => {
|
||||
$(() => {
|
||||
let chat = new Chat($("#chat-pedido"))
|
||||
chat.init()
|
||||
chat.initPedido()
|
||||
@ -10,10 +10,13 @@ $(document).ready(() => {
|
||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||
internalMessages.init()
|
||||
}
|
||||
let modalDirectMessageClient = new ModalDirectMessageClient("pedido", $("#modalNewDirectMessageClient"))
|
||||
modalDirectMessageClient.init()
|
||||
$("#direct-message-cliente").on("click",() => {
|
||||
modalDirectMessageClient.modal.show()
|
||||
})
|
||||
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||
|
||||
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||
modalDirectMessageClient.init()
|
||||
$("#direct-message-cliente").on("click", () => {
|
||||
modalDirectMessageClient.modal.show()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
@ -5,14 +5,19 @@ $(function () {
|
||||
let chat = new Chat($("#chat-presupuesto"))
|
||||
chat.init()
|
||||
chat.initPresupuesto()
|
||||
if ($("#internal_messages_chat").length > 0) {
|
||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||
internalMessages.init()
|
||||
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||
|
||||
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||
modalDirectMessageClient.init()
|
||||
$("#direct-message-cliente").on("click",() => {
|
||||
$("#direct-message-cliente").on("click", () => {
|
||||
modalDirectMessageClient.modal.show()
|
||||
})
|
||||
}
|
||||
if ($("#internal_messages_chat").length > 0) {
|
||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||
internalMessages.init()
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user