*/
public static function setNotification(int $iid)
{
- $fields = ['id', 'uri-id', 'uid', 'body', 'parent', 'gravity', 'tag',
- 'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb'];
- $item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]);
+ $fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity',
+ 'private', 'contact-id', 'thr-parent', 'parent-uri', 'author-id', 'verb'];
+ $item = Post::selectFirst($fields, ['id' => $iid, 'origin' => false]);
if (!DBA::isResult($item)) {
return;
}
return;
}
- // fetch all users in the thread
- $users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
- INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
- WHERE `parent` IN (SELECT `parent` FROM `item` WHERE `id`=?)", $iid);
+ if ($item['uid'] == 0) {
+ $uids = [];
+ } else {
+ // Always include the item user
+ $uids = [$item['uid']];
+ }
+
+ // Add every user who participated so far in this thread
+ // This can only happen with participations on global items. (means: uid = 0)
+ $users = DBA::p("SELECT DISTINCT(`contact-uid`) AS `uid` FROM `post-view`
+ WHERE `contact-uid` != 0 AND `parent` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $iid);
while ($user = DBA::fetch($users)) {
- self::setNotificationForUser($item, $user['uid']);
+ $uids[] = $user['uid'];
}
DBA::close($users);
+
+ foreach (array_unique($uids) as $uid) {
+ self::setNotificationForUser($item, $uid);
+ }
}
/**
*/
private static function setNotificationForUser(array $item, int $uid)
{
- $thread = Item::selectFirstThreadForUser($uid, ['ignored'], ['iid' => $item['parent'], 'deleted' => false]);
+ $thread = Post::selectFirstThreadForUser($uid, ['ignored'], ['iid' => $item['parent'], 'deleted' => false]);
if (!empty($thread['ignored'])) {
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);
+ $fields = ['notification-type' => $notification_type];
+ Post\User::update($item['uri-id'], $uid, $fields);
+ DBA::update('user-item', $fields, ['iid' => $item['id'], 'uid' => $uid], true);
}
/**
*/
private static function checkShared(array $item, int $uid)
{
- // Only sheck on starting posts and reshare ("announce") activities, otherwise return
+ // Only check on original posts and reshare ("announce") activities, otherwise return
if (($item['gravity'] != GRAVITY_PARENT) && ($item['verb'] != Activity::ANNOUNCE)) {
return false;
}
- // Check if the contact had posted or shared something directly
+ // Check if the contact posted or shared something directly
if (DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true])) {
return true;
}
private static function checkCommentedThread(array $item, array $contacts)
{
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_PARENT];
- return Item::exists($condition);
+ return Post::exists($condition);
}
/**
private static function checkDirectComment(array $item, array $contacts)
{
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_COMMENT];
- return Item::exists($condition);
+ return Post::exists($condition);
}
/**
private static function checkDirectCommentedThread(array $item, array $contacts)
{
$condition = ['uri' => $item['thr-parent'], 'uid' => $item['uid'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_PARENT];
- return Item::exists($condition);
+ return Post::exists($condition);
}
/**
private static function checkCommentedParticipation(array $item, array $contacts)
{
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_COMMENT];
- return Item::exists($condition);
+ return Post::exists($condition);
}
/**
private static function checkActivityParticipation(array $item, array $contacts)
{
$condition = ['parent' => $item['parent'], 'author-id' => $contacts, 'deleted' => false, 'gravity' => GRAVITY_ACTIVITY];
- return Item::exists($condition);
+ return Post::exists($condition);
}
}