3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Object\Api\Friendica;
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;
32 * Friendica Notification
34 * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
36 class Notification extends BaseDataTransferObject
42 /** @var string Full name of the contact subject */
44 /** @var string Profile page URL of the contact subject */
46 /** @var string Profile photo URL of the contact subject */
48 /** @var string YYYY-MM-DD hh:mm:ss local server time */
50 /** @var string The message (BBCode) */
52 /** @var integer Owner User Id */
54 /** @var string Notification URL */
56 /** @var integer Item Id */
58 /** @var integer Parent Item Id */
60 /** @var boolean Whether the notification was read or not. */
62 /** @var string Verb URL @see http://activitystrea.ms */
64 /** @var string Subject type ('item', 'intro' or 'mail') */
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) */
70 /** @var integer Unix timestamp */
72 /** @var string Time since the note was posted, eg "1 hour ago" */
74 /** @var string Message (HTML) */
76 /** @var string Message (Plaintext) */
79 public function __construct(Notify $Notify)
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);
101 $this->msg_html = BBCode::convert($this->msg, false);
102 } catch (\Exception $e) {
103 $this->msg_html = '';
107 $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
108 } catch (\Exception $e) {
109 $this->msg_plain = '';