Improved notification for announced posts

This commit is contained in:
Michael 2022-01-23 21:47:16 +00:00
parent 2b05561337
commit 27a306185a
2 changed files with 6 additions and 39 deletions

View File

@ -406,21 +406,6 @@ class UserNotification
return true;
}
// The following check doesn't make sense on activities, so quit here
if ($item['verb'] == Activity::ANNOUNCE) {
return false;
}
// Check if the contact is a mentioned forum
$tags = DBA::select('tag-view', ['url'], ['uri-id' => $item['uri-id'], 'type' => [Tag::MENTION, Tag::EXCLUSIVE_MENTION]]);
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)) {
return true;
}
}
DBA::close($tags);
return false;
}

View File

@ -114,7 +114,8 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
return $message;
}
if ($Notification->verb == Activity::POST) {
if (($Notification->verb == Activity::POST) ||
(($Notification->type === Post\UserNotification::TYPE_SHARED) && ($Notification->verb == Activity::ANNOUNCE))) {
$item = Post::selectFirst([], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
if (empty($item)) {
$this->logger->info('Thread parent post not found', ['uri-id' => $item['thr-parent-id']]);
@ -123,17 +124,10 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
}
}
if ($item['owner-id'] != $item['author-id']) {
$cid = $item['owner-id'];
}
if (!empty($item['causer-id']) && ($item['causer-id'] != $item['author-id'])) {
$cid = $item['causer-id'];
}
if (($Notification->type === Post\UserNotification::TYPE_SHARED) && !empty($cid)) {
$causer = Contact::getById($cid, ['id', 'name', 'url']);
if (empty($causer)) {
$this->logger->info('Causer not found', ['causer' => $cid]);
if ($Notification->type === Post\UserNotification::TYPE_SHARED) {
$author = Contact::getById($item['author-id'], ['id', 'name', 'url']);
if (empty($author)) {
$this->logger->info('Author not found', ['author' => $item['author-id']]);
return $message;
}
} elseif (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION])) {
@ -231,18 +225,6 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
$msg = $userL10n->t('%1$s commented on your thread %2$s');
break;
case Post\UserNotification::TYPE_SHARED:
if (($causer['id'] != $author['id']) && ($title != '')) {
$msg = $userL10n->t('%1$s shared the post %2$s from %3$s');
} elseif ($causer['id'] != $author['id']) {
$msg = $userL10n->t('%1$s shared a post from %3$s');
} elseif ($title != '') {
$msg = $userL10n->t('%1$s shared the post %2$s');
} else {
$msg = $userL10n->t('%1$s shared a post');
}
break;
}
break;
}