[OStatus] Add TheFreeNetwork module's support in handling profile insertion

Ostatus_profile:
- Update createActivityObjectProfile to trigger TFN's assistance in inserting the profile
This commit is contained in:
tenma 2020-04-03 02:47:55 +01:00 committed by Diogo Cordeiro
parent 134b6f6478
commit cfba91ea43

View File

@ -1206,7 +1206,31 @@ class Ostatus_profile extends Managed_DataObject
$oprofile->created = common_sql_now();
$oprofile->modified = common_sql_now();
$tfn = false;
if ($object->type == ActivityObject::PERSON) {
// Does any other protocol have this remote entity we're about to add ?
if (!Event::handle('StartTFNLookup', [$oprofile->uri, get_called_class(), &$profile_id])) {
$tfn = true; // been here!
// Yes! Avoid creating a new profile
$oprofile->profile_id = $profile_id;
if ($profile->insert() === false) {
// TRANS: Server exception.
throw new ServerException(_m('Cannot save OStatus profile.'));
}
// Update existing profile with received data
$profile = Profile::getKV('id', $profile_id);
$profile->modified = common_sql_now();
self::updateProfile($profile, $object, $hints);
// Ask TFN to handle profile duplication
Event::handle('EndTFNLookup', [get_called_class(), $profile_id]);
} else {
// No, create both a new profile and remote profile
$profile = new Profile();
$profile->created = common_sql_now();
self::updateProfile($profile, $object, $hints);
@ -1216,6 +1240,7 @@ class Ostatus_profile extends Managed_DataObject
// TRANS: Server exception.
throw new ServerException(_m('Cannot save local profile.'));
}
}
} else if ($object->type == ActivityObject::GROUP) {
$profile = new Profile();
$profile->query('BEGIN');
@ -1270,12 +1295,14 @@ class Ostatus_profile extends Managed_DataObject
}
}
if (!$tfn) {
$ok = $oprofile->insert();
if ($ok === false) {
// TRANS: Server exception.
throw new ServerException(_m('Cannot save OStatus profile.'));
}
}
$avatar = self::getActivityObjectAvatar($object, $hints);