Merge pull request #11180 from annando/announce-notification
Desktop notification for announced posts
This commit is contained in:
commit
b6aeb6e903
3 changed files with 185 additions and 172 deletions
|
@ -257,8 +257,12 @@ class UserNotification
|
|||
}
|
||||
}
|
||||
|
||||
if (empty($notification_type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only create notifications for posts and comments, not for activities
|
||||
if (empty($notification_type) || !in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT])) {
|
||||
if (($item['gravity'] == GRAVITY_ACTIVITY) && ($item['verb'] != Activity::ANNOUNCE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -280,7 +284,7 @@ class UserNotification
|
|||
*/
|
||||
private static function insertNotificationByItem(int $type, int $uid, array $item): void
|
||||
{
|
||||
if (($item['gravity'] == GRAVITY_ACTIVITY) &&
|
||||
if (($item['verb'] != Activity::ANNOUNCE) && ($item['gravity'] == GRAVITY_ACTIVITY) &&
|
||||
!in_array($type, [self::TYPE_DIRECT_COMMENT, self::TYPE_DIRECT_THREAD_COMMENT])) {
|
||||
// Activities are only stored when performed on the user's post or comment
|
||||
return;
|
||||
|
@ -402,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
return $message;
|
||||
}
|
||||
|
||||
if ($Notification->verb == Activity::POST) {
|
||||
if (($Notification->verb == Activity::POST) || ($Notification->type === Post\UserNotification::TYPE_SHARED)) {
|
||||
$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,20 +123,7 @@ 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]);
|
||||
return $message;
|
||||
}
|
||||
} elseif (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION])) {
|
||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, 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']]);
|
||||
|
@ -153,6 +140,8 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
$title = '';
|
||||
}
|
||||
|
||||
$this->logger->debug('Got verb and type', ['verb' => $Notification->verb, 'type' => $Notification->type]);
|
||||
|
||||
switch ($Notification->verb) {
|
||||
case Activity::LIKE:
|
||||
switch ($Notification->type) {
|
||||
|
@ -182,6 +171,38 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
|||
case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
|
||||
$msg = $userL10n->t('%1$s shared your post %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;
|
||||
case Activity::ATTEND:
|
||||
switch ($Notification->type) {
|
||||
case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
|
||||
$msg = $userL10n->t('%1$s wants to attend your event %2$s');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Activity::ATTENDNO:
|
||||
switch ($Notification->type) {
|
||||
case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
|
||||
$msg = $userL10n->t('%1$s does not want to attend your event %2$s');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Activity::ATTENDMAYBE:
|
||||
switch ($Notification->type) {
|
||||
case Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT:
|
||||
$msg = $userL10n->t('%1$s maybe wants to attend your event %2$s');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Activity::POST:
|
||||
|
@ -218,18 +239,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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue