From 4b858650ced0d7648a3545a9da2c67a09222ccc6 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 5 Sep 2015 12:11:14 +0200 Subject: [PATCH 1/4] Check if the author should be ignored when fetching missing posts --- include/diaspora.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/diaspora.php b/include/diaspora.php index c874ded4a7..24d4d45da6 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -975,9 +975,21 @@ function diaspora_store_by_guid($guid, $server, $uid = 0) { $person = find_diaspora_person_by_handle($author); + $contact_id = get_contact($person['url'], $uid); + + $contacts = q("SELECT * FROM `contact` WHERE `id` = %d", intval($contact_id)); + $importers = q("SELECT * FROM `user` WHERE `uid` = %d", intval($uid)); + + if ($contacts AND $importers) + if(!diaspora_post_allow($importers[0],$contacts[0], false)) { + logger('Ignoring author '.$person['url'].' for uid '.$uid); + return false; + } else + logger('Author '.$person['url'].' is allowed for uid '.$uid); + $datarray = array(); $datarray['uid'] = $uid; - $datarray['contact-id'] = get_contact($person['url'], $uid); + $datarray['contact-id'] = $contact_id; $datarray['wall'] = 0; $datarray['network'] = NETWORK_DIASPORA; $datarray['guid'] = $guid; From 988f32dfc84efc0e038c813e2647f6497bfd3aa9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 5 Sep 2015 13:26:14 +0200 Subject: [PATCH 2/4] Rearranged the dispatcher --- include/diaspora.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 24d4d45da6..96c5b64e13 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -22,6 +22,12 @@ function diaspora_dispatch_public($msg) { return; } + // Use a dummy importer to import the data for the public copy + $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE); + $result = diaspora_dispatch($importer,$msg); + logger("Dispatcher reported ".$result, LOGGER_DEBUG); + + // Now distribute it to the followers $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 AND `account_removed` = 0 ", @@ -34,15 +40,8 @@ function diaspora_dispatch_public($msg) { diaspora_dispatch($rr,$msg); } } - else { + else logger('diaspora_public: no subscribers for '.$msg["author"].' '.print_r($msg, true)); - - // Use a dummy importer - $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE); - $result = diaspora_dispatch($importer,$msg); - - logger("Dispatcher reported ".$result, LOGGER_DEBUG); - } } From c555b1b5cb7d4ced14c47582dd79662e2cd4defa Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 6 Sep 2015 07:34:51 +0200 Subject: [PATCH 3/4] Only look for the GUID when checking for duplicates. --- include/diaspora.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 96c5b64e13..3145c52ea3 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -845,9 +845,8 @@ function diaspora_post($importer,$xml,$msg) { } $message_id = $diaspora_handle . ':' . $guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer['uid']), - dbesc($message_id), dbesc($guid) ); if(count($r)) { @@ -964,9 +963,8 @@ function diaspora_store_by_guid($guid, $server, $uid = 0) { $objecttype = $item["object-type"]; $message_id = $author.':'.$guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), - dbesc($message_id), dbesc($guid) ); if(count($r)) @@ -1134,9 +1132,8 @@ function diaspora_reshare($importer,$xml,$msg) { } $message_id = $diaspora_handle . ':' . $guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer['uid']), - dbesc($message_id), dbesc($guid) ); if(count($r)) { @@ -1320,9 +1317,8 @@ function diaspora_asphoto($importer,$xml,$msg) { } $message_id = $diaspora_handle . ':' . $guid; - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", + $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer['uid']), - dbesc($message_id), dbesc($guid) ); if(count($r)) { From f918109351cf5fe4103574b3799282c56ec11606 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 6 Sep 2015 08:18:55 +0200 Subject: [PATCH 4/4] We forgot to include the title ... --- mod/p.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mod/p.php b/mod/p.php index 6bae992565..5c4b619840 100644 --- a/mod/p.php +++ b/mod/p.php @@ -19,7 +19,7 @@ function p_init($a){ $guid = strtolower(substr($guid, 0, -4)); - $item = q("SELECT `body`, `guid`, `contact-id`, `private`, `created`, `app` FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", + $item = q("SELECT `title`, `body`, `guid`, `contact-id`, `private`, `created`, `app` FROM `item` WHERE `uid` = 0 AND `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", dbesc($guid), NETWORK_DFRN, NETWORK_DIASPORA); if (!$item) { header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found')); @@ -39,8 +39,14 @@ function p_init($a){ $post["public"] = (!$item[0]["private"] ? 'true':'false'); $post["created_at"] = datetime_convert('UTC','UTC',$item[0]["created"]); } else { + + $body = bb2diaspora($item[0]["body"]); + + if(strlen($item[0]["title"])) + $body = "## ".html_entity_decode($item[0]["title"])."\n\n".$body; + $nodename = "status_message"; - $post["raw_message"] = str_replace("&", "&", bb2diaspora($item[0]["body"])); + $post["raw_message"] = str_replace("&", "&", $body); $post["guid"] = $item[0]["guid"]; $post["diaspora_handle"] = diaspora_handle_from_contact($item[0]["contact-id"]); $post["public"] = (!$item[0]["private"] ? 'true':'false');