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);
|
$facturaModel = model(FacturaModel::class);
|
||||||
$pedidoModel = model(PedidoModel::class);
|
$pedidoModel = model(PedidoModel::class);
|
||||||
|
|
||||||
$q = $this->db->table("chats")
|
$q = $this->builder()
|
||||||
->select([
|
->select([
|
||||||
"chats.id as chatId",
|
"chats.id as chatId",
|
||||||
|
"chats.chat_department_id as chatDepartmentId",
|
||||||
"chats.pedido_id as pedidoId",
|
"chats.pedido_id as pedidoId",
|
||||||
"chats.presupuesto_id as presupuestoId",
|
"chats.presupuesto_id as presupuestoId",
|
||||||
"chats.factura_id as facturaId",
|
"chats.factura_id as facturaId",
|
||||||
"chats.chat_department_id as chatDepartmentId",
|
"chats.title as chatDisplay",
|
||||||
"chat_departments.display as chatDisplay",
|
|
||||||
])
|
])
|
||||||
->join("chat_departments", "chat_departments.id = chats.chat_department_id", "left")
|
->join("chat_messages", "chat_messages.chat_id = chats.id", "left")
|
||||||
->join("chat_department_users", "chat_department_users.chat_department_id = chats.chat_department_id", "left")
|
->join("chat_notifications", "chat_notifications.chat_message_id = chat_messages.id", "left")
|
||||||
->where("chat_department_users.user_id", auth()->user()->id);
|
->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();
|
$rows = $q->get()->getResultObject();
|
||||||
$auth_user = auth()->user();
|
$auth_user = auth()->user();
|
||||||
|
$rows_new = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$messages = $chatMessageModel->get_chat_messages($row->chatId);
|
$row->unreadMessages = 0;
|
||||||
$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++;
|
|
||||||
}
|
|
||||||
if ($row->presupuestoId) {
|
if ($row->presupuestoId) {
|
||||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||||
if($auth_user->cliente_id){
|
if($auth_user->cliente_id){
|
||||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||||
}else{
|
}else{
|
||||||
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||||
|
|
||||||
}
|
}
|
||||||
$row->title = $row->presupuestoId;
|
$row->title = $row->presupuestoId;
|
||||||
|
if($row->chatDepartmentId){
|
||||||
|
$row->chatDisplay = $row->model->titulo;
|
||||||
|
}else{
|
||||||
|
$row->chatDisplay .="[INTERNAL]";
|
||||||
|
}
|
||||||
$row->avatar = "PRE";
|
$row->avatar = "PRE";
|
||||||
$row->unreadMessages = $count;
|
$row->unreadMessages = $this->countUnreadMessagePresupuesto($row->presupuestoId);
|
||||||
|
$rows_new[] = $row;
|
||||||
} elseif ($row->pedidoId) {
|
} elseif ($row->pedidoId) {
|
||||||
$row->model = $pedidoModel->find($row->pedidoId);
|
$row->model = $pedidoModel->find($row->pedidoId);
|
||||||
$row->uri = "/chat/pedido/" . $row->chatId;
|
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||||
$row->title = $row->pedidoId;
|
$row->title = $row->pedidoId;
|
||||||
|
if($row->chatDepartmentId){
|
||||||
|
$row->chatDisplay .= "[INTERNAL]";
|
||||||
|
}
|
||||||
$row->avatar = "P";
|
$row->avatar = "P";
|
||||||
$row->unreadMessages = $count;
|
$row->unreadMessages = $this->countUnreadMessagePedido($row->pedidoId);
|
||||||
|
$rows_new[] = $row;
|
||||||
} elseif ($row->facturaId) {
|
} elseif ($row->facturaId) {
|
||||||
$row->model = $facturaModel->find($row->facturaId);
|
$row->model = $facturaModel->find($row->facturaId);
|
||||||
$row->uri = "/chat/factura/" . $row->chatId;
|
$row->uri = "/chat/factura/" . $row->chatId;
|
||||||
$row->avatar = "F";
|
$row->avatar = "F";
|
||||||
|
if($row->chatDepartmentId){
|
||||||
|
$row->chatDisplay .= "[INTERNAL]";
|
||||||
|
}
|
||||||
$row->title = $row->facturaId;
|
$row->title = $row->facturaId;
|
||||||
$row->unreadMessages = $count;
|
$row->unreadMessages = $this->countUnreadMessageFactura($row->facturaId);
|
||||||
|
$rows_new[] = $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $rows;
|
return $rows_new;
|
||||||
}
|
}
|
||||||
public function getChatInternalNotifications()
|
public function getChatInternalNotifications()
|
||||||
{
|
{
|
||||||
$chatMessageModel = model(ChatMessageModel::class);
|
|
||||||
$presupuestoModel = model(PresupuestoModel::class);
|
$presupuestoModel = model(PresupuestoModel::class);
|
||||||
$facturaModel = model(FacturaModel::class);
|
$facturaModel = model(FacturaModel::class);
|
||||||
$pedidoModel = model(PedidoModel::class);
|
$pedidoModel = model(PedidoModel::class);
|
||||||
$chatNotificationModel = model(ChatNotification::class);
|
|
||||||
|
|
||||||
$q = $this->db->table("chats")
|
$q = $this->builder()
|
||||||
->select([
|
->select([
|
||||||
"chats.id as chatId",
|
"chats.id as chatId",
|
||||||
"chats.chat_department_id as chatDepartmentId",
|
"chats.chat_department_id as chatDepartmentId",
|
||||||
@ -401,9 +409,9 @@ class ChatModel extends Model
|
|||||||
if ($row->presupuestoId) {
|
if ($row->presupuestoId) {
|
||||||
$row->model = $presupuestoModel->find($row->presupuestoId);
|
$row->model = $presupuestoModel->find($row->presupuestoId);
|
||||||
if($auth_user->cliente_id){
|
if($auth_user->cliente_id){
|
||||||
$row->uri = "/presupuestocliente/edit/" . $row->presupuestoId;
|
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||||
}else{
|
}else{
|
||||||
$row->uri = "/presupuestoadmin/edit/" . $row->presupuestoId;
|
$row->uri = "/chat/presupuesto/" . $row->chatId;
|
||||||
}
|
}
|
||||||
$row->title = $row->presupuestoId;
|
$row->title = $row->presupuestoId;
|
||||||
if($row->chatDepartmentId){
|
if($row->chatDepartmentId){
|
||||||
@ -416,7 +424,7 @@ class ChatModel extends Model
|
|||||||
$rows_new[] = $row;
|
$rows_new[] = $row;
|
||||||
} elseif ($row->pedidoId) {
|
} elseif ($row->pedidoId) {
|
||||||
$row->model = $pedidoModel->find($row->pedidoId);
|
$row->model = $pedidoModel->find($row->pedidoId);
|
||||||
$row->uri = "/pedidos/edit/" . $row->pedidoId;
|
$row->uri = "/chat/pedido/" . $row->chatId;
|
||||||
$row->title = $row->pedidoId;
|
$row->title = $row->pedidoId;
|
||||||
if($row->chatDepartmentId){
|
if($row->chatDepartmentId){
|
||||||
$row->chatDisplay .= "[INTERNAL]";
|
$row->chatDisplay .= "[INTERNAL]";
|
||||||
@ -426,7 +434,7 @@ class ChatModel extends Model
|
|||||||
$rows_new[] = $row;
|
$rows_new[] = $row;
|
||||||
} elseif ($row->facturaId) {
|
} elseif ($row->facturaId) {
|
||||||
$row->model = $facturaModel->find($row->facturaId);
|
$row->model = $facturaModel->find($row->facturaId);
|
||||||
$row->uri = "/facturas/edit/" . $row->facturaId;
|
$row->uri = "/chat/factura/" . $row->chatId;
|
||||||
$row->avatar = "F";
|
$row->avatar = "F";
|
||||||
if($row->chatDepartmentId){
|
if($row->chatDepartmentId){
|
||||||
$row->chatDisplay .= "[INTERNAL]";
|
$row->chatDisplay .= "[INTERNAL]";
|
||||||
|
|||||||
@ -14,7 +14,7 @@ class Chat {
|
|||||||
this.sendBtnMessageDepartment = this.domItem.find("#send-msg-btn-deparment")
|
this.sendBtnMessageDepartment = this.domItem.find("#send-msg-btn-deparment")
|
||||||
this.sendBtnMessageInternal = this.domItem.find("#send-msg-btn-internal")
|
this.sendBtnMessageInternal = this.domItem.find("#send-msg-btn-internal")
|
||||||
this.chatSidebarLeftUserAbout = this.domItem.find('.chat-sidebar-left-user-about'),
|
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.sideBar = this.domItem.find(".sidebar-body")
|
||||||
this.chatDeparmentId = undefined
|
this.chatDeparmentId = undefined
|
||||||
this.searchInput = this.domItem.find(".chat-search-input")
|
this.searchInput = this.domItem.find(".chat-search-input")
|
||||||
@ -78,6 +78,8 @@ class Chat {
|
|||||||
this.btnUpdateMessagesUnviewed = this.domItem.find("#update-message-unviewed")
|
this.btnUpdateMessagesUnviewed = this.domItem.find("#update-message-unviewed")
|
||||||
this.btnDirectMessageSubmit = this.domItem.find("#send-msg-btn-direct")
|
this.btnDirectMessageSubmit = this.domItem.find("#send-msg-btn-direct")
|
||||||
this.btnDirectMessageSubmit.on("click", this._handleStoreChatDirectMessage.bind(this))
|
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.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.authUserId = this.domItem.data("user-id")
|
||||||
this.checkboxNotificationMessage = this.modalNewParticipant.item.find("#checkbox-notification-chat")
|
this.checkboxNotificationMessage = this.modalNewParticipant.item.find("#checkbox-notification-chat")
|
||||||
@ -157,6 +159,7 @@ class Chat {
|
|||||||
this.sendBtnMessageDepartment.removeClass("d-none")
|
this.sendBtnMessageDepartment.removeClass("d-none")
|
||||||
this.sendBtnMessageInternal.addClass("d-none")
|
this.sendBtnMessageInternal.addClass("d-none")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**============================================
|
/**============================================
|
||||||
* PRESUPUESTOS
|
* PRESUPUESTOS
|
||||||
*=============================================**/
|
*=============================================**/
|
||||||
@ -380,6 +383,13 @@ class Chat {
|
|||||||
this._sendMessage()
|
this._sendMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
_sendDirectMessagePressKey(e) {
|
||||||
|
if (e.which == 13) {
|
||||||
|
e.preventDefault();
|
||||||
|
this._handleStoreChatDirectMessage()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
_sendMessage() {
|
_sendMessage() {
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import Chat from '../components/chat.js'
|
|||||||
import InternalMessages from "../components/internalMessagesSection.js"
|
import InternalMessages from "../components/internalMessagesSection.js"
|
||||||
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(() => {
|
||||||
let chat = new Chat($("#chat-factura"))
|
let chat = new Chat($("#chat-factura"))
|
||||||
chat.init()
|
chat.init()
|
||||||
chat.initFactura()
|
chat.initFactura()
|
||||||
@ -10,9 +10,12 @@ $(document).ready(() => {
|
|||||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||||
internalMessages.init()
|
internalMessages.init()
|
||||||
}
|
}
|
||||||
let modalDirectMessageClient = new ModalDirectMessageClient("factura", $("#modalNewDirectMessageClient"))
|
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||||
modalDirectMessageClient.init()
|
|
||||||
$("#direct-message-cliente").on("click",() => {
|
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||||
modalDirectMessageClient.modal.show()
|
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 InternalMessages from "../components/internalMessagesSection.js"
|
||||||
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
import ModalDirectMessageClient from '../components/modals/modalDirectMessageClient.js'
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(() => {
|
||||||
let chat = new Chat($("#chat-pedido"))
|
let chat = new Chat($("#chat-pedido"))
|
||||||
chat.init()
|
chat.init()
|
||||||
chat.initPedido()
|
chat.initPedido()
|
||||||
@ -10,10 +10,13 @@ $(document).ready(() => {
|
|||||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
||||||
internalMessages.init()
|
internalMessages.init()
|
||||||
}
|
}
|
||||||
let modalDirectMessageClient = new ModalDirectMessageClient("pedido", $("#modalNewDirectMessageClient"))
|
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||||
modalDirectMessageClient.init()
|
|
||||||
$("#direct-message-cliente").on("click",() => {
|
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||||
modalDirectMessageClient.modal.show()
|
modalDirectMessageClient.init()
|
||||||
})
|
$("#direct-message-cliente").on("click", () => {
|
||||||
|
modalDirectMessageClient.modal.show()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
@ -5,14 +5,19 @@ $(function () {
|
|||||||
let chat = new Chat($("#chat-presupuesto"))
|
let chat = new Chat($("#chat-presupuesto"))
|
||||||
chat.init()
|
chat.init()
|
||||||
chat.initPresupuesto()
|
chat.initPresupuesto()
|
||||||
if ($("#internal_messages_chat").length > 0) {
|
if ($("#modalNewDirectMessageClient").length > 0) {
|
||||||
let internalMessages = new InternalMessages($("#internal_messages_chat"))
|
|
||||||
internalMessages.init()
|
|
||||||
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
let modalDirectMessageClient = new ModalDirectMessageClient("presupuesto", $("#modalNewDirectMessageClient"))
|
||||||
modalDirectMessageClient.init()
|
modalDirectMessageClient.init()
|
||||||
$("#direct-message-cliente").on("click",() => {
|
$("#direct-message-cliente").on("click", () => {
|
||||||
modalDirectMessageClient.modal.show()
|
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