X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fenotify.php;h=1edad36ac0c79bd6383a72c60376e8b4660d8877;hb=c18622caf999e2ddf7e2cda5bf4a50d6506c3931;hp=eb56603277c5dc8f374224688ffb7980fcf6ee7e;hpb=56a77f5275ba8566a37d690ade0e929c88b828e2;p=friendica.git diff --git a/include/enotify.php b/include/enotify.php index eb56603277..1edad36ac0 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -1,6 +1,6 @@ $parent_id, 'deleted' => false]); - if (DBA::isResult($thread) && $thread['ignored']) { - Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG); + if (Post\ThreadUser::getIgnored($parent_uri_id, $params['uid'])) { + Logger::info('Thread is ignored', ['parent' => $parent_id, 'parent-uri-id' => $parent_uri_id]); return false; } @@ -174,7 +172,7 @@ function notification($params) return false; } - $item_post_type = Item::postType($item); + $item_post_type = Item::postType($item, $l10n); $content = Plaintext::getPost($item, 70); if (!empty($content['text'])) { @@ -275,7 +273,7 @@ function notification($params) $epreamble = $l10n->t('%1$s [url=%2$s]shared a post[/url] from %3$s.', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]', $params['link'], '[url='.$params['origin_link'].']'.$params['origin_name'].'[/url]' - ); + ); } $sitelink = $l10n->t('Please visit %s to view and/or reply to the conversation.'); @@ -523,11 +521,10 @@ function notification($params) $message_id = "<" . $parent['guid'] . "@" . gethostname() . ">"; // Is this the first email notification for this parent item and user? - if (!DBA::exists('notify-threads', ['master-parent-item' => $params['parent'], 'receiver-uid' => $params['uid']])) { + if (!DBA::exists('notify-threads', ['master-parent-uri-id' => $parent_uri_id, 'receiver-uid' => $params['uid']])) { Logger::log("notify_id:" . intval($notify_id) . ", parent: " . intval($params['parent']) . "uid: " . intval($params['uid']), Logger::DEBUG); - $fields = ['notify-id' => $notify_id, 'master-parent-item' => $params['parent'], - 'master-parent-uri-id' => $parent_uri_id, + $fields = ['notify-id' => $notify_id, 'master-parent-uri-id' => $parent_uri_id, 'receiver-uid' => $params['uid'], 'parent-item' => 0]; DBA::insert('notify-threads', $fields); @@ -593,32 +590,39 @@ function notification($params) /** * Checks for users who should be notified * - * @param int $itemid ID of the item for which the check should be done + * @param int $uri_id URI ID of the item for which the check should be done + * @param int $uid User ID of the item * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ -function check_user_notification($itemid) { - // fetch all users with notifications - $useritems = DBA::select('user-item', ['uid', 'notification-type'], ['iid' => $itemid]); - while ($useritem = DBA::fetch($useritems)) { - check_item_notification($itemid, $useritem['uid'], $useritem['notification-type']); +function check_user_notification(int $uri_id, int $uid) { + $condition = ['uri-id' => $uri_id]; + + // fetch all users with notifications on public posts + if ($uid != 0) { + $condition['uid'] = $uid; + } + + $usernotifications = DBA::select('post-user-notification', ['uri-id', 'uid', 'notification-type'], $condition); + while ($usernotification = DBA::fetch($usernotifications)) { + check_item_notification($usernotification['uri-id'], $usernotification['uid'], $usernotification['notification-type'], $uid); } - DBA::close($useritems); + DBA::close($usernotifications); } /** * Checks for item related notifications and sends them * - * @param int $itemid ID of the item for which the check should be done + * @param int $uri_id URI ID of the item for which the check should be done * @param int $uid User ID * @param int $notification_type Notification bits * @return bool * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ -function check_item_notification($itemid, $uid, $notification_type) { +function check_item_notification(int $uri_id, int $uid, int $notification_type, $post_uid) { $fields = ['id', 'uri-id', 'mention', 'parent', 'parent-uri-id', 'thr-parent-id', 'title', 'body', 'author-link', 'author-name', 'author-avatar', 'author-id', 'gravity', 'guid', 'parent-uri', 'uri', 'contact-id', 'network']; - $condition = ['id' => $itemid, 'deleted' => false]; + $condition = ['uri-id' => $uri_id, 'uid' => [$uid, $post_uid], 'deleted' => false]; $item = Post::selectFirstForUser($uid, $fields, $condition); if (!DBA::isResult($item)) { return false; @@ -638,19 +642,19 @@ function check_item_notification($itemid, $uid, $notification_type) { $params['link'] = DI::baseUrl() . '/display/' . urlencode($item['guid']); // 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); + $params['activity']['explicit_tagged'] = ($notification_type & Post\UserNotification::NOTIF_EXPLICIT_TAGGED); + $params['activity']['implicit_tagged'] = ($notification_type & Post\UserNotification::NOTIF_IMPLICIT_TAGGED); + $params['activity']['origin_comment'] = ($notification_type & Post\UserNotification::NOTIF_DIRECT_COMMENT); + $params['activity']['origin_thread'] = ($notification_type & Post\UserNotification::NOTIF_THREAD_COMMENT); + $params['activity']['thread_comment'] = ($notification_type & Post\UserNotification::NOTIF_COMMENT_PARTICIPATION); + $params['activity']['thread_activity'] = ($notification_type & Post\UserNotification::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)) { + if ($params['activity']['explicit_tagged'] && ($notification_type & Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT)) { $params['activity']['origin_comment'] = true; } - if ($notification_type & UserItem::NOTIF_SHARED) { + if ($notification_type & Post\UserNotification::NOTIF_SHARED) { $params['type'] = Notification\Type::SHARE; $params['verb'] = Activity::POST; @@ -667,22 +671,22 @@ function check_item_notification($itemid, $uid, $notification_type) { $params['item'] = $parent_item; } } - } elseif ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED) { + } elseif ($notification_type & Post\UserNotification::NOTIF_EXPLICIT_TAGGED) { $params['type'] = Notification\Type::TAG_SELF; $params['verb'] = Activity::TAG; - } elseif ($notification_type & UserItem::NOTIF_IMPLICIT_TAGGED) { + } elseif ($notification_type & Post\UserNotification::NOTIF_IMPLICIT_TAGGED) { $params['type'] = Notification\Type::COMMENT; $params['verb'] = Activity::POST; - } elseif ($notification_type & UserItem::NOTIF_THREAD_COMMENT) { + } elseif ($notification_type & Post\UserNotification::NOTIF_THREAD_COMMENT) { $params['type'] = Notification\Type::COMMENT; $params['verb'] = Activity::POST; - } elseif ($notification_type & UserItem::NOTIF_DIRECT_COMMENT) { + } elseif ($notification_type & Post\UserNotification::NOTIF_DIRECT_COMMENT) { $params['type'] = Notification\Type::COMMENT; $params['verb'] = Activity::POST; - } elseif ($notification_type & UserItem::NOTIF_COMMENT_PARTICIPATION) { + } elseif ($notification_type & Post\UserNotification::NOTIF_COMMENT_PARTICIPATION) { $params['type'] = Notification\Type::COMMENT; $params['verb'] = Activity::POST; - } elseif ($notification_type & UserItem::NOTIF_ACTIVITY_PARTICIPATION) { + } elseif ($notification_type & Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION) { $params['type'] = Notification\Type::COMMENT; $params['verb'] = Activity::POST; } else {