- $params["uid"] = $uid;
- $params["item"] = $item;
- $params["parent"] = $item["parent"];
- $params["link"] = System::baseUrl().'/display/'.urlencode($item["guid"]);
- $params["otype"] = 'item';
- $params["source_name"] = $item["author-name"];
- $params["source_link"] = $item["author-link"];
- $params["source_photo"] = $item["author-avatar"];
-
- if ($item["parent-uri"] === $item["uri"]) {
- // Send a notification for every new post?
- // Either the contact had posted something directly
- $send_notification = DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true]);
-
- // Or the contact is a mentioned forum
- if (!$send_notification) {
- $tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
- intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid));
-
- if (DBA::isResult($tags)) {
- foreach ($tags AS $tag) {
- $condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
- if (DBA::exists('contact', $condition)) {
- $send_notification = true;
- }
- }
- }
- }
-
- if ($send_notification) {
- $params["type"] = NOTIFY_SHARE;
- $params["verb"] = Activity::TAG;
- }
- }
-
- // Is the user mentioned in this post?
- $tagged = false;
-
- foreach ($profiles AS $profile) {
- if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
- $tagged = true;
- }
-
- if ($item["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
- $params["type"] = NOTIFY_TAGSELF;
- $params["verb"] = Activity::TAG;
- }
-
- // Is it a post that the user had started?
- $fields = ['ignored', 'mention'];
- $thread = Item::selectFirstThreadForUser($params['uid'], $fields, ['iid' => $item["parent"], 'deleted' => false]);
-
- if ($thread['mention'] && !$thread['ignored'] && !isset($params["type"])) {
- $params["type"] = NOTIFY_COMMENT;
- $params["verb"] = Activity::POST;
- }
-
- // And now we check for participation of one of our contacts in the thread
- $condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];
-
- if (!$thread['ignored'] && !isset($params["type"]) && Item::exists($condition)) {
- $params["type"] = NOTIFY_COMMENT;
- $params["verb"] = Activity::POST;
- }
-
- if (isset($params["type"])) {
- notification($params);
- }
-}
-
-/**
- * @brief Formats a notification message with the notification author
- *
- * Replace the name with {0} but ensure to make that only once. The {0} is used
- * later and prints the name in bold.
- *
- * @param string $name
- * @param string $message
- * @return string Formatted message
- */
-function format_notification_message($name, $message) {
- if ($name != '') {
- $pos = strpos($message, $name);
+ $params['uid'] = $uid;
+ $params['item'] = $item;
+ $params['parent'] = $item['parent'];
+ $params['link'] = DI::baseUrl() . '/display/' . urlencode($item['guid']);
+ $params['otype'] = 'item';
+ $params['source_name'] = $item['author-name'];
+ $params['source_link'] = $item['author-link'];
+ $params['source_photo'] = $item['author-avatar'];
+
+ // Set the activity flags
+ $params['activity']['explicit_tagged'] = ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED);
+ $params['activity']['implicit_tagged'] = ($notification_type & UserItem::NOTIF_IMPLICIT_TAGGED);
+ $params['activity']['origin_comment'] = ($notification_type & UserItem::NOTIF_DIRECT_COMMENT);
+ $params['activity']['origin_thread'] = ($notification_type & UserItem::NOTIF_THREAD_COMMENT);
+ $params['activity']['thread_comment'] = ($notification_type & UserItem::NOTIF_COMMENT_PARTICIPATION);
+ $params['activity']['thread_activity'] = ($notification_type & UserItem::NOTIF_ACTIVITY_PARTICIPATION);
+
+ // Tagging a user in a direct post (first comment level) means a direct comment
+ if ($params['activity']['explicit_tagged'] && ($notification_type & UserItem::NOTIF_DIRECT_THREAD_COMMENT)) {
+ $params['activity']['origin_comment'] = true;
+ }
+
+ if ($notification_type & UserItem::NOTIF_SHARED) {
+ $params['type'] = NOTIFY_SHARE;
+ $params['verb'] = Activity::POST;
+ } elseif ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED) {
+ $params['type'] = NOTIFY_TAGSELF;
+ $params['verb'] = Activity::TAG;
+ } elseif ($notification_type & UserItem::NOTIF_IMPLICIT_TAGGED) {
+ $params['type'] = NOTIFY_COMMENT;
+ $params['verb'] = Activity::POST;
+ } elseif ($notification_type & UserItem::NOTIF_THREAD_COMMENT) {
+ $params['type'] = NOTIFY_COMMENT;
+ $params['verb'] = Activity::POST;
+ } elseif ($notification_type & UserItem::NOTIF_DIRECT_COMMENT) {
+ $params['type'] = NOTIFY_COMMENT;
+ $params['verb'] = Activity::POST;
+ } elseif ($notification_type & UserItem::NOTIF_COMMENT_PARTICIPATION) {
+ $params['type'] = NOTIFY_COMMENT;
+ $params['verb'] = Activity::POST;
+ } elseif ($notification_type & UserItem::NOTIF_ACTIVITY_PARTICIPATION) {
+ $params['type'] = NOTIFY_COMMENT;
+ $params['verb'] = Activity::POST;