Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions app/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ public static function getRoomsGroup(?int $userId = null)
while ($row = $dataReader->read()) {
if (isset($groups[$row['recordid']])) {
$row['isPinned'] = true;
$row['roomType'] = 'group';
$groups[$row['recordid']] = $row;
}
}
foreach ($groups as $id => $group) {
if (is_string($group)) {
if (\is_string($group)) {
$group = ['recordid' => $id, 'name' => $group, 'isPinned' => false];
}
$group['roomType'] = 'group';
$rows[$id] = $group;
}
$dataReader->close();
Expand Down Expand Up @@ -281,15 +281,16 @@ public static function getRoomsCrm(?int $userId = null)
/**
* Get room last message.
*
* @param int $roomId
* @param int $roomId
* @param string $roomType
*
* @return array
*/
public static function getRoomLastMessage(int $roomId, string $roomType): array
{
return (array) (new Db\Query())
->from(static::TABLE_NAME['message'][$roomType])
->where([$roomType === 'crm' ? 'crmid' : 'groupid' => $roomId])
->where(['crm' === $roomType ? 'crmid' : 'groupid' => $roomId])
->orderBy(['id' => \SORT_DESC])
->one();
}
Expand Down Expand Up @@ -545,6 +546,7 @@ public function addMessage(string $message): int
*
* @param int|null $messageId
* @param string $condition
* @param ?string $searchVal
*
* @throws \App\Exceptions\AppException
* @throws \App\Exceptions\IllegalValue
Expand Down Expand Up @@ -593,7 +595,7 @@ public function getHistoryByType(string $roomType = 'global', ?int $messageId =
{
$columnMessage = static::COLUMN_NAME['message'][$roomType];
$columnRoomName = static::COLUMN_NAME['room_name'][$roomType];
$roomNameId = $roomType === 'global' ? static::COLUMN_NAME['room']['global'] : $columnMessage;
$roomNameId = 'global' === $roomType ? static::COLUMN_NAME['room']['global'] : $columnMessage;
$query = (new Db\Query())
->select([
'id', 'messages', 'userid', 'created',
Expand All @@ -616,11 +618,11 @@ public function getHistoryByType(string $roomType = 'global', ?int $messageId =
$dataReader = $query->createCommand()->query();
$notPermittedIds = [];
while ($row = $dataReader->read()) {
if ('group' === $roomType && !isset($groups[$row['recordid']])) {
if ('group' === $roomType && !isset($groups[$row['recordid']])) {
continue;
}
if ('crm' === $roomType) {
if(in_array($row['recordid'], $notPermittedIds)) {
if ('crm' === $roomType) {
if (\in_array($row['recordid'], $notPermittedIds)) {
continue;
}
if (!Record::isExists($row['recordid']) || !\Vtiger_Record_Model::getInstanceById($row['recordid'])->isViewable()) {
Expand Down Expand Up @@ -880,7 +882,7 @@ public function addToFavorites()
Db::getInstance()->createCommand()->insert(
static::TABLE_NAME['room'][$this->roomType],
[
'last_message' => isset($lastMessage['id']) ? $lastMessage['id'] : 0,
'last_message' => $lastMessage['id'] ?? 0,
'userid' => $this->userId,
static::COLUMN_NAME['room'][$this->roomType] => $this->recordId
]
Expand All @@ -895,6 +897,7 @@ public function addToFavorites()
* @param int|null $messageId
* @param string $condition
* @param bool $isLimit
* @param ?string $searchVal
*
* @throws \App\Exceptions\IllegalValue
*
Expand Down
Loading