Bugfix: Diaspora retractions not always worked
This commit is contained in:
parent
7430e83679
commit
80d787d990
2 changed files with 52 additions and 25 deletions
|
@ -427,6 +427,18 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process item retractions. This has to be done separated from the other stuff,
|
||||||
|
// since retractions for comments could come even from non followers.
|
||||||
|
if (!empty($fields) && in_array($fields->getName(), array('retraction'))) {
|
||||||
|
$target = notags(unxmlify($fields->target_type));
|
||||||
|
if (in_array($target, array("Comment", "Like", "Post", "Reshare", "StatusMessage"))) {
|
||||||
|
logger('processing retraction for '.$target, LOGGER_DEBUG);
|
||||||
|
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
|
||||||
|
$message_id = self::dispatch($importer, $msg, $fields);
|
||||||
|
return $message_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now distribute it to the followers
|
// Now distribute it to the followers
|
||||||
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
|
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
|
||||||
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
|
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
|
||||||
|
@ -2462,42 +2474,52 @@ class Diaspora {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($contact["url"])) {
|
if (empty($contact["url"])) {
|
||||||
$contact["url"] = $person["url"];
|
$contact["url"] = $person["url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `id`, `parent`, `parent-uri`, `author-link` FROM `item` WHERE `guid` = '%s' AND `uid` = %d AND NOT `file` LIKE '%%[%%' LIMIT 1",
|
// Fetch items that are about to be deleted
|
||||||
dbesc($target_guid),
|
$fields = array('uid', 'id', 'parent', 'parent-uri');
|
||||||
intval($importer["uid"])
|
|
||||||
);
|
// When we receive a public retraction, we delete every item that we find.
|
||||||
if (!$r) {
|
if ($importer['uid'] == 0) {
|
||||||
logger("Target guid ".$target_guid." was not found for user ".$importer["uid"]);
|
$condition = array("`guid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid);
|
||||||
|
} else {
|
||||||
|
$condition = array("`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']);
|
||||||
|
}
|
||||||
|
$r = dba::select('item', $fields, $condition);
|
||||||
|
if (!dbm::is_result($r)) {
|
||||||
|
logger("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the sender is the thread owner
|
while ($item = dba::fetch($r)) {
|
||||||
$p = q("SELECT `id`, `author-link`, `origin` FROM `item` WHERE `id` = %d",
|
// Fetch the parent item
|
||||||
intval($r[0]["parent"]));
|
$parent = dba::select('item', array('author-link', 'origin'), array('id' => $item["parent"]), array('limit' => 1));
|
||||||
|
|
||||||
// Only delete it if the parent author really fits
|
// Only delete it if the parent author really fits
|
||||||
if (!link_compare($p[0]["author-link"], $contact["url"]) && !link_compare($r[0]["author-link"], $contact["url"])) {
|
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
|
||||||
logger("Thread author ".$p[0]["author-link"]." and item author ".$r[0]["author-link"]." don't fit to expected contact ".$contact["url"], LOGGER_DEBUG);
|
logger("Thread author ".$parent["author-link"]." and item author ".$item["author-link"]." don't fit to expected contact ".$contact["url"], LOGGER_DEBUG);
|
||||||
return false;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// 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
|
||||||
dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
|
dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
|
||||||
'edited' => datetime_convert(), 'changed' => datetime_convert()),
|
'edited' => datetime_convert(), 'changed' => datetime_convert()),
|
||||||
array('id' => $r[0]["id"]));
|
array('id' => $item["id"]));
|
||||||
|
|
||||||
delete_thread($r[0]["id"], $r[0]["parent-uri"]);
|
// Delete the thread - if it is a starting post and not a comment
|
||||||
|
if ($target_type != 'Comment') {
|
||||||
|
delete_thread($item["id"], $item["parent-uri"]);
|
||||||
|
}
|
||||||
|
|
||||||
logger("Deleted target ".$target_guid." (".$r[0]["id"].") from user ".$importer["uid"]." parent: ".$p[0]["id"], LOGGER_DEBUG);
|
logger("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], LOGGER_DEBUG);
|
||||||
|
|
||||||
// Now check if the retraction needs to be relayed by us
|
// Now check if the retraction needs to be relayed by us
|
||||||
if ($p[0]["origin"]) {
|
if ($parent["origin"]) {
|
||||||
// notify others
|
// notify others
|
||||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $r[0]["id"]);
|
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $item["id"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -240,6 +240,11 @@ function delete_thread_uri($itemuri, $uid) {
|
||||||
function delete_thread($itemid, $itemuri = "") {
|
function delete_thread($itemid, $itemuri = "") {
|
||||||
$item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid));
|
$item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid));
|
||||||
|
|
||||||
|
if (!dbm::is_result($item)) {
|
||||||
|
logger('No thread found for id '.$itemid, LOGGER_DEBUG);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Using dba::delete at this time could delete the associated item entries
|
// Using dba::delete at this time could delete the associated item entries
|
||||||
$result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid));
|
$result = q("DELETE FROM `thread` WHERE `iid` = %d", intval($itemid));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue