]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Api/Friendica/Notification.php
Use the owner, not the author
[friendica.git] / src / Object / Api / Friendica / Notification.php
index 910d5ec682dc73ad411589c9f73c9dc89f55c0cd..df59bb6b8ca8796fdee13e770ca0419e47bd1fb3 100644 (file)
@@ -1,11 +1,30 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Object\Api\Friendica;
 
-use Friendica\BaseEntity;
+use Friendica\BaseDataTransferObject;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Model\Notify;
+use Friendica\Navigation\Notifications\Entity\Notify;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Temporal;
 
@@ -14,12 +33,10 @@ use Friendica\Util\Temporal;
  *
  * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
  */
-class Notification extends BaseEntity
+class Notification extends BaseDataTransferObject
 {
        /** @var integer */
        protected $id;
-       /** @var string */
-       protected $hash;
        /** @var integer */
        protected $type;
        /** @var string Full name of the contact subject */
@@ -44,7 +61,7 @@ class Notification extends BaseEntity
        protected $seen;
        /** @var string Verb URL @see http://activitystrea.ms */
        protected $verb;
-       /** @var string Subject type (`item`, `intro` or `mail`) */
+       /** @var string Subject type ('item', 'intro' or 'mail') */
        protected $otype;
        /** @var string Full name of the contact subject (HTML) */
        protected $name_cache;
@@ -59,21 +76,37 @@ class Notification extends BaseEntity
        /** @var string Message (Plaintext) */
        protected $msg_plain;
 
-       public function __construct(Notify $notify)
+       public function __construct(Notify $Notify)
        {
-               // map each notify attribute to the entity
-               foreach ($notify->toArray() as $key => $value) {
-                       $this->{$key} = $value;
+               $this->id         = $Notify->id;
+               $this->type       = $Notify->type;
+               $this->name       = $Notify->name;
+               $this->url        = $Notify->url->__toString();
+               $this->photo      = $Notify->photo->__toString();
+               $this->date       = DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL));
+               $this->msg        = $Notify->msg;
+               $this->uid        = $Notify->uid;
+               $this->link       = $Notify->link->__toString();
+               $this->iid        = $Notify->itemId;
+               $this->parent     = $Notify->parent;
+               $this->seen       = $Notify->seen;
+               $this->verb       = $Notify->verb;
+               $this->otype      = $Notify->otype;
+               $this->name_cache = $Notify->name_cache;
+               $this->msg_cache  = $Notify->msg_cache;
+               $this->timestamp  = $Notify->date->format('U');
+               $this->date_rel   = Temporal::getRelativeDate($this->date);
+
+               try {
+                       $this->msg_html  = BBCode::convertForUriId($Notify->uriId, $this->msg, BBCode::EXTERNAL);
+               } catch (\Exception $e) {
+                       $this->msg_html  = '';
                }
 
-               // add additional attributes for the API
                try {
-                       $this->timestamp = strtotime(DateTimeFormat::local($this->date));
-                       $this->msg_html  = BBCode::convert($this->msg, false);
                        $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
                } catch (\Exception $e) {
+                       $this->msg_plain  = '';
                }
-
-               $this->date_rel = Temporal::getRelativeDate($this->date);
        }
 }