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 use Friendica\Content\Text\BBCode;
23 use Friendica\Core\Hook;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\System;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Item;
30 use Friendica\Model\ItemContent;
31 use Friendica\Model\Notify;
32 use Friendica\Model\User;
33 use Friendica\Model\UserItem;
34 use Friendica\Protocol\Activity;
37 * Creates a notification entry and possibly sends a mail
39 * @param array $params Array with the elements:
40 * uid, item, parent, type, otype, verb, event,
41 * link, subject, body, to_name, to_email, source_name,
42 * source_link, activity, preamble, notify_flags,
43 * language, show_in_notification_page
45 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
47 function notification($params)
49 /** @var string the common prefix of a notification subject */
50 $subjectPrefix = DI::l10n()->t('[Friendica:Notify]');
52 // Temporary logging for finding the origin
53 if (!isset($params['uid'])) {
54 Logger::notice('Missing parameters "uid".', ['params' => $params, 'callstack' => System::callstack()]);
57 // Ensure that the important fields are set at any time
58 $fields = ['notify-flags', 'language', 'username', 'email'];
59 $user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]);
61 if (!DBA::isResult($user)) {
62 Logger::error('Unknown user', ['uid' => $params['uid']]);
66 $params['notify_flags'] = ($params['notify_flags'] ?? '') ?: $user['notify-flags'];
67 $params['language'] = ($params['language'] ?? '') ?: $user['language'];
68 $params['to_name'] = ($params['to_name'] ?? '') ?: $user['username'];
69 $params['to_email'] = ($params['to_email'] ?? '') ?: $user['email'];
71 // from here on everything is in the recipients language
72 $l10n = DI::l10n()->withLang($params['language']);
74 $siteurl = DI::baseUrl()->get(true);
75 $sitename = DI::config()->get('config', 'sitename');
77 $hostname = DI::baseUrl()->getHostname();
78 if (strpos($hostname, ':')) {
79 $hostname = substr($hostname, 0, strpos($hostname, ':'));
82 $user = User::getById($params['uid'], ['nickname', 'page-flags']);
84 // There is no need to create notifications for forum accounts
85 if (!DBA::isResult($user) || in_array($user["page-flags"], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
88 $nickname = $user["nickname"];
90 // with $params['show_in_notification_page'] == false, the notification isn't inserted into
91 // the database, and an email is sent if applicable.
92 // default, if not specified: true
93 $show_in_notification_page = isset($params['show_in_notification_page']) ? $params['show_in_notification_page'] : true;
95 $additional_mail_header = "X-Friendica-Account: <".$nickname."@".$hostname.">\n";
97 if (array_key_exists('item', $params)) {
98 $title = $params['item']['title'];
99 $body = $params['item']['body'];
104 if (isset($params['item']['id'])) {
105 $item_id = $params['item']['id'];
110 if (isset($params['item']['uri-id'])) {
111 $uri_id = $params['item']['uri-id'];
116 if (isset($params['parent'])) {
117 $parent_id = $params['parent'];
122 if (isset($params['item']['parent-uri-id'])) {
123 $parent_uri_id = $params['item']['parent-uri-id'];
136 if ($params['type'] == Notify\Type::MAIL) {
137 $itemlink = $siteurl.'/message/'.$params['item']['id'];
138 $params["link"] = $itemlink;
140 $subject = $l10n->t('%s New mail received at %s', $subjectPrefix, $sitename);
142 $preamble = $l10n->t('%1$s sent you a new private message at %2$s.', $params['source_name'], $sitename);
143 $epreamble = $l10n->t('%1$s sent you %2$s.', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]', '[url=' . $itemlink . ']' . $l10n->t('a private message').'[/url]');
145 $sitelink = $l10n->t('Please visit %s to view and/or reply to your private messages.');
146 $tsitelink = sprintf($sitelink, $siteurl.'/message/'.$params['item']['id']);
147 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'/message/'.$params['item']['id'].'">'.$sitename.'</a>');
150 if ($params['type'] == Notify\Type::COMMENT || $params['type'] == Notify\Type::TAG_SELF) {
151 $thread = Item::selectFirstThreadForUser($params['uid'], ['ignored'], ['iid' => $parent_id, 'deleted' => false]);
152 if (DBA::isResult($thread) && $thread['ignored']) {
153 Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG);
157 // Check to see if there was already a tag notify or comment notify for this post.
158 // If so don't create a second notification
159 /// @todo In the future we should store the notification with the highest "value" and replace notifications
160 $condition = ['type' => [Notify\Type::TAG_SELF, Notify\Type::COMMENT, Notify\Type::SHARE],
161 'link' => $params['link'], 'uid' => $params['uid']];
162 if (DBA::exists('notify', $condition)) {
166 // if it's a post figure out who's post it is.
168 if ($params['otype'] === Notify\ObjectType::ITEM && $parent_id) {
169 $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]);
176 $item_post_type = Item::postType($item);
178 $content = ItemContent::getPlaintextPost($item, 70);
179 if (!empty($content['text'])) {
180 $title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
185 // First go for the general message
187 // "George Bull's post"
188 if ($params['activity']['origin_comment']) {
189 $message = $l10n->t('%1$s replied to you on %2$s\'s %3$s %4$s');
190 } elseif ($params['activity']['explicit_tagged']) {
191 $message = $l10n->t('%1$s tagged you on %2$s\'s %3$s %4$s');
193 $message = $l10n->t('%1$s commented on %2$s\'s %3$s %4$s');
196 $dest_str = sprintf($message, $params['source_name'], $item['author-name'], $item_post_type, $title);
198 // Then look for the special cases
201 if ($params['activity']['origin_thread']) {
202 if ($params['activity']['origin_comment']) {
203 $message = $l10n->t('%1$s replied to you on your %2$s %3$s');
204 } elseif ($params['activity']['explicit_tagged']) {
205 $message = $l10n->t('%1$s tagged you on your %2$s %3$s');
207 $message = $l10n->t('%1$s commented on your %2$s %3$s');
210 $dest_str = sprintf($message, $params['source_name'], $item_post_type, $title);
212 } elseif ($item['author-link'] == $params['source_link']) {
213 if ($params['activity']['origin_comment']) {
214 $message = $l10n->t('%1$s replied to you on their %2$s %3$s');
215 } elseif ($params['activity']['explicit_tagged']) {
216 $message = $l10n->t('%1$s tagged you on their %2$s %3$s');
218 $message = $l10n->t('%1$s commented on their %2$s %3$s');
221 $dest_str = sprintf($message, $params['source_name'], $item_post_type, $title);
224 // Some mail software relies on subject field for threading.
225 // So, we cannot have different subjects for notifications of the same thread.
226 // Before this we have the name of the replier on the subject rendering
227 // different subjects for messages on the same thread.
228 if ($params['activity']['explicit_tagged']) {
229 $subject = $l10n->t('%s %s tagged you', $subjectPrefix, $params['source_name']);
231 $preamble = $l10n->t('%1$s tagged you at %2$s', $params['source_name'], $sitename);
233 $subject = $l10n->t('%1$s Comment to conversation #%2$d by %3$s', $subjectPrefix, $parent_id, $params['source_name']);
235 $preamble = $l10n->t('%s commented on an item/conversation you have been following.', $params['source_name']);
238 $epreamble = $dest_str;
240 $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
241 $tsitelink = sprintf($sitelink, $siteurl);
242 $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
243 $itemlink = $params['link'];
246 if ($params['type'] == Notify\Type::WALL) {
247 $subject = $l10n->t('%s %s posted to your profile wall', $subjectPrefix, $params['source_name']);
249 $preamble = $l10n->t('%1$s posted to your profile wall at %2$s', $params['source_name'], $sitename);
250 $epreamble = $l10n->t('%1$s posted to [url=%2$s]your wall[/url]',
251 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
255 $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
256 $tsitelink = sprintf($sitelink, $siteurl);
257 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
258 $itemlink = $params['link'];
261 if ($params['type'] == Notify\Type::SHARE) {
262 if ($params['origin_link'] == $params['source_link']) {
263 $subject = $l10n->t('%s %s shared a new post', $subjectPrefix, $params['source_name']);
265 $preamble = $l10n->t('%1$s shared a new post at %2$s', $params['source_name'], $sitename);
266 $epreamble = $l10n->t('%1$s [url=%2$s]shared a post[/url].',
267 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
271 $subject = $l10n->t('%s %s shared a post from %s', $subjectPrefix, $params['source_name'], $params['origin_name']);
273 $preamble = $l10n->t('%1$s shared a post from %2$s at %3$s', $params['source_name'], $params['origin_name'], $sitename);
274 $epreamble = $l10n->t('%1$s [url=%2$s]shared a post[/url] from %3$s.',
275 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
276 $params['link'], '[url='.$params['origin_link'].']'.$params['origin_name'].'[/url]'
280 $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
281 $tsitelink = sprintf($sitelink, $siteurl);
282 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
283 $itemlink = $params['link'];
286 if ($params['type'] == Notify\Type::POKE) {
287 $subject = $l10n->t('%1$s %2$s poked you', $subjectPrefix, $params['source_name']);
289 $preamble = $l10n->t('%1$s poked you at %2$s', $params['source_name'], $sitename);
290 $epreamble = $l10n->t('%1$s [url=%2$s]poked you[/url].',
291 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
295 $subject = str_replace('poked', $l10n->t($params['activity']), $subject);
296 $preamble = str_replace('poked', $l10n->t($params['activity']), $preamble);
297 $epreamble = str_replace('poked', $l10n->t($params['activity']), $epreamble);
299 $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
300 $tsitelink = sprintf($sitelink, $siteurl);
301 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
302 $itemlink = $params['link'];
305 if ($params['type'] == Notify\Type::TAG_SHARE) {
306 $itemlink = $params['link'];
307 $subject = $l10n->t('%s %s tagged your post', $subjectPrefix, $params['source_name']);
309 $preamble = $l10n->t('%1$s tagged your post at %2$s', $params['source_name'], $sitename);
310 $epreamble = $l10n->t('%1$s tagged [url=%2$s]your post[/url]',
311 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
315 $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.');
316 $tsitelink = sprintf($sitelink, $siteurl);
317 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
320 if ($params['type'] == Notify\Type::INTRO) {
321 $itemlink = $params['link'];
322 $subject = $l10n->t('%s Introduction received', $subjectPrefix);
324 $preamble = $l10n->t('You\'ve received an introduction from \'%1$s\' at %2$s', $params['source_name'], $sitename);
325 $epreamble = $l10n->t('You\'ve received [url=%1$s]an introduction[/url] from %2$s.',
327 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
330 $body = $l10n->t('You may visit their profile at %s', $params['source_link']);
332 $sitelink = $l10n->t('Please visit %s to approve or reject the introduction.');
333 $tsitelink = sprintf($sitelink, $siteurl);
334 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
336 switch ($params['verb']) {
337 case Activity::FRIEND:
338 // someone started to share with user (mostly OStatus)
339 $subject = $l10n->t('%s A new person is sharing with you', $subjectPrefix);
341 $preamble = $l10n->t('%1$s is sharing with you at %2$s', $params['source_name'], $sitename);
342 $epreamble = $l10n->t('%1$s is sharing with you at %2$s',
343 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
347 case Activity::FOLLOW:
348 // someone started to follow the user (mostly OStatus)
349 $subject = $l10n->t('%s You have a new follower', $subjectPrefix);
351 $preamble = $l10n->t('You have a new follower at %2$s : %1$s', $params['source_name'], $sitename);
352 $epreamble = $l10n->t('You have a new follower at %2$s : %1$s',
353 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
358 // ACTIVITY_REQ_FRIEND is default activity for notifications
363 if ($params['type'] == Notify\Type::SUGGEST) {
364 $itemlink = $params['link'];
365 $subject = $l10n->t('%s Friend suggestion received', $subjectPrefix);
367 $preamble = $l10n->t('You\'ve received a friend suggestion from \'%1$s\' at %2$s', $params['source_name'], $sitename);
368 $epreamble = $l10n->t('You\'ve received [url=%1$s]a friend suggestion[/url] for %2$s from %3$s.',
370 '[url='.$params['item']['url'].']'.$params['item']['name'].'[/url]',
371 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
374 $body = $l10n->t('Name:').' '.$params['item']['name']."\n";
375 $body .= $l10n->t('Photo:').' '.$params['item']['photo']."\n";
376 $body .= $l10n->t('You may visit their profile at %s', $params['item']['url']);
378 $sitelink = $l10n->t('Please visit %s to approve or reject the suggestion.');
379 $tsitelink = sprintf($sitelink, $siteurl);
380 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
383 if ($params['type'] == Notify\Type::CONFIRM) {
384 if ($params['verb'] == Activity::FRIEND) { // mutual connection
385 $itemlink = $params['link'];
386 $subject = $l10n->t('%s Connection accepted', $subjectPrefix);
388 $preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename);
389 $epreamble = $l10n->t('%2$s has accepted your [url=%1$s]connection request[/url].',
391 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
394 $body = $l10n->t('You are now mutual friends and may exchange status updates, photos, and email without restriction.');
396 $sitelink = $l10n->t('Please visit %s if you wish to make any changes to this relationship.');
397 $tsitelink = sprintf($sitelink, $siteurl);
398 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
399 } else { // ACTIVITY_FOLLOW
400 $itemlink = $params['link'];
401 $subject = $l10n->t('%s Connection accepted', $subjectPrefix);
403 $preamble = $l10n->t('\'%1$s\' has accepted your connection request at %2$s', $params['source_name'], $sitename);
404 $epreamble = $l10n->t('%2$s has accepted your [url=%1$s]connection request[/url].',
406 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
409 $body = $l10n->t('\'%1$s\' has chosen to accept you a fan, which restricts some forms of communication - such as private messaging and some profile interactions. If this is a celebrity or community page, these settings were applied automatically.', $params['source_name']);
411 $body .= $l10n->t('\'%1$s\' may choose to extend this into a two-way or more permissive relationship in the future.', $params['source_name']);
413 $sitelink = $l10n->t('Please visit %s if you wish to make any changes to this relationship.');
414 $tsitelink = sprintf($sitelink, $siteurl);
415 $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'">'.$sitename.'</a>');
419 if ($params['type'] == Notify\Type::SYSTEM) {
420 switch($params['event']) {
421 case "SYSTEM_REGISTER_REQUEST":
422 $itemlink = $params['link'];
423 $subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request');
425 $preamble = $l10n->t('You\'ve received a registration request from \'%1$s\' at %2$s', $params['source_name'], $sitename);
426 $epreamble = $l10n->t('You\'ve received a [url=%1$s]registration request[/url] from %2$s.',
428 '[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
431 $body = $l10n->t("Full Name: %s\nSite Location: %s\nLogin Name: %s (%s)",
432 $params['source_name'],
433 $siteurl, $params['source_mail'],
434 $params['source_nick']
437 $sitelink = $l10n->t('Please visit %s to approve or reject the request.');
438 $tsitelink = sprintf($sitelink, $params['link']);
439 $hsitelink = sprintf($sitelink, '<a href="'.$params['link'].'">'.$sitename.'</a><br><br>');
441 case "SYSTEM_DB_UPDATE_FAIL":
446 $subject .= " (".$nickname."@".$hostname.")";
450 'subject' => $subject,
451 'preamble' => $preamble,
452 'epreamble' => $epreamble,
454 'sitelink' => $sitelink,
455 'tsitelink' => $tsitelink,
456 'hsitelink' => $hsitelink,
457 'itemlink' => $itemlink
460 Hook::callAll('enotify', $h);
462 $subject = $h['subject'];
464 $preamble = $h['preamble'];
465 $epreamble = $h['epreamble'];
469 $tsitelink = $h['tsitelink'];
470 $hsitelink = $h['hsitelink'];
471 $itemlink = $h['itemlink'];
475 if ($show_in_notification_page) {
476 $notification = DI::notify()->insert([
477 'name' => $params['source_name'] ?? '',
478 'name_cache' => substr(strip_tags(BBCode::convert($params['source_name'])), 0, 255),
479 'url' => $params['source_link'] ?? '',
480 'photo' => $params['source_photo'] ?? '',
481 'link' => $itemlink ?? '',
482 'uid' => $params['uid'] ?? 0,
485 'parent' => $parent_id,
486 'parent-uri-id' => $parent_uri_id,
487 'type' => $params['type'] ?? '',
488 'verb' => $params['verb'] ?? '',
489 'otype' => $params['otype'] ?? '',
492 // Notification insertion can be intercepted by an addon registering the 'enotify_store' hook
493 if (!$notification) {
497 $notification->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]);
499 DI::notify()->update($notification);
501 $itemlink = DI::baseUrl() . '/notification/' . $notification->id;
502 $notify_id = $notification->id;
505 // send email notification if notification preferences permit
506 if ((intval($params['notify_flags']) & intval($params['type']))
507 || $params['type'] == Notify\Type::SYSTEM) {
509 Logger::log('sending notification email');
511 if (isset($params['parent']) && (intval($params['parent']) != 0)) {
512 $parent = Item::selectFirst(['guid'], ['id' => $params['parent']]);
513 $message_id = "<" . $parent['guid'] . "@" . gethostname() . ">";
515 // Is this the first email notification for this parent item and user?
516 if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) {
517 Logger::log("notify_id:" . intval($notify_id) . ", parent: " . intval($params['parent']) . "uid: " . intval($params['uid']), Logger::DEBUG);
519 $fields = ['notify-id' => $notify_id, 'master-parent-item' => $params['parent'],
520 'master-parent-uri-id' => $parent_uri_id,
521 'receiver-uid' => $params['uid'], 'parent-item' => 0];
522 DBA::insert('notify-threads', $fields);
524 $additional_mail_header .= "Message-ID: " . $message_id . "\n";
525 $log_msg = "include/enotify: No previous notification found for this parent:\n" .
526 " parent: ${params['parent']}\n" . " uid : ${params['uid']}\n";
527 Logger::log($log_msg, Logger::DEBUG);
529 // If not, just "follow" the thread.
530 $additional_mail_header .= "References: " . $message_id . "\nIn-Reply-To: " . $message_id . "\n";
531 Logger::log("There's already a notification for this parent.", Logger::DEBUG);
536 'preamble' => $preamble,
537 'type' => $params['type'],
538 'parent' => $parent_id,
539 'source_name' => $params['source_name'] ?? null,
540 'source_link' => $params['source_link'] ?? null,
541 'source_photo' => $params['source_photo'] ?? null,
542 'uid' => $params['uid'],
543 'hsitelink' => $hsitelink,
544 'tsitelink' => $tsitelink,
545 'itemlink' => $itemlink,
548 'subject' => $subject,
549 'headers' => $additional_mail_header,
552 Hook::callAll('enotify_mail', $datarray);
554 $builder = DI::emailer()
556 ->addHeaders($datarray['headers'])
557 ->withRecipient($params['to_email'])
559 'uid' => $datarray['uid'],
560 'language' => $params['language'],
562 ->withNotification($datarray['subject'], $datarray['preamble'], $datarray['title'], $datarray['body'])
563 ->withSiteLink($datarray['tsitelink'], $datarray['hsitelink'])
564 ->withItemLink($datarray['itemlink']);
566 // If a photo is present, add it to the email
567 if (!empty($datarray['source_photo'])) {
569 $datarray['source_photo'],
570 $datarray['source_link'] ?? $sitelink,
571 $datarray['source_name'] ?? $sitename);
574 $email = $builder->build();
576 // use the Emailer class to send the message
577 return DI::emailer()->send($email);
584 * Checks for users who should be notified
586 * @param int $itemid ID of the item for which the check should be done
587 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
589 function check_user_notification($itemid) {
590 // fetch all users with notifications
591 $useritems = DBA::select('user-item', ['uid', 'notification-type'], ['iid' => $itemid]);
592 while ($useritem = DBA::fetch($useritems)) {
593 check_item_notification($itemid, $useritem['uid'], $useritem['notification-type']);
595 DBA::close($useritems);
599 * Checks for item related notifications and sends them
601 * @param int $itemid ID of the item for which the check should be done
602 * @param int $uid User ID
603 * @param int $notification_type Notification bits
605 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
607 function check_item_notification($itemid, $uid, $notification_type) {
608 $fields = ['id', 'uri-id', 'mention', 'parent', 'parent-uri-id', 'thr-parent-id',
609 'title', 'body', 'author-link', 'author-name', 'author-avatar', 'author-id',
610 'gravity', 'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
611 $condition = ['id' => $itemid, 'deleted' => false];
612 $item = Item::selectFirstForUser($uid, $fields, $condition);
613 if (!DBA::isResult($item)) {
617 // Generate the notification array
619 $params['uid'] = $uid;
620 $params['item'] = $item;
621 $params['parent'] = $item['parent'];
622 $params['link'] = DI::baseUrl() . '/display/' . urlencode($item['guid']);
623 $params['otype'] = 'item';
624 $params['origin_name'] = $params['source_name'] = $item['author-name'];
625 $params['origin_link'] = $params['source_link'] = $item['author-link'];
626 $params['origin_photo'] = $params['source_photo'] = $item['author-avatar'];
628 // Set the activity flags
629 $params['activity']['explicit_tagged'] = ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED);
630 $params['activity']['implicit_tagged'] = ($notification_type & UserItem::NOTIF_IMPLICIT_TAGGED);
631 $params['activity']['origin_comment'] = ($notification_type & UserItem::NOTIF_DIRECT_COMMENT);
632 $params['activity']['origin_thread'] = ($notification_type & UserItem::NOTIF_THREAD_COMMENT);
633 $params['activity']['thread_comment'] = ($notification_type & UserItem::NOTIF_COMMENT_PARTICIPATION);
634 $params['activity']['thread_activity'] = ($notification_type & UserItem::NOTIF_ACTIVITY_PARTICIPATION);
636 // Tagging a user in a direct post (first comment level) means a direct comment
637 if ($params['activity']['explicit_tagged'] && ($notification_type & UserItem::NOTIF_DIRECT_THREAD_COMMENT)) {
638 $params['activity']['origin_comment'] = true;
641 if ($notification_type & UserItem::NOTIF_SHARED) {
642 $params['type'] = Notify\Type::SHARE;
643 $params['verb'] = Activity::POST;
645 // Special treatment for posts that had been shared via "announce"
646 if ($item['gravity'] == GRAVITY_ACTIVITY) {
647 $parent_item = Item::selectFirst($fields, ['uri-id' => $item['thr-parent-id'], 'uid' => [$uid, 0]]);
648 if (DBA::isResult($parent_item)) {
649 // Don't notify on own entries
650 if (User::getIdForURL($parent_item['author-link']) == $uid) {
654 $params['origin_name'] = $parent_item['author-name'];
655 $params['origin_link'] = $parent_item['author-link'];
656 $params['origin_photo'] = $parent_item['author-avatar'];
657 $params['item'] = $parent_item;
660 } elseif ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED) {
661 $params['type'] = Notify\Type::TAG_SELF;
662 $params['verb'] = Activity::TAG;
663 } elseif ($notification_type & UserItem::NOTIF_IMPLICIT_TAGGED) {
664 $params['type'] = Notify\Type::COMMENT;
665 $params['verb'] = Activity::POST;
666 } elseif ($notification_type & UserItem::NOTIF_THREAD_COMMENT) {
667 $params['type'] = Notify\Type::COMMENT;
668 $params['verb'] = Activity::POST;
669 } elseif ($notification_type & UserItem::NOTIF_DIRECT_COMMENT) {
670 $params['type'] = Notify\Type::COMMENT;
671 $params['verb'] = Activity::POST;
672 } elseif ($notification_type & UserItem::NOTIF_COMMENT_PARTICIPATION) {
673 $params['type'] = Notify\Type::COMMENT;
674 $params['verb'] = Activity::POST;
675 } elseif ($notification_type & UserItem::NOTIF_ACTIVITY_PARTICIPATION) {
676 $params['type'] = Notify\Type::COMMENT;
677 $params['verb'] = Activity::POST;
682 notification($params);