Files
hortusfox-web/app/models/ChatViewModel.php
2025-02-03 15:38:52 +01:00

32 lines
784 B
PHP

<?php
/**
* Class ChatViewModel
*
* Handles the "seen" status of chat messages by users
*/
class ChatViewModel extends \Asatru\Database\Model {
/**
* @param $userId
* @param $messageId
* @return bool
* @throws \Exception
*/
public static function handleNewMessage($userId, $messageId)
{
try {
$row = static::raw('SELECT * FROM `@THIS` WHERE userId = ? AND messageId = ?', [$userId, $messageId])->first();
if (!$row) {
static::raw('INSERT INTO `@THIS` (userId, messageId) VALUES(?, ?)', [
$userId, $messageId
]);
return true;
}
return false;
} catch (\Exception $e) {
throw $e;
}
}
}