Added "follow" subscription message

This commit is contained in:
Michael 2021-08-22 08:27:56 +00:00
parent 59045b2e23
commit e9c63ff075
2 changed files with 165 additions and 149 deletions

View file

@ -168,159 +168,165 @@ class Notification extends BaseModel
{ {
$message = []; $message = [];
if ($notification['type'] == Post\UserNotification::NOTIF_NONE) {
return $message;
}
if (empty($notification['target-uri-id'])) {
return $message;
}
$user = User::getById($notification['uid']); $user = User::getById($notification['uid']);
if (empty($user)) { if (empty($user)) {
Logger::info('User not found', ['application' => $notification['uid']]); Logger::info('User not found', ['application' => $notification['uid']]);
return $message; return $message;
} }
$causer = $contact = Contact::getById($notification['actor-id'], ['id', 'name', 'url']); $l10n = DI::l10n()->withLang($user['language']);
$causer = $contact = Contact::getById($notification['actor-id'], ['id', 'name', 'url', 'pending']);
if (empty($contact)) { if (empty($contact)) {
Logger::info('Contact not found', ['contact' => $notification['actor-id']]); Logger::info('Contact not found', ['contact' => $notification['actor-id']]);
return $message; return $message;
} }
$like = Verb::getID(Activity::LIKE); if ($notification['type'] == Post\UserNotification::NOTIF_NONE) {
$dislike = Verb::getID(Activity::DISLIKE); if ($contact['pending']) {
$announce = Verb::getID(Activity::ANNOUNCE); $msg = $l10n->t('%1$s wants to follow you');
$post = Verb::getID(Activity::POST); } else {
$msg = $l10n->t('%1$s had started following you');
if (in_array($notification['type'], [Post\UserNotification::NOTIF_THREAD_COMMENT, Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION, Post\UserNotification::NOTIF_EXPLICIT_TAGGED])) {
$item = Post::selectFirst([], ['uri-id' => $notification['parent-uri-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]);
if (empty($item)) {
Logger::info('Parent post not found', ['uri-id' => $notification['parent-uri-id']]);
return $message;
} }
$title = $contact['name'];
$link = DI::baseUrl() . '/contact/' . $contact['id'];
} else { } else {
$item = Post::selectFirst([], ['uri-id' => $notification['target-uri-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]); if (empty($notification['target-uri-id'])) {
if (empty($item)) {
Logger::info('Post not found', ['uri-id' => $notification['target-uri-id']]);
return $message; return $message;
} }
if ($notification['vid'] == $post) { $like = Verb::getID(Activity::LIKE);
$item = Post::selectFirst([], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]); $dislike = Verb::getID(Activity::DISLIKE);
$announce = Verb::getID(Activity::ANNOUNCE);
$post = Verb::getID(Activity::POST);
if (in_array($notification['type'], [Post\UserNotification::NOTIF_THREAD_COMMENT, Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION, Post\UserNotification::NOTIF_EXPLICIT_TAGGED])) {
$item = Post::selectFirst([], ['uri-id' => $notification['parent-uri-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]);
if (empty($item)) { if (empty($item)) {
Logger::info('Thread parent post not found', ['uri-id' => $item['thr-parent-id']]); Logger::info('Parent post not found', ['uri-id' => $notification['parent-uri-id']]);
return $message;
}
} else {
$item = Post::selectFirst([], ['uri-id' => $notification['target-uri-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]);
if (empty($item)) {
Logger::info('Post not found', ['uri-id' => $notification['target-uri-id']]);
return $message;
}
if ($notification['vid'] == $post) {
$item = Post::selectFirst([], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $notification['uid']]], ['order' => ['uid' => true]]);
if (empty($item)) {
Logger::info('Thread parent post not found', ['uri-id' => $item['thr-parent-id']]);
return $message;
}
}
}
if (($notification['type'] == Post\UserNotification::NOTIF_SHARED) && !empty($item['causer-id'])) {
$causer = Contact::getById($item['causer-id'], ['id', 'name', 'url']);
if (empty($contact)) {
Logger::info('Causer not found', ['causer' => $item['causer-id']]);
return $message;
}
} elseif (in_array($notification['type'], [Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION])) {
$contact = Contact::getById($item['author-id'], ['id', 'name', 'url']);
if (empty($contact)) {
Logger::info('Author not found', ['author' => $item['author-id']]);
return $message; return $message;
} }
} }
}
if (($notification['type'] == Post\UserNotification::NOTIF_SHARED) && !empty($item['causer-id'])) { $link = DI::baseUrl() . '/display/' . urlencode($item['guid']);
$causer = Contact::getById($item['causer-id'], ['id', 'name', 'url']);
if (empty($contact)) { $content = Plaintext::getPost($item, 70);
Logger::info('Causer not found', ['causer' => $item['causer-id']]); if (!empty($content['text'])) {
return $message; $title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
} else {
$title = '';
} }
} elseif (in_array($notification['type'], [Post\UserNotification::NOTIF_COMMENT_PARTICIPATION, Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION])) {
$contact = Contact::getById($item['author-id'], ['id', 'name', 'url']); switch ($notification['vid']) {
if (empty($contact)) { case $like:
Logger::info('Author not found', ['author' => $item['author-id']]); switch ($notification['type']) {
return $message; case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s liked your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s liked your post %2$s');
break;
}
break;
case $dislike:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s disliked your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s disliked your post %2$s');
break;
}
break;
case $announce:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s shared your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s shared your post %2$s');
break;
}
break;
case $post:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_EXPLICIT_TAGGED:
$msg = $l10n->t('%1$s tagged you on %2$s');
break;
case Post\UserNotification::NOTIF_IMPLICIT_TAGGED:
$msg = $l10n->t('%1$s replied to you on %2$s');
break;
case Post\UserNotification::NOTIF_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented in your thread %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s commented on your comment %2$s');
break;
case Post\UserNotification::NOTIF_COMMENT_PARTICIPATION:
case Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION:
if (($causer['id'] == $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s commented in their thread %2$s');
} elseif ($causer['id'] == $contact['id']) {
$msg = $l10n->t('%1$s commented in their thread');
} elseif ($title != '') {
$msg = $l10n->t('%1$s commented in the thread %2$s from %3$s');
} else {
$msg = $l10n->t('%1$s commented in the thread from %3$s');
}
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented on your thread %2$s');
break;
case Post\UserNotification::NOTIF_SHARED:
if (($causer['id'] != $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s shared the post %2$s from %3$s');
} elseif ($causer['id'] != $contact['id']) {
$msg = $l10n->t('%1$s shared a post from %3$s');
} elseif ($title != '') {
$msg = $l10n->t('%1$s shared the post %2$s');
} else {
$msg = $l10n->t('%1$s shared a post');
}
break;
}
break;
} }
} }
$link = DI::baseUrl() . '/display/' . urlencode($item['guid']);
$content = Plaintext::getPost($item, 70);
if (!empty($content['text'])) {
$title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
} else {
$title = '';
}
$l10n = DI::l10n()->withLang($user['language']);
switch ($notification['vid']) {
case $like:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s liked your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s liked your post %2$s');
break;
}
break;
case $dislike:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s disliked your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s disliked your post %2$s');
break;
}
break;
case $announce:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s shared your comment %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s shared your post %2$s');
break;
}
break;
case $post:
switch ($notification['type']) {
case Post\UserNotification::NOTIF_EXPLICIT_TAGGED:
$msg = $l10n->t('%1$s tagged you on %2$s');
break;
case Post\UserNotification::NOTIF_IMPLICIT_TAGGED:
$msg = $l10n->t('%1$s replied to you on %2$s');
break;
case Post\UserNotification::NOTIF_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented in your thread %2$s');
break;
case Post\UserNotification::NOTIF_DIRECT_COMMENT:
$msg = $l10n->t('%1$s commented on your comment %2$s');
break;
case Post\UserNotification::NOTIF_COMMENT_PARTICIPATION:
case Post\UserNotification::NOTIF_ACTIVITY_PARTICIPATION:
if (($causer['id'] == $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s commented in their thread %2$s');
} elseif ($causer['id'] == $contact['id']) {
$msg = $l10n->t('%1$s commented in their thread');
} elseif ($title != '') {
$msg = $l10n->t('%1$s commented in the thread %2$s from %3$s');
} else {
$msg = $l10n->t('%1$s commented in the thread from %3$s');
}
break;
case Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT:
$msg = $l10n->t('%1$s commented on your thread %2$s');
break;
case Post\UserNotification::NOTIF_SHARED:
if (($causer['id'] != $contact['id']) && ($title != '')) {
$msg = $l10n->t('%1$s shared the post %2$s from %3$s');
} elseif ($causer['id'] != $contact['id']) {
$msg = $l10n->t('%1$s shared a post from %3$s');
} elseif ($title != '') {
$msg = $l10n->t('%1$s shared the post %2$s');
} else {
$msg = $l10n->t('%1$s shared a post');
}
break;
}
break;
}
if (!empty($msg)) { if (!empty($msg)) {
// Name of the notification's causer // Name of the notification's causer
$message['causer'] = $causer['name']; $message['causer'] = $causer['name'];
@ -328,7 +334,7 @@ class Notification extends BaseModel
$message['notification'] = sprintf($msg, '{0}', $title, $contact['name']); $message['notification'] = sprintf($msg, '{0}', $title, $contact['name']);
// Plain text for the web push api // Plain text for the web push api
$message['plain'] = sprintf($msg, $causer['name'], $title, $contact['name']); $message['plain'] = sprintf($msg, $causer['name'], $title, $contact['name']);
// Rich text for other purposes // Rich text for other purposes
$message['rich'] = sprintf($msg, $message['rich'] = sprintf($msg,
'[url=' . $causer['url'] . ']' . $causer['name'] . '[/url]', '[url=' . $causer['url'] . ']' . $causer['name'] . '[/url]',
'[url=' . $link . ']' . $title . '[/url]', '[url=' . $link . ']' . $title . '[/url]',

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2021.09-dev\n" "Project-Id-Version: 2021.09-dev\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-08-22 03:57+0000\n" "POT-Creation-Date: 2021-08-22 08:26+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -4665,97 +4665,107 @@ msgstr ""
msgid "[no subject]" msgid "[no subject]"
msgstr "" msgstr ""
#: src/Model/Notification.php:247 #: src/Model/Notification.php:187
#, php-format
msgid "%1$s wants to follow you"
msgstr ""
#: src/Model/Notification.php:189
#, php-format
msgid "%1$s had started following you"
msgstr ""
#: src/Model/Notification.php:252
#, php-format #, php-format
msgid "%1$s liked your comment %2$s" msgid "%1$s liked your comment %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:250 #: src/Model/Notification.php:255
#, php-format #, php-format
msgid "%1$s liked your post %2$s" msgid "%1$s liked your post %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:257 #: src/Model/Notification.php:262
#, php-format #, php-format
msgid "%1$s disliked your comment %2$s" msgid "%1$s disliked your comment %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:260 #: src/Model/Notification.php:265
#, php-format #, php-format
msgid "%1$s disliked your post %2$s" msgid "%1$s disliked your post %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:267 #: src/Model/Notification.php:272
#, php-format #, php-format
msgid "%1$s shared your comment %2$s" msgid "%1$s shared your comment %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:270 #: src/Model/Notification.php:275
#, php-format #, php-format
msgid "%1$s shared your post %2$s" msgid "%1$s shared your post %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:277 #: src/Model/Notification.php:282
#, php-format #, php-format
msgid "%1$s tagged you on %2$s" msgid "%1$s tagged you on %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:281 #: src/Model/Notification.php:286
#, php-format #, php-format
msgid "%1$s replied to you on %2$s" msgid "%1$s replied to you on %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:285 #: src/Model/Notification.php:290
#, php-format #, php-format
msgid "%1$s commented in your thread %2$s" msgid "%1$s commented in your thread %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:289 #: src/Model/Notification.php:294
#, php-format #, php-format
msgid "%1$s commented on your comment %2$s" msgid "%1$s commented on your comment %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:295 #: src/Model/Notification.php:300
#, php-format #, php-format
msgid "%1$s commented in their thread %2$s" msgid "%1$s commented in their thread %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:297 #: src/Model/Notification.php:302
#, php-format #, php-format
msgid "%1$s commented in their thread" msgid "%1$s commented in their thread"
msgstr "" msgstr ""
#: src/Model/Notification.php:299 #: src/Model/Notification.php:304
#, php-format #, php-format
msgid "%1$s commented in the thread %2$s from %3$s" msgid "%1$s commented in the thread %2$s from %3$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:301 #: src/Model/Notification.php:306
#, php-format #, php-format
msgid "%1$s commented in the thread from %3$s" msgid "%1$s commented in the thread from %3$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:306 #: src/Model/Notification.php:311
#, php-format #, php-format
msgid "%1$s commented on your thread %2$s" msgid "%1$s commented on your thread %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:311 #: src/Model/Notification.php:316
#, php-format #, php-format
msgid "%1$s shared the post %2$s from %3$s" msgid "%1$s shared the post %2$s from %3$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:313 #: src/Model/Notification.php:318
#, php-format #, php-format
msgid "%1$s shared a post from %3$s" msgid "%1$s shared a post from %3$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:315 #: src/Model/Notification.php:320
#, php-format #, php-format
msgid "%1$s shared the post %2$s" msgid "%1$s shared the post %2$s"
msgstr "" msgstr ""
#: src/Model/Notification.php:317 #: src/Model/Notification.php:322
#, php-format #, php-format
msgid "%1$s shared a post" msgid "%1$s shared a post"
msgstr "" msgstr ""