3 * @copyright Copyright (C) 2020, Friendica
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\Model\Notification as NotificationModel;
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
44 /** @var string Full name of the contact subject */
46 /** @var string Profile page URL of the contact subject */
48 /** @var string Profile photo URL of the contact subject */
50 /** @var string YYYY-MM-DD hh:mm:ss local server time */
52 /** @var string The message (BBCode) */
54 /** @var integer Owner User Id */
56 /** @var string Notification URL */
58 /** @var integer Item Id */
60 /** @var integer Parent Item Id */
62 /** @var boolean Whether the notification was read or not. */
64 /** @var string Verb URL @see http://activitystrea.ms */
66 /** @var string Subject type ('item', 'intro' or 'mail') */
68 /** @var string Full name of the contact subject (HTML) */
69 protected $name_cache;
70 /** @var string Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name. (Plaintext) */
72 /** @var integer Unix timestamp */
74 /** @var string Time since the note was posted, eg "1 hour ago" */
76 /** @var string Message (HTML) */
78 /** @var string Message (Plaintext) */
81 public function __construct(NotificationModel $notify)
83 // map each notify attribute to the entity
84 foreach ($notify->toArray() as $key => $value) {
85 $this->{$key} = $value;
88 // add additional attributes for the API
90 $this->timestamp = strtotime(DateTimeFormat::local($this->date));
91 $this->msg_html = BBCode::convert($this->msg, false);
92 $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
93 } catch (\Exception $e) {
96 $this->date_rel = Temporal::getRelativeDate($this->date);