3 namespace Friendica\Object\Api\Friendica;
5 use Friendica\BaseEntity;
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Content\Text\HTML;
8 use Friendica\Model\Notify;
9 use Friendica\Util\DateTimeFormat;
10 use Friendica\Util\Temporal;
13 * Friendica Notification
15 * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
17 class Notification extends BaseEntity
25 /** @var string Full name of the contact subject */
27 /** @var string Profile page URL of the contact subject */
29 /** @var string Profile photo URL of the contact subject */
31 /** @var string YYYY-MM-DD hh:mm:ss local server time */
33 /** @var string The message (BBCode) */
35 /** @var integer Owner User Id */
37 /** @var string Notification URL */
39 /** @var integer Item Id */
41 /** @var integer Parent Item Id */
43 /** @var boolean Whether the notification was read or not. */
45 /** @var string Verb URL @see http://activitystrea.ms */
47 /** @var string Subject type (`item`, `intro` or `mail`) */
49 /** @var string Full name of the contact subject (HTML) */
50 protected $name_cache;
51 /** @var string Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name. (Plaintext) */
53 /** @var integer Unix timestamp */
55 /** @var string Time since the note was posted, eg "1 hour ago" */
57 /** @var string Message (HTML) */
59 /** @var string Message (Plaintext) */
62 public function __construct(Notify $notify)
64 // map each notify attribute to the entity
65 foreach ($notify->toArray() as $key => $value) {
66 $this->{$key} = $value;
69 // add additional attributes for the API
71 $this->timestamp = strtotime(DateTimeFormat::local($this->date));
72 $this->msg_html = BBCode::convert($this->msg, false);
73 $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
74 } catch (\Exception $e) {
77 $this->date_rel = Temporal::getRelativeDate($this->date);