support mastodon account move notifications

This commit is contained in:
zotlabs 2019-10-14 15:55:58 -07:00
parent 29a4777452
commit dbf477f3d8
3 changed files with 59 additions and 1 deletions

View file

@ -1356,8 +1356,9 @@ class Activity {
static function actor_store($url,$person_obj) {
if (! is_array($person_obj))
if (! is_array($person_obj)) {
return;
}
// logger('person_obj: ' . print_r($person_obj,true));
@ -1373,6 +1374,13 @@ class Activity {
}
}
if (array_key_exists('movedTo',$person_obj) && $person_obj['movedTo'] && ! is_array($person_obj['movedTo'])) {
$tgt = self::fetch($person_obj['movedTo']);
self::actor_store($person_obj['movedTo'],$tgt);
ActivityPub::move($person_obj['id'],$tgt);
return;
}
$url = $person_obj['id'];
if (! $url) {

View file

@ -421,4 +421,48 @@ class ActivityPub {
return false;
}
static public function move($src,$dst) {
if (! ($src && $dst)) {
return;
}
if ($src && ! is_array($src)) {
$src = Activity::fetch($src);
if (is_array($src)) {
$src_xchan = $src['id'];
}
}
$approvals = null;
if ($dst && ! is_array($dst)) {
$dst = Activity::fetch($dst);
if (is_array($dst)) {
$dst_xchan = $dst['id'];
if (array_key_exists('alsoKnownAs',$dst)) {
if(! is_array($dst['alsoKnownAs'])) {
$dst['alsoKnownAs'] = [ $dst['alsoKnownAs'] ];
}
$approvals = $dst['alsoKnownAs'];
}
}
}
if(! ($src_xchan && $dst_xchan)) {
return;
}
if ($approvals) {
foreach($approvals as $approval) {
if($approval === $src_xchan) {
$r = q("update abook set abook_xchan = '%s' where abook_xchan = '%s'",
dbesc($dst_xchan),
dbesc($src_xchan)
);
}
}
}
}
}

View file

@ -242,6 +242,12 @@ class Inbox extends Controller {
case 'Delete':
Activity::drop($channel,$observer_hash,$AS);
break;
case 'Move':
if($observer_hash && $observer_hash === $AS->actor && Activity::is_an_actor($AS->obj) && Activity::is_an_actor($AS->tgt)) {
ActivityPub::move($AS->obj,$AS->tgt);
}
break;
case 'Add':
case 'Remove':
default: