fix : mensajes internos, arreglar total numero mensajes

This commit is contained in:
amazuecos
2024-11-13 00:47:47 +01:00
parent b97e027920
commit eb604f3293
8 changed files with 64 additions and 30 deletions

View File

@ -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
];
}