From 8e2494568e4e9dcd704dbe8756eba6ec3cbae878 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jan 2020 01:23:40 +0000 Subject: [PATCH] Functionality is now added --- src/Model/Item.php | 2 ++ src/Model/UserItem.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index c9d71e8c1..e030141fa 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2026,6 +2026,8 @@ class Item self::updateContact($item); + UserItem::setNotification($current_post, $item['uid']); + check_user_notification($current_post); if ($notify || ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin']))) { diff --git a/src/Model/UserItem.php b/src/Model/UserItem.php index ea61696e3..d0d1ebad9 100644 --- a/src/Model/UserItem.php +++ b/src/Model/UserItem.php @@ -6,6 +6,7 @@ namespace Friendica\Model; +use Friendica\Core\Logger; use Friendica\Core\Hook; use Friendica\Database\DBA; use Friendica\DI; @@ -28,8 +29,12 @@ class UserItem * @param array $item The message array that is checked for notifications * @param int $uid User ID */ - public static function setNotification($item, $uid) + public static function setNotification($iid, $uid) { + $fields = ['id', 'body', 'origin', 'parent', 'gravity', 'tag', 'contact-id', + 'thr-parent', 'parent-uri', 'mention']; + $item = Item::selectFirst($fields, ['id' => $iid]); + // Don't check for own posts if ($item['origin'] || empty($uid)) { return; @@ -80,6 +85,12 @@ class UserItem $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); } @@ -144,7 +155,7 @@ class UserItem } // Or the contact is a mentioned forum - $tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => TERM_MENTION, 'uid' => $uid]); + $tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $item['id'], 'type' => TERM_MENTION, 'uid' => $uid]); while ($tag = DBA::fetch($tags)) { $condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY]; if (DBA::exists('contact', $condition)) {