1
1
Fork 0

Merge pull request #9005 from annando/notify-shared

Create notifications for shared posts
This commit is contained in:
Hypolite Petovan 2020-08-13 02:21:56 -04:00 committed by GitHub
commit 7d50335e05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 33 deletions

View file

@ -597,7 +597,7 @@ function check_item_notification($itemid, $uid, $notification_type) {
$fields = ['id', 'uri-id', 'mention', 'parent', 'parent-uri-id', 'title', 'body',
'author-link', 'author-name', 'author-avatar', 'author-id',
'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);
if (!DBA::isResult($item)) {
return false;

View file

@ -2018,14 +2018,7 @@ class Item
if (!empty($contact['id'])) {
$condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']], $condition);
$forum_item = Item::selectFirst(['id'], $condition);
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']]);
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']]);
}
}

View file

@ -27,6 +27,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Strings;
use Friendica\Model\Tag;
use Friendica\Protocol\Activity;
class UserItem
{
@ -50,12 +51,18 @@ class UserItem
*/
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]);
if (!DBA::isResult($item)) {
return;
}
// "Activity::FOLLOW" is an automated activity, so we ignore it here
if ($item['verb'] == Activity::FOLLOW) {
return;
}
// fetch all users in the thread
$users = DBA::p("SELECT DISTINCT(`contact`.`uid`) FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` != 0
@ -100,6 +107,8 @@ class UserItem
return;
}
// Only create notifications for posts and comments, not for activities
if (in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT])) {
if (self::checkImplicitMention($item, $profiles)) {
$notification_type = $notification_type | self::NOTIF_IMPLICIT_TAGGED;
}
@ -127,6 +136,7 @@ class UserItem
if (self::checkActivityParticipation($item, $contacts)) {
$notification_type = $notification_type | self::NOTIF_ACTIVITY_PARTICIPATION;
}
}
if (empty($notification_type)) {
return;
@ -197,16 +207,22 @@ class UserItem
*/
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;
}
// 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])) {
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]]);
while ($tag = DBA::fetch($tags)) {
$condition = ['nurl' => Strings::normaliseLink($tag['url']), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];