Some work at the retractions.
This commit is contained in:
parent
1f7f964bb7
commit
66919761ab
2 changed files with 230 additions and 159 deletions
|
@ -116,13 +116,13 @@ function diaspora_dispatch($importer,$msg,$attempt=1) {
|
||||||
$ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
|
$ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
|
||||||
}
|
}
|
||||||
elseif($xmlbase->signed_retraction) {
|
elseif($xmlbase->signed_retraction) {
|
||||||
//$tempfile = tempnam(get_temppath(), "diaspora-signed_retraction");
|
$tempfile = tempnam(get_temppath(), "diaspora-signed_retraction");
|
||||||
//file_put_contents($tempfile, json_encode($data));
|
file_put_contents($tempfile, json_encode($data));
|
||||||
$ret = diaspora_signed_retraction($importer,$xmlbase->signed_retraction,$msg);
|
$ret = diaspora_signed_retraction($importer,$xmlbase->signed_retraction,$msg);
|
||||||
}
|
}
|
||||||
elseif($xmlbase->relayable_retraction) {
|
elseif($xmlbase->relayable_retraction) {
|
||||||
//$tempfile = tempnam(get_temppath(), "diaspora-relayable_retraction");
|
$tempfile = tempnam(get_temppath(), "diaspora-relayable_retraction");
|
||||||
//file_put_contents($tempfile, json_encode($data));
|
file_put_contents($tempfile, json_encode($data));
|
||||||
$ret = diaspora_signed_retraction($importer,$xmlbase->relayable_retraction,$msg);
|
$ret = diaspora_signed_retraction($importer,$xmlbase->relayable_retraction,$msg);
|
||||||
}
|
}
|
||||||
elseif($xmlbase->photo) {
|
elseif($xmlbase->photo) {
|
||||||
|
|
|
@ -95,11 +95,11 @@ class diaspora {
|
||||||
$type = $fields->getName();
|
$type = $fields->getName();
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case "account_deletion":
|
case "account_deletion": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_account_deletion($importer, $fields);
|
//return self::import_account_deletion($importer, $fields);
|
||||||
|
|
||||||
case "comment":
|
case "comment": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_comment($importer, $sender, $fields);
|
//return self::import_comment($importer, $sender, $fields);
|
||||||
|
|
||||||
|
@ -107,40 +107,40 @@ class diaspora {
|
||||||
return true;
|
return true;
|
||||||
//return self::import_conversation($importer, $fields);
|
//return self::import_conversation($importer, $fields);
|
||||||
|
|
||||||
case "like":
|
case "like": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_like($importer, $sender, $fields);
|
//return self::import_like($importer, $sender, $fields);
|
||||||
|
|
||||||
case "message":
|
case "message": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_message($importer, $fields);
|
//return self::import_message($importer, $fields);
|
||||||
|
|
||||||
case "participation": // Not implemented
|
case "participation": // Not implemented
|
||||||
return self::import_participation($importer, $fields);
|
return self::import_participation($importer, $fields);
|
||||||
|
|
||||||
case "photo":
|
case "photo": // Not needed
|
||||||
return self::import_photo($importer, $fields);
|
return self::import_photo($importer, $fields);
|
||||||
|
|
||||||
case "poll_participation": // Not implemented
|
case "poll_participation": // Not implemented
|
||||||
return self::import_poll_participation($importer, $fields);
|
return self::import_poll_participation($importer, $fields);
|
||||||
|
|
||||||
case "profile":
|
case "profile": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_profile($importer, $fields);
|
//return self::import_profile($importer, $fields);
|
||||||
|
|
||||||
case "request":
|
case "request":
|
||||||
return self::import_request($importer, $fields);
|
return self::import_request($importer, $fields);
|
||||||
|
|
||||||
case "reshare":
|
case "reshare": // Done
|
||||||
return true;
|
return true;
|
||||||
//return self::import_reshare($importer, $fields);
|
//return self::import_reshare($importer, $fields);
|
||||||
|
|
||||||
case "retraction":
|
case "retraction":
|
||||||
return self::import_retraction($importer, $fields);
|
return self::import_retraction($importer, $fields);
|
||||||
|
|
||||||
case "status_message":
|
case "status_message": // Done
|
||||||
//return true;
|
return true;
|
||||||
return self::import_status_message($importer, $fields);
|
//return self::import_status_message($importer, $fields);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logger("Unknown message type ".$type);
|
logger("Unknown message type ".$type);
|
||||||
|
@ -703,14 +703,14 @@ class diaspora {
|
||||||
$conversation = null;
|
$conversation = null;
|
||||||
|
|
||||||
$c = q("select * from conv where uid = %d and guid = '%s' limit 1",
|
$c = q("select * from conv where uid = %d and guid = '%s' limit 1",
|
||||||
intval($importer['uid']),
|
intval($importer["uid"]),
|
||||||
dbesc($guid)
|
dbesc($guid)
|
||||||
);
|
);
|
||||||
if(count($c))
|
if(count($c))
|
||||||
$conversation = $c[0];
|
$conversation = $c[0];
|
||||||
else {
|
else {
|
||||||
$r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
|
$r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||||
intval($importer['uid']),
|
intval($importer["uid"]),
|
||||||
dbesc($guid),
|
dbesc($guid),
|
||||||
dbesc($diaspora_handle),
|
dbesc($diaspora_handle),
|
||||||
dbesc(datetime_convert('UTC','UTC',$created_at)),
|
dbesc(datetime_convert('UTC','UTC',$created_at)),
|
||||||
|
@ -720,7 +720,7 @@ class diaspora {
|
||||||
);
|
);
|
||||||
if($r)
|
if($r)
|
||||||
$c = q("select * from conv where uid = %d and guid = '%s' limit 1",
|
$c = q("select * from conv where uid = %d and guid = '%s' limit 1",
|
||||||
intval($importer['uid']),
|
intval($importer["uid"]),
|
||||||
dbesc($guid)
|
dbesc($guid)
|
||||||
);
|
);
|
||||||
if(count($c))
|
if(count($c))
|
||||||
|
@ -755,15 +755,15 @@ class diaspora {
|
||||||
|
|
||||||
$author_signature = base64_decode($msg_author_signature);
|
$author_signature = base64_decode($msg_author_signature);
|
||||||
|
|
||||||
if(strcasecmp($msg_diaspora_handle,$msg['author']) == 0) {
|
if(strcasecmp($msg_diaspora_handle,$msg["author"]) == 0) {
|
||||||
$person = $contact;
|
$person = $contact;
|
||||||
$key = $msg['key'];
|
$key = $msg["key"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$person = find_diaspora_person_by_handle($msg_diaspora_handle);
|
$person = find_diaspora_person_by_handle($msg_diaspora_handle);
|
||||||
|
|
||||||
if(is_array($person) && x($person,'pubkey'))
|
if(is_array($person) && x($person,'pubkey'))
|
||||||
$key = $person['pubkey'];
|
$key = $person["pubkey"];
|
||||||
else {
|
else {
|
||||||
logger('diaspora_conversation: unable to find author details');
|
logger('diaspora_conversation: unable to find author details');
|
||||||
continue;
|
continue;
|
||||||
|
@ -780,7 +780,7 @@ class diaspora {
|
||||||
|
|
||||||
$parent_author_signature = base64_decode($msg_parent_author_signature);
|
$parent_author_signature = base64_decode($msg_parent_author_signature);
|
||||||
|
|
||||||
$key = $msg['key'];
|
$key = $msg["key"];
|
||||||
|
|
||||||
if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
|
if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
|
||||||
logger('diaspora_conversation: owner verification failed.');
|
logger('diaspora_conversation: owner verification failed.');
|
||||||
|
@ -797,13 +797,13 @@ class diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
q("insert into mail ( `uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) values ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
|
q("insert into mail ( `uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) values ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
|
||||||
intval($importer['uid']),
|
intval($importer["uid"]),
|
||||||
dbesc($msg_guid),
|
dbesc($msg_guid),
|
||||||
intval($conversation['id']),
|
intval($conversation["id"]),
|
||||||
dbesc($person['name']),
|
dbesc($person["name"]),
|
||||||
dbesc($person['photo']),
|
dbesc($person["photo"]),
|
||||||
dbesc($person['url']),
|
dbesc($person["url"]),
|
||||||
intval($contact['id']),
|
intval($contact["id"]),
|
||||||
dbesc($subject),
|
dbesc($subject),
|
||||||
dbesc($body),
|
dbesc($body),
|
||||||
0,
|
0,
|
||||||
|
@ -815,20 +815,20 @@ class diaspora {
|
||||||
|
|
||||||
q("update conv set updated = '%s' where id = %d",
|
q("update conv set updated = '%s' where id = %d",
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
intval($conversation['id'])
|
intval($conversation["id"])
|
||||||
);
|
);
|
||||||
|
|
||||||
notification(array(
|
notification(array(
|
||||||
'type' => NOTIFY_MAIL,
|
'type' => NOTIFY_MAIL,
|
||||||
'notify_flags' => $importer['notify-flags'],
|
'notify_flags' => $importer["notify-flags"],
|
||||||
'language' => $importer['language'],
|
'language' => $importer["language"],
|
||||||
'to_name' => $importer['username'],
|
'to_name' => $importer["username"],
|
||||||
'to_email' => $importer['email'],
|
'to_email' => $importer["email"],
|
||||||
'uid' =>$importer['uid'],
|
'uid' =>$importer["uid"],
|
||||||
'item' => array('subject' => $subject, 'body' => $body),
|
'item' => array('subject' => $subject, 'body' => $body),
|
||||||
'source_name' => $person['name'],
|
'source_name' => $person["name"],
|
||||||
'source_link' => $person['url'],
|
'source_link' => $person["url"],
|
||||||
'source_photo' => $person['thumb'],
|
'source_photo' => $person["thumb"],
|
||||||
'verb' => ACTIVITY_POST,
|
'verb' => ACTIVITY_POST,
|
||||||
'otype' => 'mail'
|
'otype' => 'mail'
|
||||||
));
|
));
|
||||||
|
@ -1420,7 +1420,78 @@ print_r($data);
|
||||||
return $message_id;
|
return $message_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function item_retraction($importer, $contact, $data) {
|
||||||
|
$target_guid = notags(unxmlify($data->target_guid));
|
||||||
|
|
||||||
|
$r = q("SELECT `id`, `parent`, `parent-uri`, `author-link` FROM `item` WHERE `guid` = '%s' AND `uid` = %d AND NOT `file` LIKE '%%[%%' LIMIT 1",
|
||||||
|
dbesc($target_guid),
|
||||||
|
intval($importer["uid"])
|
||||||
|
);
|
||||||
|
if (!$r)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Only delete it if the author really fits
|
||||||
|
if (!link_compare($r[0]["author-link"],$contact["url"]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Currently we don't have a central deletion function that we could use in this case. The function "item_drop" doesn't work for that case
|
||||||
|
q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' WHERE `id` = %d",
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
dbesc(datetime_convert()),
|
||||||
|
intval($r[0]["id"])
|
||||||
|
);
|
||||||
|
delete_thread($r[0]["id"], $r[0]["parent-uri"]);
|
||||||
|
|
||||||
|
// Now check if the retraction needs to be relayed by us
|
||||||
|
//
|
||||||
|
// The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
|
||||||
|
// return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
|
||||||
|
// The only item with `parent` and `id` as the parent id is the parent item.
|
||||||
|
$p = q("SELECT `origin` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1",
|
||||||
|
intval($r[0]["parent"]),
|
||||||
|
intval($r[0]["parent"])
|
||||||
|
);
|
||||||
|
if(count($p)) {
|
||||||
|
if($p[0]["origin"]) {
|
||||||
|
|
||||||
|
// Formerly we stored the signed text, the signature and the author in different fields.
|
||||||
|
// The new Diaspora protocol can have variable fields. We now store the data in correct order in a single field.
|
||||||
|
q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
|
||||||
|
intval($r[0]["id"]),
|
||||||
|
dbesc(json_encode($data))
|
||||||
|
);
|
||||||
|
|
||||||
|
// the existence of parent_author_signature would have meant the parent_author or owner
|
||||||
|
// is already relaying.
|
||||||
|
logger("relaying retraction");
|
||||||
|
|
||||||
|
proc_run("php", "include/notifier.php", "drop", $r[0]["id"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function import_retraction($importer, $data) {
|
private function import_retraction($importer, $data) {
|
||||||
|
$target_type = notags(unxmlify($data->target_type));
|
||||||
|
$author = notags(unxmlify($data->author));
|
||||||
|
|
||||||
|
$contact = self::get_contact_by_handle($importer["uid"], $author);
|
||||||
|
if (!$contact) {
|
||||||
|
logger("cannot find contact for author: ".$author);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($target_type) {
|
||||||
|
case "Comment": case "Like": case "StatusMessage":
|
||||||
|
self::item_retraction($importer, $contact, $data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Person":
|
||||||
|
contact_remove($contact["id"]);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
logger("Unknown target type ".$target_type);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1434,11 +1505,11 @@ print_r($data);
|
||||||
$provider_display_name = notags(unxmlify($data->provider_display_name));
|
$provider_display_name = notags(unxmlify($data->provider_display_name));
|
||||||
|
|
||||||
/// @todo enable support for polls
|
/// @todo enable support for polls
|
||||||
if ($data->poll) {
|
//if ($data->poll) {
|
||||||
foreach ($data->poll AS $poll)
|
// foreach ($data->poll AS $poll)
|
||||||
print_r($poll);
|
// print_r($poll);
|
||||||
die("poll!\n");
|
// die("poll!\n");
|
||||||
}
|
//}
|
||||||
$contact = self::get_allowed_contact_by_handle($importer, $author, false);
|
$contact = self::get_allowed_contact_by_handle($importer, $author, false);
|
||||||
if (!$contact)
|
if (!$contact)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue