diff --git a/Web/Models/Entities/Message.php b/Web/Models/Entities/Message.php index e9e0fb7a..ec8e7c74 100644 --- a/Web/Models/Entities/Message.php +++ b/Web/Models/Entities/Message.php @@ -2,6 +2,7 @@ namespace openvk\Web\Models\Entities; use openvk\Web\Models\Repositories\Clubs; use openvk\Web\Models\Repositories\Users; +use openvk\Web\Models\Entities\Photo; use openvk\Web\Models\RowModel; use openvk\Web\Util\DateTime; @@ -86,6 +87,22 @@ class Message extends RowModel { $author = $this->getSender(); + $attachments = []; + foreach($this->getChildren() as $attachment) { + if($attachment instanceof Photo) { + $attachments[] = [ + "type" => "photo", + "link" => "/photo" . $attachment->getPrettyId(), + "photo" => [ + "url" => $attachment->getURL(), + "caption" => $attachment->getDescription(), + ], + ]; + } else { + throw new \Exception("Unknown attachment type: " . get_class($attachment)); + } + } + return [ "uuid" => $this->getId(), "sender" => [ @@ -98,9 +115,11 @@ class Message extends RowModel "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(), + "text" => $this->getText(), + "attachments" => $attachments, ]; } use Traits\TRichText; + use Traits\TAttachmentHost; } diff --git a/Web/Models/Entities/Traits/TAttachmentHost.php b/Web/Models/Entities/Traits/TAttachmentHost.php index 61bf487c..cbe7cad2 100644 --- a/Web/Models/Entities/Traits/TAttachmentHost.php +++ b/Web/Models/Entities/Traits/TAttachmentHost.php @@ -17,9 +17,10 @@ trait TAttachmentHost function getChildren(): \Traversable { - $sel = $this->getRecord() - ->related("attachments.target_id") - ->where("attachments.target_type", get_class($this)); + $sel = DatabaseConnection::i()->getContext() + ->table("attachments") + ->where("target_id", $this->getId()) + ->where("attachments.target_type", get_class($this)); foreach($sel as $rel) { $repoName = $rel->attachable_type . "s"; $repoName = str_replace("Entities", "Repositories", $repoName); diff --git a/Web/Presenters/templates/Messenger/App.xml b/Web/Presenters/templates/Messenger/App.xml index 44082dac..3cdfa450 100644 --- a/Web/Presenters/templates/Messenger/App.xml +++ b/Web/Presenters/templates/Messenger/App.xml @@ -23,12 +23,21 @@
- Целестина Неонова {* lulz *} + - ... + +
+
+
+ + + +
+
+
- Monday, the 1st of January 1970 00:00:00 +
@@ -171,6 +180,7 @@ "edited": null }, "text": content, + "attachments": [], "_tuid": Math.ceil(performance.now()) }; } diff --git a/Web/static/css/style.css b/Web/static/css/style.css index 88d84cf6..25f59468 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -845,6 +845,18 @@ table.User { overflow: hidden; } +.messenger-app--messages---message ._content .attachments { + width: 100%; +} + +.messenger-app--messages---message ._content .attachments > .msg-attach-j * { + max-width: 86%; +} + +.messenger-app--messages---message ._content .attachments:not(:empty) { + margin-top: 15px; +} + .messenger-app--messages---message .time { width: 100px; }