+ private static function setNotificationForUser(array $item, int $uid)
+ {
+ $thread = Item::selectFirstThreadForUser($uid, ['ignored'], ['iid' => $item['parent'], 'deleted' => false]);
+ if ($thread['ignored']) {
+ return;
+ }
+
+ $notification_type = self::NOTIF_NONE;
+
+ if (self::checkShared($item, $uid)) {
+ $notification_type = $notification_type | self::NOTIF_SHARED;
+ }
+
+ $profiles = self::getProfileForUser($uid);
+
+ // Fetch all contacts for the given profiles
+ $contacts = [];
+ $ret = DBA::select('contact', ['id'], ['uid' => 0, 'nurl' => $profiles]);
+ while ($contact = DBA::fetch($ret)) {
+ $contacts[] = $contact['id'];
+ }
+ DBA::close($ret);
+
+ // Don't create notifications for user's posts
+ if (in_array($item['author-id'], $contacts)) {
+ return;
+ }
+
+ if (self::checkImplicitMention($item, $profiles)) {
+ $notification_type = $notification_type | self::NOTIF_IMPLICIT_TAGGED;
+ }
+
+ if (self::checkExplicitMention($item, $profiles)) {
+ $notification_type = $notification_type | self::NOTIF_EXPLICIT_TAGGED;
+ }
+
+ if (self::checkCommentedThread($item, $contacts)) {
+ $notification_type = $notification_type | self::NOTIF_THREAD_COMMENT;
+ }
+
+ if (self::checkDirectComment($item, $contacts)) {
+ $notification_type = $notification_type | self::NOTIF_DIRECT_COMMENT;
+ }
+
+ if (self::checkDirectCommentedThread($item, $contacts)) {
+ $notification_type = $notification_type | self::NOTIF_DIRECT_THREAD_COMMENT;
+ }
+
+ if (self::checkCommentedParticipation($item, $contacts)) {
+ $notification_type = $notification_type | self::NOTIF_COMMENT_PARTICIPATION;
+ }
+
+ if (self::checkActivityParticipation($item, $contacts)) {
+ $notification_type = $notification_type | self::NOTIF_ACTIVITY_PARTICIPATION;
+ }
+
+ if (empty($notification_type)) {
+ return;
+ }
+
+ Logger::info('Set notification', ['iid' => $item['id'], 'uid' => $uid, 'notification-type' => $notification_type]);
+
+ DBA::update('user-item', ['notification-type' => $notification_type], ['iid' => $item['id'], 'uid' => $uid], true);
+ }
+
+ /**
+ * Fetch all profiles (contact URL) of a given user
+ * @param int $uid User ID
+ *
+ * @return array Profile links
+ */
+ private static function getProfileForUser(int $uid)