mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Unread messages stub
This commit is contained in:
parent
1d46bbb6d6
commit
080e918f11
6 changed files with 81 additions and 22 deletions
|
@ -57,6 +57,14 @@ class Correspondence
|
||||||
return "/im?sel=$id";
|
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.
|
* 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]);
|
$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)) {
|
if(is_null($cap)) {
|
||||||
$query = str_replace("\n AND (`id` > ?)", "", $query);
|
$query = str_replace("\n AND (`id` > ?)", "", $query);
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,8 +161,11 @@ class Correspondence
|
||||||
$message->setSender_Type($classes[0]);
|
$message->setSender_Type($classes[0]);
|
||||||
$message->setRecipient_Type($classes[1]);
|
$message->setRecipient_Type($classes[1]);
|
||||||
$message->setCreated(time());
|
$message->setCreated(time());
|
||||||
|
$message->setUnread(1);
|
||||||
$message->save();
|
$message->save();
|
||||||
|
|
||||||
|
DatabaseConnection::i()->getConnection()->query("UPDATE messages SET unread = 0 WHERE sender_id = ".$this->correspondents[1]->getId());
|
||||||
|
|
||||||
# да
|
# да
|
||||||
if($ids[0] !== $ids[1]) {
|
if($ids[0] !== $ids[1]) {
|
||||||
$event = new NewMessageEvent($message);
|
$event = new NewMessageEvent($message);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Entities;
|
namespace openvk\Web\Models\Entities;
|
||||||
|
use Chandler\Database\DatabaseConnection;
|
||||||
use openvk\Web\Models\Repositories\Clubs;
|
use openvk\Web\Models\Repositories\Clubs;
|
||||||
use openvk\Web\Models\Repositories\Users;
|
use openvk\Web\Models\Repositories\Users;
|
||||||
use openvk\Web\Models\Entities\Photo;
|
use openvk\Web\Models\Entities\Photo;
|
||||||
|
@ -43,6 +44,13 @@ class Message extends RowModel
|
||||||
return (new Clubs)->get($this->getRecord()->recipient_id);
|
return (new Clubs)->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.
|
* Get date of initial publication.
|
||||||
*
|
*
|
||||||
|
@ -78,6 +86,11 @@ class Message extends RowModel
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isUnread(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getRecord()->unread;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplify to array
|
* Simplify to array
|
||||||
*
|
*
|
||||||
|
@ -109,13 +122,14 @@ class Message extends RowModel
|
||||||
"id" => $author->getId(),
|
"id" => $author->getId(),
|
||||||
"link" => $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $author->getURL(),
|
"link" => $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['HTTP_HOST'] . $author->getURL(),
|
||||||
"avatar" => $author->getAvatarUrl(),
|
"avatar" => $author->getAvatarUrl(),
|
||||||
"name" => $author->getFirstName(),
|
"name" => $author->getFirstName().$unreadmsg,
|
||||||
],
|
],
|
||||||
"timing" => [
|
"timing" => [
|
||||||
"sent" => (string) $this->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X"),
|
"sent" => (string) $this->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X"),
|
||||||
"edited" => is_null($this->getEditTime()) ? null : (string) $this->getEditTime(),
|
"edited" => is_null($this->getEditTime()) ? null : (string) $this->getEditTime(),
|
||||||
],
|
],
|
||||||
"text" => $this->getText(),
|
"text" => $this->getText(),
|
||||||
|
"read" => !$this->isUnread(),
|
||||||
"attachments" => $attachments,
|
"attachments" => $attachments,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<div class="messenger-app">
|
<div class="messenger-app">
|
||||||
<div class="messenger-app--messages" data-bind="event: { scroll: onMessagesScroll }">
|
<div class="messenger-app--messages" data-bind="event: { scroll: onMessagesScroll }">
|
||||||
<div data-bind="foreach: messages">
|
<div data-bind="foreach: messages">
|
||||||
<div class="messenger-app--messages---message">
|
<div class="messenger-app--messages---message" data-bind="css: { unread: !read }">
|
||||||
<img class="ava" data-bind="attr: { src: sender.avatar, alt: sender.name }" />
|
<img class="ava" data-bind="attr: { src: sender.avatar, alt: sender.name }" />
|
||||||
<div class="_content">
|
<div class="_content">
|
||||||
<a href="#" data-bind="attr: { href: sender.link }">
|
<a href="#" data-bind="attr: { href: sender.link }">
|
||||||
|
@ -188,6 +188,7 @@
|
||||||
"edited": null
|
"edited": null
|
||||||
},
|
},
|
||||||
"text": content,
|
"text": content,
|
||||||
|
"read": false,
|
||||||
"attachments": [],
|
"attachments": [],
|
||||||
"_tuid": Math.ceil(performance.now())
|
"_tuid": Math.ceil(performance.now())
|
||||||
};
|
};
|
||||||
|
@ -205,6 +206,7 @@
|
||||||
"edited": null
|
"edited": null
|
||||||
},
|
},
|
||||||
"text": content,
|
"text": content,
|
||||||
|
"read": true,
|
||||||
"_tuid": Math.ceil(performance.now())
|
"_tuid": Math.ceil(performance.now())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,10 @@
|
||||||
<a href="{$recipient->getURL()}">{$recipient->getCanonicalName()}</a><br/>
|
<a href="{$recipient->getURL()}">{$recipient->getCanonicalName()}</a><br/>
|
||||||
<span>{$lastMsg->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X")}</span>
|
<span>{$lastMsg->getSendTime()->format("%e %B %G" . tr("time_at_sp") . "%X")}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="crp-entry--message">
|
<div n:class="crp-entry--message, $lastMsg->getUnreadState() ? unread">
|
||||||
{var _author = $lastMsg->getSender()}
|
{var _author = $lastMsg->getSender()}
|
||||||
|
|
||||||
<div class="crp-entry--message---av">
|
<div class="crp-entry--message---av" n:if="$_author->getId() === $thisUser->getId()">
|
||||||
<img src="{$_author->getAvatarURL()}"
|
<img src="{$_author->getAvatarURL()}"
|
||||||
alt="Фотография пользователя" />
|
alt="Фотография пользователя" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,15 +22,15 @@ div.content > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth
|
||||||
|
|
||||||
.crp-entry--image > img
|
.crp-entry--image > img
|
||||||
{
|
{
|
||||||
width: 64px;
|
width: 48px;
|
||||||
height: 64px;
|
height: 48px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
.crp-entry--message---av > img,
|
.crp-entry--message---av > img,
|
||||||
.ava
|
.ava
|
||||||
{
|
{
|
||||||
width: 46px;
|
width: 42px;
|
||||||
height: 46px;
|
height: 42px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
}
|
}
|
||||||
|
|
|
@ -714,7 +714,7 @@ table.User {
|
||||||
}
|
}
|
||||||
|
|
||||||
.crp-list {
|
.crp-list {
|
||||||
margin: 10px -6px 0 -11px;
|
margin: 10px -6px -10px -11px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
border-top: 1px solid #d6d6d6;
|
border-top: 1px solid #d6d6d6;
|
||||||
|
@ -726,10 +726,18 @@ table.User {
|
||||||
.crp-entry {
|
.crp-entry {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border-bottom: 1px solid #d6d6d6;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 592px;
|
width: 611px;
|
||||||
margin-left: 1px;
|
margin-left: 1px;
|
||||||
|
border-bottom: 1px solid #d6d6d6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crp-entry:hover {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.crp-entry:first-of-type {
|
||||||
|
border-top: 1px solid #d6d6d6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.crp-entry--image, .crp-entry--info {
|
.crp-entry--image, .crp-entry--info {
|
||||||
|
@ -744,14 +752,6 @@ margin-left: 1px;
|
||||||
max-width: 64px;
|
max-width: 64px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.crp-entry:hover {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
|
|
||||||
width: 592px;
|
|
||||||
|
|
||||||
margin-left: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.crp-entry--info span {
|
.crp-entry--info span {
|
||||||
color: grey;
|
color: grey;
|
||||||
}
|
}
|
||||||
|
@ -760,6 +760,35 @@ margin-left: 1px;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.crp-entry--message.unread {
|
||||||
|
background-color: #dcdcdc;
|
||||||
|
padding: 5px;
|
||||||
|
width: 346px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messenger-app--messages---message.unread {
|
||||||
|
background-color: #dcdcdc;
|
||||||
|
padding: 5px;
|
||||||
|
margin: -5px;
|
||||||
|
padding-bottom: 1.2rem;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messenger-app--messages---message.unread:first-of-type {
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-top-right-radius: 3px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
margin-bottom: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.messenger-app--messages---message.unread:last-of-type {
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
border-bottom-right-radius: 3px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
margin-bottom: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
.crp-entry--message---av img {
|
.crp-entry--message---av img {
|
||||||
max-width: 42px;
|
max-width: 42px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue