From 75f5cfe63e2d84fbe55384a7b2769c55bbf423b6 Mon Sep 17 00:00:00 2001
From: Michael Vogel <icarus@dabo.de>
Date: Sun, 13 Mar 2016 21:11:48 +0100
Subject: [PATCH] Retraction and reshares work

---
 include/diaspora2.php | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/include/diaspora2.php b/include/diaspora2.php
index b031651675..f6b8b9a704 100644
--- a/include/diaspora2.php
+++ b/include/diaspora2.php
@@ -1628,6 +1628,8 @@ class diaspora {
 		if (!$original_item)
 			return false;
 
+		$orig_url = App::get_baseurl()."/display/".$original_item["guid"];
+
 		$datarray = array();
 
 		$datarray["uid"] = $importer["uid"];
@@ -1651,7 +1653,7 @@ class diaspora {
 		$datarray["object"] = json_encode($data);
 
 		$prefix = share_header($original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"],
-					$original_item["guid"], $original_item["created"], $original_item["uri"]);
+					$original_item["guid"], $original_item["created"], $orig_url);
 		$datarray["body"] = $prefix.$original_item["body"]."[/share]";
 
 		$datarray["tag"] = $original_item["tag"];
@@ -1691,16 +1693,20 @@ class diaspora {
 			return false;
 
 		// Only delete it if the author really fits
-		if (!link_compare($r[0]["author-link"],$person["url"]))
+		if (!link_compare($r[0]["author-link"], $person["url"])) {
+			logger("Item author ".$r[0]["author-link"]." doesn't fit to expected contact ".$person["url"], LOGGER_DEBUG);
 			return false;
+		}
 
 		// Check if the sender is the thread owner
 		$p = q("SELECT `author-link`, `origin` FROM `item` WHERE `id` = %d",
 			intval($r[0]["parent"]));
 
 		// Only delete it if the parent author really fits
-		if (!link_compare($p[0]["author-link"], $contact["url"]))
+		if (!link_compare($p[0]["author-link"], $contact["url"]) AND !link_compare($r[0]["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);
 			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",
@@ -1736,6 +1742,8 @@ class diaspora {
 			return false;
 		}
 
+		logger("Got retraction for ".$target_type.", sender ".$sender." and user ".$importer["uid"], LOGGER_DEBUG);
+
 		switch ($target_type) {
 			case "Comment":
 			case "Like":
-- 
2.39.5