]> git.mxchange.org Git - friendica.git/commitdiff
AP: Automatically send follow requests for reshared items
authorMichael <heluecht@pirati.ca>
Wed, 30 Jan 2019 21:33:23 +0000 (21:33 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 30 Jan 2019 21:33:23 +0000 (21:33 +0000)
src/Object/Post.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Transmitter.php

index bc1123db2b1af845e6a98a915c4c773cee5221a6..847135d3621bf10945d71a652e694c4b9faa4a8f 100644 (file)
@@ -775,6 +775,10 @@ class Post extends BaseObject
         */
        private function getDefaultText()
        {
+               if (!local_user()) {
+                       return;
+               }
+
                $a = self::getApp();
 
                $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]);
index ea4d5ba411c1123eae0d4c199c972d2839c694ee..fd6d70a42a2d01fac09c0501a2da35a57a03d13b 100644 (file)
@@ -329,6 +329,15 @@ class Processor
                        $item_id = Item::insert($item);
                        Logger::log('Storing for user ' . $item['uid'] . ': ' . $item_id);
                }
+
+               if (!$item['private'] && ($item['gravity'] == GRAVITY_PARENT) && ($item['author-link'] != $item['owner-link'])) {
+                       $author = APContact::getByURL($item['owner-link'], false);
+                       // We send automatic follow requests for reshared messages. (We don't need though for forum posts)
+                       if ($author['type'] != 'Group') {
+                               Logger::log('Send follow request for ' . $item['uri'] . ' to ' . $item['author-link'], Logger::DEBUG);
+                               ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']);
+                       }
+               }
        }
 
        /**
index b2f0291adf054bd1b9063808532909aad3e619e6..f5953e7c5fcdab1e5bc54aba944b48d0440d53ee 100644 (file)
@@ -6,6 +6,7 @@ namespace Friendica\Protocol\ActivityPub;
 
 use Friendica\BaseObject;
 use Friendica\Database\DBA;
+use Friendica\Core\Config;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Util\HTTPSignature;
@@ -1295,10 +1296,20 @@ class Transmitter
         * @throws \ImagickException
         * @throws \Exception
         */
-       public static function sendFollowObject($object, $target, $uid)
+       public static function sendFollowObject($object, $target, $uid = 0)
        {
                $profile = APContact::getByURL($target);
 
+               if (empty($uid)) {
+                       // Fetch the list of administrators
+                       $admin_mail = explode(',', str_replace(' ', '', Config::get('config', 'admin_email')));
+
+                       // We need to use some user as a sender. It doesn't care who it will send. We will use an administrator account.
+                       $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false, 'email' => $admin_mail];
+                       $first_user = DBA::selectFirst('user', ['uid'], $condition);
+                       $uid = $first_user['uid'];
+               }
+
                $owner = User::getOwnerDataById($uid);
 
                $data = ['@context' => ActivityPub::CONTEXT,