+ return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
+ }
+
+ /**
+ * Transmits a "follow object" activity to a target
+ * This is a preparation for sending automated "follow" requests when receiving "Announce" messages
+ *
+ * @param string $object Object URL
+ * @param string $target Target profile
+ * @param integer $uid User ID
+ * @return bool
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ * @throws \Exception
+ */
+ 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'];
+ }
+
+ $condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
+ 'author-id' => Contact::getPublicIdByUserId($uid)];
+ if (Item::exists($condition)) {
+ Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
+ return false;
+ }
+
+ $owner = User::getOwnerDataById($uid);
+
+ $data = ['@context' => ActivityPub::CONTEXT,
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Follow',
+ 'actor' => $owner['url'],
+ 'object' => $object,
+ 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+ 'to' => [$profile['url']]];
+
+ Logger::log('Sending follow ' . $object . ' to ' . $target . ' for user ' . $uid, Logger::DEBUG);
+
+ $signed = LDSignature::sign($data, $owner);
+ return HTTPSignature::transmit($signed, $profile['inbox'], $uid);