Add New notice and reblog delivery events, various bug fixes and improvements

This commit is contained in:
Diogo Cordeiro
2018-07-15 02:13:46 +01:00
parent a5b56b3089
commit b693dab832
9 changed files with 311 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
<?php
require_once dirname (__DIR__) . DIRECTORY_SEPARATOR . "utils" . DIRECTORY_SEPARATOR . "explorer.php";
/**
* GNU social - a federating social network
*
@@ -178,7 +179,13 @@ class Activitypub_profile extends Profile
$aprofile = Activitypub_profile::getKV ('profile_id', $profile_id);
if (!$aprofile instanceof Activitypub_profile) {
throw new Exception ('No Activitypub_profile for Profile ID: '.$profile_id);
// No Activitypub_profile for this profile_id,
if (!$profile->isLocal ()) {
// create one!
$aprofile = self::create_from_local_profile ($profile);
} else {
throw new Exception ('No Activitypub_profile for Profile ID: '.$profile_id. ', this probably is a local profile.');
}
}
foreach ($profile as $key => $value) {
@@ -188,6 +195,35 @@ class Activitypub_profile extends Profile
return $aprofile;
}
/**
* Given an existent local profile creates an ActivityPub profile.
* One must be careful not to give a user profile to this function
* as only remote users have ActivityPub_profiles on local instance
*
* @param Profile $profile
* @return Activitypub_profile
*/
private static function create_from_local_profile (Profile $profile)
{
$url = $profile->getURL ();
$inboxes = Activitypub_explorer::get_actor_inboxes_uri ($url);
$aprofile->created = $aprofile->modified = common_sql_now ();
$aprofile = new Activitypub_profile;
$aprofile->profile_id = $profile->getID ();
$aprofile->uri = $url;
$aprofile->nickname = $profile->getNickname ();
$aprofile->fullname = $profile->getFullname ();
$aprofile->bio = substr ($profile->getDescription (), 0, 1000);
$aprofile->inboxuri = $inboxes["inbox"];
$aprofile->sharedInboxuri = $inboxes["sharedInbox"];
$aprofile->insert ();
return $aprofile;
}
/**
* Returns sharedInbox if possible, inbox otherwise
*