Issue 5983: Central check for blocked and ignored contacts added
[friendica.git/.git] / src / Model / Item.php
index 387014d..67d051d 100644 (file)
@@ -11,9 +11,9 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Config;
 use Friendica\Core\Hook;
+use Friendica\Core\L10n;
 use Friendica\Core\Lock;
 use Friendica\Core\Logger;
-use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
@@ -24,10 +24,11 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
-use Friendica\Util\XML;
+use Friendica\Util\Network;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
-use Friendica\Util\Network;
+use Friendica\Util\XML;
+use Friendica\Worker\Delivery;
 use Text_LanguageDetect;
 
 class Item extends BaseObject
@@ -62,7 +63,7 @@ class Item extends BaseObject
 
        // Field list that is used to deliver items via the protocols
        const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
-                       'created', 'edited', 'verb', 'object-type', 'object', 'target',
+                       'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
                        'private', 'title', 'body', 'location', 'coord', 'app',
                        'attach', 'tag', 'deleted', 'extid', 'post-type',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
@@ -87,7 +88,7 @@ class Item extends BaseObject
                        'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
                        'title', 'content-warning', 'body', 'location', 'coord', 'app',
                        'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
-                       'author-id', 'author-link', 'author-name', 'author-avatar',
+                       'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar'];
 
        // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
@@ -925,7 +926,7 @@ class Item extends BaseObject
                        // We only need to notfiy others when it is an original entry from us.
                        // Only call the notifier when the item has some content relevant change.
                        if ($item['origin'] && in_array('edited', array_keys($fields))) {
-                               Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']);
+                               Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item['id']);
                        }
                }
 
@@ -1095,7 +1096,7 @@ class Item extends BaseObject
                        self::delete(['uri' => $item['uri'], 'deleted' => false], $priority);
 
                        // send the notification upstream/downstream
-                       Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", "drop", intval($item['id']));
+                       Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id']));
                } elseif ($item['uid'] != 0) {
 
                        // When we delete just our local user copy of an item, we have to set a marker to hide it
@@ -1452,6 +1453,16 @@ class Item extends BaseObject
                        return 0;
                }
 
+               if (!empty($uid) && Contact::isBlockedByUser($item['author-link'], $uid)) {
+                       Logger::notice('Author is blocked by user', ['author-link' => $item['author-link'], 'uid' => $uid, 'item-uri' => $item['uri']]);
+                       return 0;
+               }
+
+               if (!empty($uid) && ($item['parent-uri'] === $item['uri']) && Contact::isIgnoredByUser($item['author-link'], $uid)) {
+                       Logger::notice('Author is ignored by user', ['author-link' => $item['author-link'], 'uid' => $uid, 'item-uri' => $item['uri']]);
+                       return 0;
+               }
+
                $default = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
                        'photo' => $item['owner-avatar'], 'network' => $item['network']];
 
@@ -1467,6 +1478,16 @@ class Item extends BaseObject
                        return 0;
                }
 
+               if (!empty($uid) && Contact::isBlockedByUser($item['owner-link'], $uid)) {
+                       Logger::notice('Owner is blocked by user', ['owner-link' => $item['owner-link'], 'uid' => $uid, 'item-uri' => $item['uri']]);
+                       return 0;
+               }
+
+               if (!empty($uid) && ($item['parent-uri'] === $item['uri']) && Contact::isIgnoredByUser($item['owner-link'], $uid)) {
+                       Logger::notice('Owner is ignored by user', ['owner-link' => $item['owner-link'], 'uid' => $uid, 'item-uri' => $item['uri']]);
+                       return 0;
+               }
+
                if ($item['network'] == Protocol::PHANTOM) {
                        $item['network'] = Protocol::DFRN;
                        Logger::notice('Missing network, setting to {network}.', [
@@ -1508,7 +1529,7 @@ class Item extends BaseObject
 
                $item['thr-parent'] = $item['parent-uri'];
 
-               $notify_type = '';
+               $notify_type = Delivery::POST;
                $allow_cid = '';
                $allow_gid = '';
                $deny_cid  = '';
@@ -1521,7 +1542,6 @@ class Item extends BaseObject
                        $allow_gid = $item['allow_gid'];
                        $deny_cid  = $item['deny_cid'];
                        $deny_gid  = $item['deny_gid'];
-                       $notify_type = 'wall-new';
                } else {
                        // find the parent and snarf the item id and ACLs
                        // and anything else we need to inherit
@@ -1558,8 +1578,7 @@ class Item extends BaseObject
                                $allow_gid      = $parent['allow_gid'];
                                $deny_cid       = $parent['deny_cid'];
                                $deny_gid       = $parent['deny_gid'];
-                               $item['wall']    = $parent['wall'];
-                               $notify_type    = 'comment-new';
+                               $item['wall']   = $parent['wall'];
 
                                /*
                                 * If the parent is private, force privacy for the entire conversation
@@ -1603,6 +1622,10 @@ class Item extends BaseObject
                        }
                }
 
+               if (stristr($item['verb'], ACTIVITY_POKE)) {
+                       $notify_type = Delivery::POKE;
+               }
+
                $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
                $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
 
@@ -1721,6 +1744,7 @@ class Item extends BaseObject
                unset($item['author-link']);
                unset($item['author-name']);
                unset($item['author-avatar']);
+               unset($item['author-network']);
 
                unset($item['owner-link']);
                unset($item['owner-name']);
@@ -1876,18 +1900,8 @@ class Item extends BaseObject
 
                check_user_notification($current_post);
 
-               if ($notify) {
+               if ($notify || ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin']))) {
                        Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post);
-               } elseif ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin'])) {
-                       if ($item['gravity'] == GRAVITY_ACTIVITY) {
-                               $cmd = $item['origin'] ? 'activity-new' : 'activity-import';
-                       } elseif ($item['gravity'] == GRAVITY_COMMENT) {
-                               $cmd = $item['origin'] ? 'comment-new' : 'comment-import';
-                       } else {
-                               $cmd = 'wall-new';
-                       }
-
-                       Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $cmd, $current_post);
                }
 
                return $current_post;
@@ -2603,7 +2617,7 @@ class Item extends BaseObject
 
                self::updateThread($item_id);
 
-               Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', 'tgroup', $item_id);
+               Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
        }
 
        public static function isRemoteSelf($contact, &$datarray)
@@ -2653,7 +2667,6 @@ class Item extends BaseObject
                                $datarray['author-link']   = $datarray['owner-link'];
                                $datarray['author-avatar'] = $datarray['owner-avatar'];
 
-                               unset($datarray['created']);
                                unset($datarray['edited']);
 
                                unset($datarray['network']);