diff --git a/Web/Models/Entities/Correspondence.php b/Web/Models/Entities/Correspondence.php index 77ba655b..031b905e 100644 --- a/Web/Models/Entities/Correspondence.php +++ b/Web/Models/Entities/Correspondence.php @@ -57,6 +57,14 @@ class Correspondence return "/im?sel=$id"; } + function getID(): int + { + $id = $this->correspondents[1]->getId(); + $id = get_class($this->correspondents[1]) === 'openvk\Web\Models\Entities\Club' ? $id * -1 : $id; + + return $id; + } + /** * Get correspondents as array. * @@ -86,6 +94,9 @@ class Correspondence ]; $params = array_merge($params[0], $params[1], array_reverse($params[0]), array_reverse($params[1]), $params[2]); + if ($limit === NULL) + DatabaseConnection::i()->getConnection()->query("UPDATE messages SET unread = 0 WHERE sender_id = ".$this->correspondents[1]->getId()); + if(is_null($cap)) { $query = str_replace("\n AND (`id` > ?)", "", $query); } else { @@ -102,7 +113,7 @@ class Correspondence if($reverse) $query = str_replace("`created` DESC", "`created` ASC", $query); - + $msgs = DatabaseConnection::i()->getConnection()->query($query, ...$params); $msgs = array_map(function($message) { $message = new ActiveRow((array) $message, $this->messages); #Directly creating ActiveRow is faster than making query @@ -150,8 +161,11 @@ class Correspondence $message->setSender_Type($classes[0]); $message->setRecipient_Type($classes[1]); $message->setCreated(time()); + $message->setUnread(1); $message->save(); + DatabaseConnection::i()->getConnection()->query("UPDATE messages SET unread = 0 WHERE sender_id = ".$this->correspondents[1]->getId()); + # да if($ids[0] !== $ids[1]) { $event = new NewMessageEvent($message); diff --git a/Web/Models/Entities/Message.php b/Web/Models/Entities/Message.php index 7a95af2f..f4fcc9af 100644 --- a/Web/Models/Entities/Message.php +++ b/Web/Models/Entities/Message.php @@ -1,5 +1,6 @@ get($this->getRecord()->recipient_id); } + function getUnreadState(): int + { + trigger_error("TODO: use isUnread", E_USER_DEPRECATED); + + return (int) $this->isUnread(); + } + /** * Get date of initial publication. * @@ -78,6 +86,11 @@ class Message extends RowModel return false; } + function isUnread(): bool + { + return (bool) $this->getRecord()->unread; + } + /** * Simplify to array * @@ -109,13 +122,14 @@ class Message extends RowModel "id" => $author->getId(), "link" => $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $author->getURL(), "avatar" => $author->getAvatarUrl(), - "name" => $author->getFirstName(), + "name" => $author->getFirstName().$unreadmsg, ], "timing" => [ "sent" => (string) $this->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X"), "edited" => is_null($this->getEditTime()) ? null : (string) $this->getEditTime(), ], "text" => $this->getText(), + "read" => !$this->isUnread(), "attachments" => $attachments, ]; } diff --git a/Web/Presenters/templates/Messenger/App.xml b/Web/Presenters/templates/Messenger/App.xml index 67c4f3e4..afd464cc 100644 --- a/Web/Presenters/templates/Messenger/App.xml +++ b/Web/Presenters/templates/Messenger/App.xml @@ -19,7 +19,7 @@