3 namespace Friendica\Navigation\Notifications\Entity;
6 use Friendica\BaseEntity;
7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\Renderer;
9 use Psr\Http\Message\UriInterface;
12 * @property-read $type
13 * @property-read $name
15 * @property-read $photo
16 * @property-read $date
19 * @property-read $link
20 * @property-read $itemId
21 * @property-read $parent
22 * @property-read $seen
23 * @property-read $verb
24 * @property-read $otype
25 * @property-read $name_cache
26 * @property-read $msg_cache
27 * @property-read $uriId
28 * @property-read $parentUriId
31 class Notify extends BaseEntity
37 /** @var UriInterface */
39 /** @var UriInterface */
47 /** @var UriInterface */
60 protected $name_cache;
66 protected $parentUriId;
70 public function __construct(int $type, string $name, UriInterface $url, UriInterface $photo, DateTime $date, int $uid, UriInterface $link, bool $seen, string $verb, string $otype, string $name_cache, string $msg = null, string $msg_cache = null, int $itemId = null, int $uriId = null, int $parent = null, int $parentUriId = null, int $id = null)
75 $this->photo = $photo;
80 $this->itemId = $itemId;
81 $this->parent = $parent;
84 $this->otype = $otype;
85 $this->name_cache = $name_cache;
86 $this->msg_cache = $msg_cache;
87 $this->uriId = $uriId;
88 $this->parentUriId = $parentUriId;
92 public function setSeen()
97 public function updateMsgFromPreamble($epreamble)
99 $this->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
100 $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
104 * Formats a notification message with the notification author
106 * Replace the name with {0} but ensure to make that only once. The {0} is used
107 * later and prints the name in bold.
109 * @param string $name
110 * @param string $message
112 * @return string Formatted message
114 public static function formatMessage(string $name, string $message): string
117 $pos = strpos($message, $name);
122 if ($pos !== false) {
123 $message = substr_replace($message, '{0}', $pos, strlen($name));