Fixes for the notifications
This commit is contained in:
parent
61e023d448
commit
1fe756b5b6
|
@ -537,6 +537,11 @@ abstract class DI
|
||||||
return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
|
return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function formattedNavNotificationFactory(): Navigation\Notifications\Factory\FormattedNavNotification
|
||||||
|
{
|
||||||
|
return self::$dice->create(Navigation\Notifications\Factory\FormattedNavNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// "Protocol" namespace instances
|
// "Protocol" namespace instances
|
||||||
//
|
//
|
||||||
|
|
|
@ -183,8 +183,6 @@ class Ping extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary workaround for notifications without messages like with the following verb:
|
|
||||||
// - \Friendica\Protocol\Activity::ANNOUNCE
|
|
||||||
$navNotifications = array_map(function (Entity\Notification $notification) {
|
$navNotifications = array_map(function (Entity\Notification $notification) {
|
||||||
try {
|
try {
|
||||||
return $this->formattedNavNotification->createFromNotification($notification);
|
return $this->formattedNavNotification->createFromNotification($notification);
|
||||||
|
|
|
@ -133,7 +133,7 @@ class FormattedNavNotification extends BaseFactory
|
||||||
return $this->createFromParams(
|
return $this->createFromParams(
|
||||||
self::$contacts[$intro->cid],
|
self::$contacts[$intro->cid],
|
||||||
$this->l10n->t('{0} wants to follow you'),
|
$this->l10n->t('{0} wants to follow you'),
|
||||||
new \DateTime($intro->datetime, new \DateTimeZone('UTC')),
|
$intro->datetime,
|
||||||
new Uri($this->baseUrl->get() . '/notifications/intros/' . $intro->id)
|
new Uri($this->baseUrl->get() . '/notifications/intros/' . $intro->id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,11 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
||||||
{
|
{
|
||||||
$message = [];
|
$message = [];
|
||||||
|
|
||||||
|
if (Post\ThreadUser::getIgnored($Notification->parentUriId, $Notification->uid)) {
|
||||||
|
$this->logger->info('Thread is ignored', ['parent-uri-id' => $Notification->parentUriId, 'type' => $Notification->type]);
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
$causer = $author = Contact::getById($Notification->actorId, ['id', 'name', 'url', 'contact-type', 'pending']);
|
$causer = $author = Contact::getById($Notification->actorId, ['id', 'name', 'url', 'contact-type', 'pending']);
|
||||||
if (empty($causer)) {
|
if (empty($causer)) {
|
||||||
$this->logger->info('Causer not found', ['contact' => $Notification->actorId]);
|
$this->logger->info('Causer not found', ['contact' => $Notification->actorId]);
|
||||||
|
@ -128,28 +133,29 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array($Notification->type, [Post\UserNotification::TYPE_THREAD_COMMENT, Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_EXPLICIT_TAGGED])) {
|
||||||
|
$item = Post::selectFirst([], ['uri-id' => $Notification->parentUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
||||||
|
if (empty($item)) {
|
||||||
|
$this->logger->info('Parent post not found', ['uri-id' => $Notification->parentUriId]);
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
if ($Notification->type == Post\UserNotification::TYPE_COMMENT_PARTICIPATION) {
|
||||||
|
$link_item = Post::selectFirst(['guid'], ['uri-id' => $Notification->targetUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$item = Post::selectFirst([], ['uri-id' => $Notification->targetUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
$item = Post::selectFirst([], ['uri-id' => $Notification->targetUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
$this->logger->info('Post not found', ['uri-id' => $Notification->targetUriId]);
|
$this->logger->info('Post not found', ['uri-id' => $Notification->targetUriId]);
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Notification->type == Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION) {
|
if (($Notification->verb == Activity::POST) || ($Notification->type === Post\UserNotification::TYPE_SHARED)) {
|
||||||
$thrParentId = $item['thr-parent-id'];
|
$item = Post::selectFirst([], ['uri-id' => $item['thr-parent-id'], 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
||||||
$item = Post::selectFirst([], ['uri-id' => $thrParentId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
$this->logger->info('Thread parent post not found', ['uri-id' => $thrParentId]);
|
$this->logger->info('Thread parent post not found', ['uri-id' => $item['thr-parent-id']]);
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $item;
|
|
||||||
if ($Notification->targetUriId != $Notification->parentUriId) {
|
|
||||||
$parent = Post::selectFirst([], ['uri-id' => $Notification->parentUriId, 'uid' => [0, $Notification->uid]], ['order' => ['uid' => true]]);
|
|
||||||
if (empty($parent)) {
|
|
||||||
$this->logger->info('Top level post not found', ['uri-id' => $Notification->parentUriId]);
|
|
||||||
return $message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_SHARED])) {
|
if (in_array($Notification->type, [Post\UserNotification::TYPE_COMMENT_PARTICIPATION, Post\UserNotification::TYPE_ACTIVITY_PARTICIPATION, Post\UserNotification::TYPE_SHARED])) {
|
||||||
|
@ -160,9 +166,9 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = $this->baseUrl . '/display/' . urlencode($item['guid']);
|
$link = $this->baseUrl . '/display/' . urlencode($link_item['guid'] ?? $item['guid']);
|
||||||
|
|
||||||
$content = Plaintext::getPost($parent, 70);
|
$content = Plaintext::getPost($item, 70);
|
||||||
if (!empty($content['text'])) {
|
if (!empty($content['text'])) {
|
||||||
$title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
|
$title = '"' . trim(str_replace("\n", " ", $content['text'])) . '"';
|
||||||
} else {
|
} else {
|
||||||
|
@ -298,6 +304,8 @@ class Notification extends BaseFactory implements ICanCreateFromTableRow
|
||||||
'[url=' . $link . ']' . $title . '[/url]',
|
'[url=' . $link . ']' . $title . '[/url]',
|
||||||
'[url=' . $author['url'] . ']' . $author['name'] . '[/url]');
|
'[url=' . $author['url'] . ']' . $author['name'] . '[/url]');
|
||||||
$message['link'] = $link;
|
$message['link'] = $link;
|
||||||
|
} else {
|
||||||
|
$this->logger->debug('Unhandled notification', ['notification' => $Notification]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message;
|
return $message;
|
||||||
|
|
|
@ -125,7 +125,7 @@ class Notification extends BaseRepository
|
||||||
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]);
|
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->selectForUser(local_user(), $condition, ['limit' => 50, 'order' => ['id' => true]]);
|
return $this->selectForUser($uid, $condition, ['limit' => 50, 'order' => ['id' => true]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user