Commit 7391f7ac authored by Mario's avatar Mario

pubcrawl: add support for inbound shares

parent 9c57875e
......@@ -40,7 +40,22 @@ class Inbox extends \Zotlabs\Web\Controller {
if(is_array($AS->actor) && array_key_exists('id',$AS->actor))
as_actor_store($AS->actor['id'],$AS->actor);
if($AS->type == 'Announce' && is_array($AS->obj) && array_key_exists('attributedTo',$AS->obj)) {
$sharee = asfetch_profile([ 'id' => $AS->obj['attributedTo'] ]);
if(! $sharee) {
$arr = [
'address' => $AS->obj['attributedTo']
];
$x = pubcrawl_discover_channel_webfinger($arr);
if($x['success']) {
$sharee = asfetch_profile([ 'id' => $AS->obj['attributedTo'] ]);
}
}
if($sharee)
$AS->sharee = $sharee;
}
$observer_hash = $AS->actor['id'];
if(! $observer_hash)
......@@ -142,10 +157,11 @@ class Inbox extends \Zotlabs\Web\Controller {
case 'Delete':
case 'Add':
case 'Remove':
case 'Announce':
break;
case 'Announce':
as_announce_action($channel,$observer_hash,$AS);
continue;
default:
break;
......
......@@ -232,13 +232,14 @@ function asdecode_taxonomy($item) {
$ret = [];
if($item['tag']) {
logger(print_r($item['tag'],true));
foreach($item['tag'] as $t) {
if(! array_key_exists('type',$t))
$t['type'] = 'Hashtag';
switch($t['type']) {
case 'Hashtag':
$ret[] = [ 'ttype' => TERM_HASHTAG, 'url' => $t['id'], 'term' => ((substr($t['name'],0,1) === '#') ? substr($t['name'],1) : $t['name']) ];
$ret[] = [ 'ttype' => TERM_HASHTAG, 'url' => $t['href'], 'term' => ((substr($t['name'],0,1) === '#') ? substr($t['name'],1) : $t['name']) ];
break;
case 'Mention':
......@@ -453,13 +454,29 @@ function asencode_person($p) {
if($p['xchan_addr'] && strpos($p['xchan_addr'],'@'))
$ret['preferredUsername'] = substr($p['xchan_addr'],0,strpos($p['xchan_addr'],'@'));
$ret['name'] = $p['xchan_name'];
$ret['icon'] = [
'type' => 'Image',
'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png' ),
'url' => $p['xchan_photo_l'],
'height' => 300,
'width' => 300,
];
$ret['icon'] = [
[
'type' => 'Image',
'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png' ),
'url' => $p['xchan_photo_l'],
'height' => 300,
'width' => 300,
],
[
'type' => 'Image',
'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png' ),
'url' => $p['xchan_photo_m'],
'height' => 80,
'width' => 80,
],
[
'type' => 'Image',
'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png' ),
'url' => $p['xchan_photo_s'],
'height' => 48,
'width' => 48,
]
];
$ret['url'] = [
'type' => 'Link',
'mediaType' => 'text/html',
......@@ -972,6 +989,15 @@ function as_create_action($channel,$observer_hash,$act) {
}
function as_announce_action($channel,$observer_hash,$act) {
if(in_array($act->obj['type'], [ 'Announce' ])) {
as_announce_note($channel,$observer_hash,$act);
}
}
function as_like_action($channel,$observer_hash,$act) {
if(in_array($act->obj['type'], [ 'Note', 'Article' ])) {
......@@ -1115,6 +1141,114 @@ function as_create_note($channel,$observer_hash,$act) {
}
function as_announce_note($channel,$observer_hash,$act) {
logger(print_r($act,true));
$s = [];
if(! perm_is_allowed($channel['channel_id'],$observer_hash,'send_stream')) {
logger('no permission');
return;
}
$content = as_get_content($act->obj);
if(! $content) {
logger('no content');
return;
}
$s['owner_xchan'] = $s['author_xchan'] = $observer_hash;
$s['aid'] = $channel['channel_account_id'];
$s['uid'] = $channel['channel_id'];
$s['mid'] = urldecode($act->obj['id']);
if(! $s['created'])
$s['created'] = datetime_convert();
if(! $s['edited'])
$s['edited'] = $s['created'];
$s['parent_mid'] = $s['mid'];
$s['verb'] = ACTIVITY_POST;
$s['obj_type'] = ACTIVITY_OBJ_NOTE;
$s['app'] = t('ActivityPub');
$abook = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($observer_hash),
intval($channel['channel_id'])
);
if($abook) {
if(! post_is_importable($s,$abook[0])) {
logger('post is filtered');
return;
}
}
if($act->obj['conversation']) {
set_iconfig($s,'ostatus','conversation',$act->obj['conversation'],1);
}
$a = asdecode_taxonomy($act->obj);
if($a) {
$s['term'] = $a;
}
$a = asdecode_attachment($act->obj);
if($a) {
$s['attach'] = $a;
}
$body = "[share author='" . $act->sharee['name'] .
"' profile='" . $act->sharee['id'] .
"' avatar='" . $act->sharee['icon'][2]['url'] .
"' link='" . $act->obj['url'] .
"' posted='" . $act->obj['published'] .
"' message_id='" . $act->obj['id'] .
"']";
if($content['name'])
$body .= as_bb_content($content,'name') . "\r\n";
$body .= as_bb_content($content,'content');
if($act->obj['type'] === 'Note' && $s['attach']) {
foreach($s['attach'] as $img) {
if(strpos($img['type'],'image') !== false) {
$body .= "\n\n" . '[img]' . $img['href'] . '[/img]';
}
}
}
$body .= "[/share]";
$s['title'] = as_bb_content($content,'name');
$s['body'] = $body;
set_iconfig($s,'activitypub','recips',$act->raw_recips);
$r = q("select created, edited from item where mid = '%s' and uid = %d limit 1",
dbesc($s['mid']),
intval($s['uid'])
);
if($r) {
if($s['edited'] > $r[0]['edited']) {
$x = item_store_update($s);
}
else {
return;
}
}
else {
$x = item_store($s);
}
}
function as_like_note($channel,$observer_hash,$act) {
......
......@@ -144,7 +144,7 @@ function pubcrawl_discover_channel_webfinger(&$b) {
$person_obj = $AS->data;
}
elseif($AS->obj && $AS->obj['type'] === 'Person') {
$person_obj = $AS->object;
$person_obj = $AS->obj;
}
else {
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment