Merge pull request #9005 from annando/notify-shared
Create notifications for shared posts
This commit is contained in:
commit
7d50335e05
|
@ -597,7 +597,7 @@ function check_item_notification($itemid, $uid, $notification_type) {
|
||||||
$fields = ['id', 'uri-id', 'mention', 'parent', 'parent-uri-id', 'title', 'body',
|
$fields = ['id', 'uri-id', 'mention', 'parent', 'parent-uri-id', 'title', 'body',
|
||||||
'author-link', 'author-name', 'author-avatar', 'author-id',
|
'author-link', 'author-name', 'author-avatar', 'author-id',
|
||||||
'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
|
'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
|
||||||
$condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'deleted' => false];
|
$condition = ['id' => $itemid, 'deleted' => false];
|
||||||
$item = Item::selectFirstForUser($uid, $fields, $condition);
|
$item = Item::selectFirstForUser($uid, $fields, $condition);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2018,14 +2018,7 @@ class Item
|
||||||
if (!empty($contact['id'])) {
|
if (!empty($contact['id'])) {
|
||||||
$condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
|
$condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
|
||||||
Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']], $condition);
|
Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']], $condition);
|
||||||
$forum_item = Item::selectFirst(['id'], $condition);
|
Logger::info('Convert message into a forum message', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $contact['id']]);
|
||||||
if (!empty($forum_item['id'])) {
|
|
||||||
// This will trigger notifications like "X shared a new post"
|
|
||||||
UserItem::setNotification($forum_item['id']);
|
|
||||||
|
|
||||||
check_user_notification($forum_item['id']);
|
|
||||||
}
|
|
||||||
LOgger::info('Convert message into a forum message', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $contact['id']]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
|
use Friendica\Protocol\Activity;
|
||||||
|
|
||||||
class UserItem
|
class UserItem
|
||||||
{
|
{
|
||||||
|
@ -50,12 +51,18 @@ class UserItem
|
||||||
*/
|
*/
|
||||||
public static function setNotification(int $iid)
|
public static function setNotification(int $iid)
|
||||||
{
|
{
|
||||||
$fields = ['id', 'uri-id', 'uid', 'body', 'parent', 'gravity', 'tag', 'contact-id', 'thr-parent', 'parent-uri', 'author-id'];
|
$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]);
|
$item = Item::selectFirst($fields, ['id' => $iid, 'origin' => false]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "Activity::FOLLOW" is an automated activity, so we ignore it here
|
||||||
|
if ($item['verb'] == Activity::FOLLOW) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// fetch all users in the thread
|
// fetch all users in the thread
|
||||||
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
|
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
|
||||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
|
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
|
||||||
|
@ -100,32 +107,35 @@ class UserItem
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkImplicitMention($item, $profiles)) {
|
// Only create notifications for posts and comments, not for activities
|
||||||
$notification_type = $notification_type | self::NOTIF_IMPLICIT_TAGGED;
|
if (in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT])) {
|
||||||
}
|
if (self::checkImplicitMention($item, $profiles)) {
|
||||||
|
$notification_type = $notification_type | self::NOTIF_IMPLICIT_TAGGED;
|
||||||
|
}
|
||||||
|
|
||||||
if (self::checkExplicitMention($item, $profiles)) {
|
if (self::checkExplicitMention($item, $profiles)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_EXPLICIT_TAGGED;
|
$notification_type = $notification_type | self::NOTIF_EXPLICIT_TAGGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkCommentedThread($item, $contacts)) {
|
if (self::checkCommentedThread($item, $contacts)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_THREAD_COMMENT;
|
$notification_type = $notification_type | self::NOTIF_THREAD_COMMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkDirectComment($item, $contacts)) {
|
if (self::checkDirectComment($item, $contacts)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_DIRECT_COMMENT;
|
$notification_type = $notification_type | self::NOTIF_DIRECT_COMMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkDirectCommentedThread($item, $contacts)) {
|
if (self::checkDirectCommentedThread($item, $contacts)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_DIRECT_THREAD_COMMENT;
|
$notification_type = $notification_type | self::NOTIF_DIRECT_THREAD_COMMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkCommentedParticipation($item, $contacts)) {
|
if (self::checkCommentedParticipation($item, $contacts)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_COMMENT_PARTICIPATION;
|
$notification_type = $notification_type | self::NOTIF_COMMENT_PARTICIPATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::checkActivityParticipation($item, $contacts)) {
|
if (self::checkActivityParticipation($item, $contacts)) {
|
||||||
$notification_type = $notification_type | self::NOTIF_ACTIVITY_PARTICIPATION;
|
$notification_type = $notification_type | self::NOTIF_ACTIVITY_PARTICIPATION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($notification_type)) {
|
if (empty($notification_type)) {
|
||||||
|
@ -197,16 +207,22 @@ class UserItem
|
||||||
*/
|
*/
|
||||||
private static function checkShared(array $item, int $uid)
|
private static function checkShared(array $item, int $uid)
|
||||||
{
|
{
|
||||||
if ($item['gravity'] != GRAVITY_PARENT) {
|
// Only check on original posts and reshare ("announce") activities, otherwise return
|
||||||
|
if (($item['gravity'] != GRAVITY_PARENT) && ($item['verb'] != Activity::ANNOUNCE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Either the contact had posted something directly
|
// Check if the contact posted or shared something directly
|
||||||
if (DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true])) {
|
if (DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Or the contact is a mentioned forum
|
// 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]]);
|
$tags = DBA::select('tag-view', ['url'], ['uri-id' => $item['uri-id'], 'type' => [Tag::MENTION, Tag::EXCLUSIVE_MENTION]]);
|
||||||
while ($tag = DBA::fetch($tags)) {
|
while ($tag = DBA::fetch($tags)) {
|
||||||
$condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
|
$condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user