Commit b4e1a1d3 authored by Zot's avatar Zot

some work on diaspora event attendance, but there's a very long way to go....

some work on diaspora event attendance, but there's a very long way to go. Started by copying the like code and modifying it, but it looks entirely possible that we have 3rd party permission issues with the like code. Need a lot more caffeine before resuming.
parent 81f29e9e
......@@ -1400,6 +1400,8 @@ class Diaspora_Receiver {
return;
}
// @fixme - check 3rd party like permissions. E.g. fred@server1 is liking something posted by bob@server2 which you (mick@server3) receive a copy
if((! $this->importer['system']) && (! perm_is_allowed($this->importer['channel_id'],$contact['xchan_hash'],'post_comments'))) {
logger('diaspora_like: Ignoring this author.');
......@@ -1825,6 +1827,293 @@ class Diaspora_Receiver {
}
function event() {
$diaspora_handle = notags($this->get_author());
// not currently handled
logger('event: ' . print_r($this->xmlbase,true), LOGGER_DATA);
}
function event_participation() {
logger('event_participation: ' . print_r($this->xmlbase,true), LOGGER_DATA);
// not yet ready for prime time
return;
$guid = notags($this->get_property('guid'));
$parent_guid = notags($this->get_property('parent_guid'));
$diaspora_handle = notags($this->get_author());
$status = notags($this->get_property('status'));
$author_signature = notags($this->get_property('author_signature'));
$parent_author_signature = $this->get_property('parent_author_signature');
$xchan = find_diaspora_person_by_handle($diaspora_handle);
if(! $xchan) {
logger('Cannot resolve diaspora handle ' . $diaspora_handle);
return;
}
$contact = diaspora_get_contact_by_handle($this->importer['channel_id'],$this->msg['author']);
$pubcomment = get_pconfig($this->importer['channel_id'],'system','diaspora_public_comments',1);
// by default comments on public posts are allowed from anybody on Diaspora. That is their policy.
// Once this setting is set to something we'll track your preference and it will over-ride the default.
if(($pubcomment) && (! $contact))
$contact = find_diaspora_person_by_handle($this->msg['author']);
// find a message owned by this channel and holding the referenced event
$r = q("select item.mid, item.id from item left join iconfig on iconfig.iid = item.id where cat = 'system' and k = 'event_id' and v = '%s' and item.uid = '%d' limit 1",
dbesc($parent_guid),
dbesc($this->importer['channel_id'])
);
if(! $r) {
logger('event ' . $parent_guid . ' not found.');
return;
}
$item_id = $r[0]['id'];
if(! $contact) {
logger('cannot find contact: ' . $this->msg['author'] . ' for channel ' . $this->importer['channel_name']);
return;
}
switch ($status) {
case 'accepted':
$verb = ACTIVITY_ATTEND;
break;
case 'declined':
$verb = ACTIVITY_ATTENDNO;
break;
case 'tentative':
default:
$verb = ACTIVITY_ATTENDMAYBE;
break;
}
// if((! $this->importer['system']) && (! perm_is_allowed($this->importer['channel_id'],$contact['xchan_hash'],'post_comments'))) {
// logger('diaspora_like: Ignoring this author.');
// return 202;
// }
$r = q("SELECT * FROM item WHERE uid = %d AND id = '%s' LIMIT 1",
intval($this->importer['channel_id']),
intval($item_id)
);
if(! $r) {
logger('parent post not found: ' . $guid);
return;
}
xchan_query($r);
$parent_item = $r[0];
if(intval($parent_item['item_nocomment']) || $parent_item['comment_policy'] === 'none'
|| ($parent_item['comments_closed'] > NULL_DATE && $parent_item['comments_closed'] < datetime_convert())) {
logger('comments disabled for post ' . $parent_item['mid']);
return;
}
$r = q("SELECT * FROM item WHERE uid = %d AND mid = '%s' LIMIT 1",
intval($this->importer['channel_id']),
dbesc($guid)
);
if($r) {
if($positive === 'true') {
logger('diaspora_like: duplicate like: ' . $guid);
return;
}
// Note: I don't think "Like" objects with positive = "false" are ever actually used
// It looks like "RelayableRetractions" are used for "unlike" instead
if($positive === 'false') {
logger('diaspora_like: received a like with positive set to "false"...ignoring');
// perhaps call drop_item()
// FIXME--actually don't unless it turns out that Diaspora does indeed send out "false" likes
// send notification via proc_run()
return;
}
}
$i = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($parent_item['author_xchan'])
);
if($i)
$item_author = $i[0];
// Note: I don't think "Like" objects with positive = "false" are ever actually used
// It looks like "RelayableRetractions" are used for "unlike" instead
if($positive === 'true')
$activity = ACTIVITY_LIKE;
else
$activity = ACTIVITY_DISLIKE;
// old style signature
$signed_data = $positive . ';' . $guid . ';' . $target_type . ';' . $parent_guid . ';' . $diaspora_handle;
$key = $this->msg['key'];
if($parent_author_signature) {
// If a parent_author_signature exists, then we've received the like
// relayed from the top-level post owner.
$x = diaspora_verify_fields($this->xmlbase,$parent_author_signature,$key);
if(! $x) {
logger('diaspora_like: top-level owner verification failed.');
return;
}
}
else {
// If there's no parent_author_signature, then we've received the like
// from the like creator. In that case, the person is "like"ing
// our post, so he/she must be a contact of ours and his/her public key
// should be in $this->msg['key']
$x = diaspora_verify_fields($this->xmlbase,$author_signature,$key);
if(! $x) {
logger('diaspora_like: author verification failed.');
return;
}
if(defined('DIASPORA_V2'))
$this->xmlbase['parent_author_signature'] = diaspora_sign_fields($this->xmlbase,$this->importer['channel_prvkey']);
}
logger('diaspora_like: signature check complete.',LOGGER_DEBUG);
// Phew! Everything checks out. Now create an item.
// Find the original comment author information.
// We need this to make sure we display the comment author
// information (name and avatar) correctly.
if(strcasecmp($diaspora_handle,$this->msg['author']) == 0)
$person = $contact;
else {
$person = find_diaspora_person_by_handle($diaspora_handle);
if(! is_array($person)) {
logger('diaspora_like: unable to find author details');
return;
}
}
$uri = $diaspora_handle . ':' . $guid;
$post_type = (($parent_item['resource_type'] === 'photo') ? t('photo') : t('status'));
$links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $parent_item['plink']));
$objtype = (($parent_item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
$body = $parent_item['body'];
$object = json_encode(array(
'type' => $post_type,
'id' => $parent_item['mid'],
'parent' => (($parent_item['thr_parent']) ? $parent_item['thr_parent'] : $parent_item['parent_mid']),
'link' => $links,
'title' => $parent_item['title'],
'content' => $parent_item['body'],
'created' => $parent_item['created'],
'edited' => $parent_item['edited'],
'author' => array(
'name' => $item_author['xchan_name'],
'address' => $item_author['xchan_addr'],
'guid' => $item_author['xchan_guid'],
'guid_sig' => $item_author['xchan_guid_sig'],
'link' => array(
array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item_author['xchan_url']),
array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])),
),
));
$bodyverb = t('%1$s likes %2$s\'s %3$s');
$arr = array();
$arr['uid'] = $this->importer['channel_id'];
$arr['aid'] = $this->importer['channel_account_id'];
$arr['mid'] = $guid;
$arr['parent_mid'] = $parent_item['mid'];
if($parent_item['mid'] !== $parent_guid)
$arr['thr_parent'] = $parent_guid;
$arr['owner_xchan'] = $parent_item['owner_xchan'];
$arr['author_xchan'] = $person['xchan_hash'];
$ulink = '[url=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/url]';
$alink = '[url=' . $parent_item['author']['xchan_url'] . ']' . $parent_item['author']['xchan_name'] . '[/url]';
$plink = '[url='. z_root() .'/display/'.$guid.']'.$post_type.'[/url]';
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
$arr['app'] = 'Diaspora';
// set the route to that of the parent so downstream hubs won't reject it.
$arr['route'] = $parent_item['route'];
$arr['item_private'] = $parent_item['item_private'];
$arr['verb'] = $activity;
$arr['obj_type'] = $objtype;
$arr['obj'] = $object;
$oldxml = array_map('unxmlify',$this->xmlbase);
if($oldxml) {
$unxml = [];
foreach($oldxml as $k => $v) {
if($k === 'diaspora_handle')
$k = 'author';
if($k === 'target_type')
$k = 'parent_type';
$unxml[$k] = $v;
}
}
set_iconfig($arr,'diaspora','fields',$unxml,true);
$result = item_store($arr);
if($result['success']) {
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if(intval($parent_item['item_origin']) && (! $parent_author_signature))
Zotlabs\Daemon\Master::Summon(array('Notifier','comment-import',$result['item_id']));
sync_an_item($this->importer['channel_id'],$result['item_id']);
}
return;
}
function participation() {
$diaspora_handle = notags($this->get_author());
......
......@@ -152,6 +152,14 @@ function diaspora_dispatch($importer,$msg) {
$base = $xmlbase['participation'];
$fn = 'participation';
}
elseif($xmlbase['event']) {
$base = $xmlbase['event'];
$fn = 'event';
}
elseif($xmlbase['event_participation']) {
$base = $xmlbase['event_participation'];
$fn = 'event_participation';
}
elseif($xmlbase['account_deletion']) {
$base = $xmlbase['account_deletion'];
$fn = 'account_deletion';
......
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