add client to chat

This commit is contained in:
amazuecos
2025-03-17 06:50:35 +01:00
parent 55157d23aa
commit 3662613ba5
7 changed files with 248 additions and 108 deletions

View File

@ -897,7 +897,10 @@ $routes->group('chat', ['namespace' => 'App\Controllers\Chat'], function ($route
$routes->get('department/presupuesto/(:num)/(:num)', 'ChatController::get_chat_presupuesto/$1/$2', ['as' => 'getChatPresupuesto']);
$routes->get('department/pedido/(:num)/(:num)', 'ChatController::get_chat_pedido/$1/$2', ['as' => 'getChatPedido']);
$routes->get('department/factura/(:num)/(:num)', 'ChatController::get_chat_factura/$1/$2', ['as' => 'getChatFactura']);
$routes->get('department/(:num)/users', 'ChatController::get_chat_department_users/$1', ['as' => 'getChatDepartmentUsers']);
$routes->get('department/users/presupuesto/(:num)/(:num)', 'ChatController::get_chat_department_presupuesto_users/$1/$2', ['as' => 'getPresupuestoChatDepartmentUsers']);
$routes->get('department/users/pedido/(:num)/(:num)', 'ChatController::get_chat_department_pedido_users/$1/$2', ['as' => 'getPedidoChatDepartmentUsers']);
$routes->get('department/users/factura/(:num)/(:num)', 'ChatController::get_chat_department_factura_users/$1/$2', ['as' => 'getFacturaChatDepartmentUsers']);
$routes->post('department/user', 'ChatController::subscribe_to_chat_deparment/$1', ['as' => 'subscribeToChatDepartment']);
$routes->delete('department/user/(:num)', 'ChatController::delete_user_from_department/$1', ['as' => 'deleteUserFromDepartment']);

View File

@ -207,15 +207,18 @@ class ChatController extends BaseController
$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"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPresupuestoUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
$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();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'presupuesto_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'presupuesto_id' => $data['model_id']]);
}
}
foreach ($chatDepartmentUsers as $user) {
@ -223,6 +226,11 @@ class ChatController extends BaseController
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
foreach ($chatExternalUsers as $user) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
}
public function store_chat_message_pedido()
@ -239,21 +247,30 @@ class ChatController extends BaseController
$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"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentPedidoUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
$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();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'pedido_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_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) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
}
public function store_chat_message_factura()
@ -270,21 +287,30 @@ class ChatController extends BaseController
$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"]);
$chatExternalUsers = $this->chatDeparmentModel->getChatDeparmentFacturaUsers($data["chat_department_id"],$data["model_id"]);
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $data['client']]);
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->countAllResults();
$cliente_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',$data['client'])->where('factura_id',$data['model_id'])->countAllResults();
$auth_user_in_department_count = $this->chatDeparmentUserModel->where('chat_department_id',$data["chat_department_id"])->where('user_id',auth()->user()->id)->countAllResults();
if($cliente_in_department_count == 0){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client']]);
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => $data['client'],'factura_id' => $data['model_id']]);
}
if($auth_user_in_department_count){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'user_id' => auth()->user()->id]);
$users_always_in_department = array_map(fn($q) => $q->id,$chatDepartmentUsers);
if(!in_array(auth()->user()->id,$users_always_in_department)){
$this->chatDeparmentUserModel->insert(['chat_department_id' => $data["chat_department_id"],'factura_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) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
return $this->response->setJSON($dataResponse);
}
public function store_chat_message_single()
@ -392,10 +418,23 @@ class ChatController extends BaseController
return $this->response->setJSON($response);
}
public function get_chat_department_users(int $chat_department_id)
public function get_chat_department_presupuesto_users(int $chat_department_id,int $presupuesto_id)
{
$data = $this->chatDeparmentModel->getChatDepartmentUsers($chat_department_id);
return $this->response->setJSON($data);
$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]);
}
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]);
}
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]);
}
public function get_chat_users_internal()
{
@ -837,8 +876,18 @@ class ChatController extends BaseController
}
public function delete_user_from_department($chat_department_id)
{
$data = $this->request->getPost();
$user_id = auth()->user()->id;
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id);
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)
->where('user_id',$user_id)
->where('pedido_id',null)
->where('factura_id',null)
->where('presupuesto_id',null)->countAllResults();
if($adminExist)
{
return $this->response->setJSON(["message" => lang('Chat.exit_admin_chat_wrong'),"status" => false]);
}
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id)->where($data['model_fk'],$data['model_id_fk']);
if($chatDepartmentUserEntity->countAllResults() > 0)
{
$deleted = $this->chatDeparmentUserModel->where('chat_department_id',$chat_department_id)->where('user_id',$user_id)->delete();
@ -851,12 +900,21 @@ class ChatController extends BaseController
{
$data = $this->request->getPost();
$user_id = auth()->user()->id;
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])->where('user_id',$user_id);
$adminExist = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])
->where('user_id',$user_id)
->where('pedido_id',null)
->where('factura_id',null)
->where('presupuesto_id',null)->countAllResults();
if($adminExist)
{
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'),"status" => false]);
}
$chatDepartmentUserEntity = $this->chatDeparmentUserModel->where('chat_department_id',$data['chat_department_id'])->where('user_id',$user_id)->where($data['model_fk'],$data['model_id_fk']);
if($chatDepartmentUserEntity->countAllResults() > 0)
{
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_wrong'),"status" => false]);
}else{
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"],"user_id" => $user_id]);
$this->chatDeparmentUserModel->insert(["chat_department_id" => $data["chat_department_id"],"user_id" => $user_id,$data['model_fk'] => $data['model_id_fk']]);
return $this->response->setJSON(["message" => lang('Chat.subscribe_chat_ok'), "status" => true]);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class AddForeignChatDepartmentUsers extends Migration
{
protected array $COLUMNS = [
"pedido_id" => [
"type" => "INT",
"constraint" => 16,
"unsigned" => true,
"null" => true
],
"presupuesto_id" => [
"type" => "INT",
"constraint" => 10,
"unsigned" => true,
"null" => true
],
"factura_id" => [
"type" => "INT",
"constraint" => 10,
"unsigned" => true,
"null" => true
],
];
public function up()
{
$this->forge->addColumn("chat_department_users",$this->COLUMNS);
$this->forge->addForeignKey('pedido_id', 'pedidos', 'id');
$this->forge->addForeignKey('factura_id', 'facturas', 'id');
$this->forge->addForeignKey('presupuesto_id', 'presupuestos', 'id');
}
public function down()
{
$this->forge->dropForeignKey("chat_department_users","pedido_id");
$this->forge->dropForeignKey("chat_department_users","factura_id");
$this->forge->dropForeignKey("chat_department_users","presupuesto_id");
$this->forge->dropColumn("chat_department_users",["pedido_id","factura_id","presupuesto_id"]);
}
}

View File

@ -40,9 +40,7 @@ return [
"subscribe_chat" => 'Subscribirse al chat',
"exit_chat_ok" => "Ha salido de la conversación correctamente. No recibirá más notificaciones a no ser que sea añadido de nuevo.",
"exit_chat_wrong" => "No puede salir de la conversación porque no pertenece a ella.",
"exit_admin_chat_wrong" => "Perteneces como personal a este chat y no puedes salirte. Contacta administrador para ello.",
"subscribe_chat_ok" => "Te has subscrito al chat correctamente. Ahora recibirás notificaciones cuando lleguen mensajes.",
"subscribe_chat_wrong" => "Ya perteneces a este chat.",
];

View File

@ -89,7 +89,7 @@ class ChatDeparmentModel extends Model
$departmentName = $row['name'];
// If the department is not yet added to the array, initialize it
if (!isset($departments[$departmentName])) {
$departments[$departmentName] = [
'id' => $row['id'],
'name' => $row['name'],
@ -105,9 +105,10 @@ class ChatDeparmentModel extends Model
}
return $departments;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
public function getChatDeparmentUserQuery(int $chat_deparment_id)
{
$result = $this->builder()
$query = $this->builder()
->select(
[
"users.*"
@ -123,12 +124,42 @@ class ChatDeparmentModel extends Model
"chat_department_users.user_id = users.id",
'left'
)->where("chat_departments.id", $chat_deparment_id)
->where("chat_department_users.deleted_at",null)
->where("users.deleted_at",null)
->where("chat_department_users.deleted_at", null)
->where("users.deleted_at", null);
return $query;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.presupuesto_id', null)
->where('chat_department_users.pedido_id', null)
->where('chat_department_users.factura_id', null)
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id) : string
public function getChatDeparmentPresupuestoUsers(int $chat_deparment_id, int $presupuesto_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.presupuesto_id', $presupuesto_id)
->get()->getResultObject();
return $result;
}
public function getChatDeparmentPedidoUsers(int $chat_deparment_id, int $pedido_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.pedido_id', $pedido_id)
->get()->getResultObject();
return $result;
}
public function getChatDeparmentFacturaUsers(int $chat_deparment_id, int $factura_id)
{
$result = $this->getChatDeparmentUserQuery($chat_deparment_id)
->where('chat_department_users.factura_id', $factura_id)
->get()->getResultObject();
return $result;
}
public function getDisplay(int $chat_deparment_id): string
{
return $this->find($chat_deparment_id)->display;
}
@ -139,9 +170,9 @@ class ChatDeparmentModel extends Model
"display as name",
"description"
]);
if($query){
$q->orLike("display",$query)
->orLike("name",$query);
if ($query) {
$q->orLike("display", $query)
->orLike("name", $query);
}
return $q;
}

View File

@ -15,7 +15,10 @@ class ChatDeparmentUserModel extends Model
protected $protectFields = true;
protected $allowedFields = [
"chat_department_id",
"user_id"
"user_id",
"pedido_id",
"factura_id",
"presupuesto_id"
];
protected bool $allowEmptyInserts = false;
@ -47,6 +50,7 @@ class ChatDeparmentUserModel extends Model
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getChatDepartmentUser(int $user_id)
{
return $this->db->table($this->table." t1")
@ -55,6 +59,5 @@ class ChatDeparmentUserModel extends Model
->where("t1.user_id",$user_id)
->where("t1.deleted_at",null)
->get()->getResultObject();
}
}

View File

@ -1,7 +1,7 @@
import Ajax from '../components/ajax.js'
import Modal from './modal.js'
import ClassSelect from './select2.js'
import {alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess} from "./alerts/sweetAlert.js"
import { alertConfirmAction, alertConfirmationDelete, alertError, alertSuccess } from "./alerts/sweetAlert.js"
class Chat {
@ -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.selectItem = this.domItem.find(".chat-search-client")
this.btnExitChat = this.domItem.find(".exit-chat")
@ -55,8 +55,8 @@ class Chat {
}
this.sendBtnMessageDepartment.addClass("d-none")
this.btnExitChat.on('click',this._handleExitChatDepartment.bind(this))
this.btnSubscribeChat.on('click',this._handleSubscribeChatDepartment.bind(this))
this.btnExitChat.on('click', this._handleExitChatDepartment.bind(this))
this.btnSubscribeChat.on('click', this._handleSubscribeChatDepartment.bind(this))
this.sendBtnMessageInternal.addClass("d-none")
if (this.chatContactsBody[0]) {
@ -98,7 +98,7 @@ class Chat {
this.selectParticipants.init()
this.modalNewParticipant.toggle()
})
this.selectParticipants.item.on("change", () => {
if (this.selectParticipants.getVal().length > 0) {
this.btnAddParticipantSubmit.removeClass("d-none")
@ -106,19 +106,18 @@ class Chat {
this.btnAddParticipantSubmit.addClass("d-none")
}
})
this.btnUpdateMessagesUnviewed.on("click",this._handleUpdateChatMessagesUnread.bind(this))
this.btnUpdateMessagesUnviewed.on("click", this._handleUpdateChatMessagesUnread.bind(this))
this._handleGetChatDirect()
setInterval(this._handleReloadChatDirectMessages.bind(this),10000)
setInterval(this._handleReloadChatDirectMessages.bind(this), 10000)
}
initSelectClient()
{
this.selectClientUser = new ClassSelect(this.selectItem,`/chat/direct/client/users/select/${this.chatType}/${this.modelId}`,"Seleccione contacto",true)
initSelectClient() {
this.selectClientUser = new ClassSelect(this.selectItem, `/chat/direct/client/users/select/${this.chatType}/${this.modelId}`, "Seleccione contacto", true)
this.selectClientUser.init()
this.selectItem.on('change',() => {
if(this.selectClientUser.getVal()){
this.sendBtnMessageDepartment.attr('disabled',null)
}else{
this.sendBtnMessageDepartment.attr('disabled','disabled')
this.selectItem.on('change', () => {
if (this.selectClientUser.getVal()) {
this.sendBtnMessageDepartment.attr('disabled', null)
} else {
this.sendBtnMessageDepartment.attr('disabled', 'disabled')
}
})
@ -228,7 +227,7 @@ class Chat {
this.domItem.find("#chat-header-users").empty()
this.domItem.find("#chat-header-dropdown-users").removeClass("d-none")
let ajax = new Ajax(
`/chat/department/${this.chatDeparmentId}/users`,
`/chat/department/users/${this.chatType}/${this.chatDeparmentId}/${this.modelId}`,
null,
null,
this._getChatDeparmentUsersSuccess.bind(this),
@ -238,31 +237,34 @@ class Chat {
ajax.get()
}
_getChatDeparmentUsersSuccess(deparmentUsers) {
deparmentUsers.map((user) => {
this.domItem.find("#chat-header-users").append(
`
<li class="chat-contact-list-item p-1">
<a class="d-flex align-items-center py-1"
id="chat-contact-list-item-${user.id}">
<div class="avatar d-block flex-shrink-0">
<span class="avatar-initial rounded-circle bg-label-primary">
${user?.first_name?.charAt(0) ?? "?"
+ user?.last_name?.charAt(0) ?? "?"}</span>
</div>
<div class="chat-contact-info flex-grow-1 ms-2">
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
user?.last_name ?? ""}</h6>
<p class="chat-contact-status text-muted text-truncate mb-0">
${user.username}
</p>
</div>
</a>
</li>
deparmentUsers.admin_users.map(user => this.appendChatDepartmentUser(user))
deparmentUsers.external_users.map(user => this.appendChatDepartmentUser(user, 'warning', 'user'))
}
appendChatDepartmentUser(user, color = "primary", icon = "user") {
this.domItem.find("#chat-header-users").append(
`
)
})
<li class="chat-contact-list-item p-1">
<div class="d-flex align-items-center py-1"
id="chat-contact-list-item-${user.id}">
<div class="avatar-initial avatar-md px-2 py-2">
<span class="badge badge-center rounded-pill text-bg-${color}">
<i class="icon-base ti ti-xs ti-${icon}"></i>
</span>
</div>
<div class="chat-contact-info flex-grow-1 ms-2">
<h6 class="chat-contact-name text-truncate m-0">${user?.first_name ?? "" + " " +
user?.last_name ?? ""}</h6>
<p class="chat-contact-status text-muted text-truncate mb-0">
${user.username}
</p>
</div>
</div>
</li>
`
)
}
_getChatDeparmentUsersError(err) { }
@ -424,7 +426,7 @@ class Chat {
message: messageText,
chat_department_id: this.chatDeparmentId,
user: this.userId,
client : this.selectClientUser.getVal(),
client: this.selectClientUser.getVal(),
model_id: this.modelId
}
if (messageText) {
@ -442,6 +444,7 @@ class Chat {
_sendMessageSuccess(data) {
this.messageInput.val("")
this._getChatMessage(this.chatDeparmentId)
this._getChatDeparmentUsers()
}
_sendMessageError(err) {
console.error(err)
@ -674,7 +677,7 @@ class Chat {
}
_handleReloadChatDirectMessagesError(error) { }
_handleStoreChatDirectUsers() {
const data = { "users": this.selectParticipants.getVal() ,"notification" : this.checkboxNotificationMessage.prop("checked")}
const data = { "users": this.selectParticipants.getVal(), "notification": this.checkboxNotificationMessage.prop("checked") }
this.domItem.find(".chat-loader").removeClass("d-none")
const ajax = new Ajax(
@ -716,7 +719,7 @@ class Chat {
this._addChatDirectMessages(message)
this.messageInput.val("")
} catch (error) {
} finally {
this.scrollbarChatHistory.update()
this.chatHistoryBody[0].scrollTop = this.scrollbarChatHistory.containerHeight
@ -735,20 +738,22 @@ class Chat {
)
ajax.post()
}
_handleUpdateChatMessagesUnreadSuccess(){
_handleUpdateChatMessagesUnreadSuccess() {
this._handleReloadChatDirectMessages();
}
_handleUpdateChatMessagesUnreadError(){}
_handleRequestExitChatDeparment()
{
const ajax = new Ajax('/chat/department/user/'+this.chatDeparmentId,
null,
_handleUpdateChatMessagesUnreadError() { }
_handleRequestExitChatDeparment() {
const ajax = new Ajax('/chat/department/user/' + this.chatDeparmentId,
{
model_fk: this.chatType,
model_id_fk: this.modelId
},
null,
(response) => {
if(response.status){
if (response.status) {
alertSuccess(response.message).fire()
this._getChatDeparmentUsers()
}else{
} else {
alertError(response.message).fire()
}
},
@ -759,18 +764,19 @@ class Chat {
)
ajax.delete();
}
_handleRequestSubscribeChatDeparment()
{
_handleRequestSubscribeChatDeparment() {
const ajax = new Ajax('/chat/department/user',
{
chat_department_id : this.chatDeparmentId
chat_department_id: this.chatDeparmentId,
model_fk: this.chatType,
model_id_fk: this.modelId
},
null,
(response) => {
if(response.status){
if (response.status) {
alertSuccess(response.message).fire()
this._getChatDeparmentUsers()
}else{
} else {
alertError(response.message).fire()
}
},
@ -781,27 +787,23 @@ class Chat {
)
ajax.post();
}
_handleExitChatDepartment()
{
if(this.chatDeparmentId)
{
alertConfirmationDelete('¿Estás seguro de salir de la conversación?').then((result) => {
if(result.isConfirmed){
this._handleRequestExitChatDeparment()
}
})
}
_handleExitChatDepartment() {
if (this.chatDeparmentId) {
alertConfirmationDelete('¿Estás seguro de salir de la conversación?').then((result) => {
if (result.isConfirmed) {
this._handleRequestExitChatDeparment()
}
})
}
}
_handleSubscribeChatDepartment()
{
if(this.chatDeparmentId)
{
alertConfirmAction('¿Estás seguro de subscribirte al chat?').then((result) => {
if(result.isConfirmed){
this._handleRequestSubscribeChatDeparment()
}
})
}
_handleSubscribeChatDepartment() {
if (this.chatDeparmentId) {
alertConfirmAction('¿Estás seguro de subscribirte al chat?').then((result) => {
if (result.isConfirmed) {
this._handleRequestSubscribeChatDeparment()
}
})
}
}