mirror of
https://github.com/friendica/friendica
synced 2025-04-26 09:10:15 +00:00
We can now manage relay servers and can send content to them
This commit is contained in:
parent
ca624ec612
commit
178455928a
6 changed files with 226 additions and 3 deletions
|
@ -163,11 +163,13 @@ class Receiver
|
|||
|
||||
if ($type != 'as:Announce') {
|
||||
Logger::info('Not an announcement', ['activity' => $activity]);
|
||||
return;
|
||||
}
|
||||
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||
if (empty($object_id)) {
|
||||
Logger::info('No object id found', ['activity' => $activity]);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Got relayed message id', ['id' => $object_id]);
|
||||
|
|
|
@ -61,6 +61,68 @@ require_once 'mod/share.php';
|
|||
*/
|
||||
class Transmitter
|
||||
{
|
||||
/**
|
||||
* Add relay servers to the list of inboxes
|
||||
*
|
||||
* @param array $inboxes
|
||||
* @return array inboxes with added relay servers
|
||||
*/
|
||||
public static function addRelayServerInboxes(array $inboxes)
|
||||
{
|
||||
$contacts = DBA::select('apcontact', ['inbox'],
|
||||
["`type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))",
|
||||
'Application', 0, Contact::FOLLOWER, Contact::FRIEND]);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$inboxes[] = $contact['inbox'];
|
||||
}
|
||||
DBA::close($contacts);
|
||||
|
||||
return $inboxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to a relay
|
||||
*
|
||||
* @param string $url Subscribe actor url
|
||||
* @return bool success
|
||||
*/
|
||||
public static function sendRelayFollow(string $url)
|
||||
{
|
||||
$contact_id = Contact::getIdForURL($url);
|
||||
if (!$contact_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
|
||||
$success = ActivityPub\Transmitter::sendActivity('Follow', $url, 0, $activity_id);
|
||||
if ($success) {
|
||||
DBA::update('contact', ['rel' => Contact::FRIEND], ['id' => $contact_id]);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from a relay
|
||||
*
|
||||
* @param string $url Subscribe actor url
|
||||
* @return bool success
|
||||
*/
|
||||
public static function sendRelayUndoFollow(string $url)
|
||||
{
|
||||
$contact_id = Contact::getIdForURL($url);
|
||||
if (!$contact_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = self::sendContactUndo($url, $contact_id, 0);
|
||||
if ($success) {
|
||||
DBA::update('contact', ['rel' => Contact::SHARING], ['id' => $contact_id]);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects a list of contacts of the given owner
|
||||
*
|
||||
|
@ -1917,18 +1979,19 @@ class Transmitter
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
* @throws \Exception
|
||||
* @return bool success
|
||||
*/
|
||||
public static function sendContactUndo($target, $cid, $uid)
|
||||
{
|
||||
$profile = APContact::getByURL($target);
|
||||
if (empty($profile['inbox'])) {
|
||||
Logger::warning('No inbox found for target', ['target' => $target, 'profile' => $profile]);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$object_id = self::activityIDFromContact($cid);
|
||||
if (empty($object_id)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = DI::baseUrl() . '/activity/' . System::createGUID();
|
||||
|
@ -1947,7 +2010,7 @@ class Transmitter
|
|||
Logger::log('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
|
||||
|
||||
$signed = LDSignature::sign($data, $owner);
|
||||
HTTPSignature::transmit($signed, $profile['inbox'], $uid);
|
||||
return HTTPSignature::transmit($signed, $profile['inbox'], $uid);
|
||||
}
|
||||
|
||||
private static function prependMentions($body, int $uriid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue