3 * @copyright Copyright (C) 2010-2022, 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\Navigation\Notifications\Entity;
25 use Friendica\BaseEntity;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Renderer;
28 use Psr\Http\Message\UriInterface;
31 * @property-read $type
32 * @property-read $name
34 * @property-read $photo
35 * @property-read $date
38 * @property-read $link
39 * @property-read $itemId
40 * @property-read $parent
41 * @property-read $seen
42 * @property-read $verb
43 * @property-read $otype
44 * @property-read $name_cache
45 * @property-read $msg_cache
46 * @property-read $uriId
47 * @property-read $parentUriId
50 class Notify extends BaseEntity
56 /** @var UriInterface */
58 /** @var UriInterface */
66 /** @var UriInterface */
79 protected $name_cache;
85 protected $parentUriId;
89 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)
94 $this->photo = $photo;
99 $this->itemId = $itemId;
100 $this->parent = $parent;
103 $this->otype = $otype;
104 $this->name_cache = $name_cache;
105 $this->msg_cache = $msg_cache;
106 $this->uriId = $uriId;
107 $this->parentUriId = $parentUriId;
111 public function setSeen()
116 public function updateMsgFromPreamble($epreamble)
118 $this->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
119 $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
123 * Formats a notification message with the notification author
125 * Replace the name with {0} but ensure to make that only once. The {0} is used
126 * later and prints the name in bold.
128 * @param string $name
129 * @param string $message
131 * @return string Formatted message
133 public static function formatMessage(string $name, string $message): string
136 $pos = strpos($message, $name);
141 if ($pos !== false) {
142 $message = substr_replace($message, '{0}', $pos, strlen($name));