]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Friendica/Notification.php
Use the owner, not the author
[friendica.git] / src / Object / Api / Friendica / Notification.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Friendica;
23
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Content\Text\BBCode;
26 use Friendica\Content\Text\HTML;
27 use Friendica\Navigation\Notifications\Entity\Notify;
28 use Friendica\Util\DateTimeFormat;
29 use Friendica\Util\Temporal;
30
31 /**
32  * Friendica Notification
33  *
34  * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
35  */
36 class Notification extends BaseDataTransferObject
37 {
38         /** @var integer */
39         protected $id;
40         /** @var integer */
41         protected $type;
42         /** @var string Full name of the contact subject */
43         protected $name;
44         /** @var string Profile page URL of the contact subject */
45         protected $url;
46         /** @var string Profile photo URL of the contact subject */
47         protected $photo;
48         /** @var string YYYY-MM-DD hh:mm:ss local server time */
49         protected $date;
50         /** @var string The message (BBCode) */
51         protected $msg;
52         /** @var integer Owner User Id */
53         protected $uid;
54         /** @var string Notification URL */
55         protected $link;
56         /** @var integer Item Id */
57         protected $iid;
58         /** @var integer Parent Item Id */
59         protected $parent;
60         /** @var boolean  Whether the notification was read or not. */
61         protected $seen;
62         /** @var string Verb URL @see http://activitystrea.ms */
63         protected $verb;
64         /** @var string Subject type ('item', 'intro' or 'mail') */
65         protected $otype;
66         /** @var string Full name of the contact subject (HTML) */
67         protected $name_cache;
68         /** @var string Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name. (Plaintext) */
69         protected $msg_cache;
70         /** @var integer  Unix timestamp */
71         protected $timestamp;
72         /** @var string Time since the note was posted, eg "1 hour ago" */
73         protected $date_rel;
74         /** @var string Message (HTML) */
75         protected $msg_html;
76         /** @var string Message (Plaintext) */
77         protected $msg_plain;
78
79         public function __construct(Notify $Notify)
80         {
81                 $this->id         = $Notify->id;
82                 $this->type       = $Notify->type;
83                 $this->name       = $Notify->name;
84                 $this->url        = $Notify->url->__toString();
85                 $this->photo      = $Notify->photo->__toString();
86                 $this->date       = DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL));
87                 $this->msg        = $Notify->msg;
88                 $this->uid        = $Notify->uid;
89                 $this->link       = $Notify->link->__toString();
90                 $this->iid        = $Notify->itemId;
91                 $this->parent     = $Notify->parent;
92                 $this->seen       = $Notify->seen;
93                 $this->verb       = $Notify->verb;
94                 $this->otype      = $Notify->otype;
95                 $this->name_cache = $Notify->name_cache;
96                 $this->msg_cache  = $Notify->msg_cache;
97                 $this->timestamp  = $Notify->date->format('U');
98                 $this->date_rel   = Temporal::getRelativeDate($this->date);
99
100                 try {
101                         $this->msg_html  = BBCode::convertForUriId($Notify->uriId, $this->msg, BBCode::EXTERNAL);
102                 } catch (\Exception $e) {
103                         $this->msg_html  = '';
104                 }
105
106                 try {
107                         $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
108                 } catch (\Exception $e) {
109                         $this->msg_plain  = '';
110                 }
111         }
112 }