]> git.mxchange.org Git - friendica.git/commitdiff
Fix bugs in the retraction code
authorZach Prezkuta <fermion@gmx.com>
Sat, 2 Jun 2012 22:11:31 +0000 (16:11 -0600)
committerZach Prezkuta <fermion@gmx.com>
Sun, 3 Jun 2012 20:53:30 +0000 (14:53 -0600)
Currently, the following seems to be the functional status:
For a Diaspora top-level post:
Friendica comments show up AND delete
Diaspora comments show up AND delete for top-level owner
Diaspora comments show up for non-owner
Diaspora comments sometimes don't delete for non-owner
-> Appears to be Diaspora's fault, as a "not a valid object" error shows up in the log

Friendica likes show up, but can't unlike (Friendica doesn't even message Diaspora)
Diaspora likes show up
Diaspora non-owner can't unlike
-> Same as comments, seems to be Diaspora's fault

For a Friendica top-level post:
Friendica comments show up AND delete
Diaspora comments show up AND delete

Friendica likes don't show up in Diaspora sometimes
Friendica doesn't even message Diaspora for unlikes (sometimes?)
Diaspora likes and unlikes work

include/delivery.php
include/diaspora.php
include/items.php
include/notifier.php
update.php
view/diaspora_like_relay.tpl [changed mode: 0644->0755]
view/diaspora_relayable_retraction.tpl [changed mode: 0644->0755]

index 62c9f92020f231965182e7f78f733085e8770e4c..235b766c5fb04d5813f5223ac401c0e17e3af0b4 100644 (file)
@@ -509,13 +509,13 @@ function delivery_run($argv, $argc){
                                        // unsupported
                                        break;
                                }
-                               elseif(($target_item['deleted']) && ($top_level) && ($target_item['verb'] !== ACTIVITY_LIKE)) {
+                               elseif(($target_item['deleted']) && ($target_item['uri'] === $target_item['parent-uri']) && ($target_item['verb'] !== ACTIVITY_LIKE)) {
                                logger('delivery: diaspora retract: ' . $loc);
                                        // diaspora delete, 
                                        diaspora_send_retraction($target_item,$owner,$contact,$public_message);
                                        break;
                                }
-                               elseif($target_item['parent'] != $target_item['id']) {
+                               elseif($target_item['uri'] !== $target_item['parent-uri']) {
 
                                logger('delivery: diaspora relay: ' . $loc);
 
index 584be5ef266d3db7879fe9afcd20e61720994128..10c56564b734998372f04f14143ae2be0aa4471d 100644 (file)
@@ -1168,22 +1168,7 @@ function diaspora_comment($importer,$xml,$msg) {
                );
        }
 
-       if(($parent_item['origin']) && (! $parent_author_signature)) {  if(($parent_item['origin']) && (! $parent_author_signature)) {
-               q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
-                       intval($message_id),
-                       dbesc($author_signed_data),
-                       dbesc(base64_encode($author_signature)),
-                       dbesc($diaspora_handle)
-               );
-
-               // 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.
-
-               proc_run('php','include/notifier.php','comment',$message_id);
-       }
-
-
+       if(($parent_item['origin']) && (! $parent_author_signature)) {
                q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
                        intval($message_id),
                        dbesc($author_signed_data),
@@ -1846,7 +1831,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
 
        }
 
-       if($type === 'StatusMessage' || $type === 'Comment') {
+       if($type === 'StatusMessage' || $type === 'Comment' || $type === 'Like') {
                $r = q("select * from item where guid = '%s' and uid = %d and not file like '%%[%%' limit 1",
                        dbesc($guid),
                        intval($importer['uid'])
@@ -1854,6 +1839,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
                if(count($r)) {
                        if(link_compare($r[0]['author-link'],$contact['url'])) {
                                q("update item set `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' where `id` = %d limit 1",
+                                       dbesc(datetime_convert()),                      
                                        dbesc(datetime_convert()),                      
                                        intval($r[0]['id'])
                                );
@@ -2184,16 +2170,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
 // I'm assuming for now that "$owner" will be the user of the top-level post for retractions too. Be
 // aware that another reasonable possibility is that it's the "$owner" of the deleted comment.
 
-// TODO
-// CHECK       1. If we receive a retraction from Diaspora to be relayed by us, we need to insert the signature
-//                into the DB and call notifier.php
-// CHECK       2. diaspora_send_retraction() needs to be modified to send
-//                Diaspora a retraction for it to relay when appropriate
-// CHECK       3. notifier.php (and delivery.php?) need to be modified to call the right functions for the right
-//                retraction situation
-// 4. If possible, modify notifier.php (and delivery.php?) to remove the relayable retraction's signature
-//    from the DB after finishing with relaying retractions
-
 
 
        $a = get_app();
@@ -2216,20 +2192,20 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
        $like = false;
        $relay_retract = false;
        $sql_sign_id = 'iid';
-       if($item['verb'] === ACTIVITY_LIKE) {
+       if( $item['deleted']) {
+               $tpl = get_markup_template('diaspora_relayable_retraction.tpl');
+               $relay_retract = true;
+               $sql_sign_id = 'retract_iid';
+               $target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
+       }
+       elseif($item['verb'] === ACTIVITY_LIKE) {
                $tpl = get_markup_template('diaspora_like_relay.tpl');
                $like = true;
                $target_type = 'Post';
                $positive = (($item['deleted']) ? 'false' : 'true');
        }
-       elseif(! $item['deleted']) {
-               $tpl = get_markup_template('diaspora_comment_relay.tpl');
-       }
        else {
-               $tpl = get_markup_template('diaspora_relayable_retraction.tpl');
-               $relay_retract = true;
-               $sql_sign_id = 'retract_iid';
-               $target_type = 'Comment';
+               $tpl = get_markup_template('diaspora_comment_relay.tpl');
        }
 
        $body = $item['body'];
index 8858ca64fab9a7c8946dbf59e8b03d21fc75b15d..897036c26f560fdb6a01e62d147289d30e732dc7 100644 (file)
@@ -3281,33 +3281,33 @@ function drop_item($id,$interactive = true) {
                        }
 
                        // Add a relayable_retraction signature for Diaspora. Note that we can't add a target_author_signature
-                       // if the comment was deleted by a remote user. That should be ok, because if a remote user is deleting
-                       // the comment, that means we're the home of the post, and Diaspora will only
+                       // if the comment/like was deleted by a remote user. That should be ok, because if a remote user is deleting
+                       // the comment/like, that means we're the home of the post, and Diaspora will only
                        // check the parent_author_signature of retractions that it doesn't have to relay further
-                       if( strcmp($item['type'], 'activity') != 0) {
-                               $signed_text = $item['guid'] . ';' . 'Comment';
+                       $signed_text = $item['guid'] . ';' . ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment');
 
-                               if(local_user() == $item['uid']) {
+                       if(local_user() == $item['uid']) {
 
-                                       $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
-                                       $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
-                               }
-                               else {
-                                       $r = q("SELECT `nick`, `url` FROM `contact` WHERE `id` = '%d' LIMIT 1",
-                                               $item['contact-id']
-                                       );
-                                       if(count($r))
-                                               $handle = $r['nick'] . '@' . substr($r['url'], strpos($r['url'],'://') + 3, strpos($r['url'],'/profile') - 1);
+                               $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
+                               $authorsig = base64_encode(rsa_sign($signed_text,$a->user['prvkey'],'sha256'));
+                       }
+                       else {
+                               $r = q("SELECT `nick`, `url` FROM `contact` WHERE `id` = '%d' LIMIT 1",
+                                       $item['contact-id']
+                               );
+                               if(count($r)) {
+                                       $handle = $r['nick'] . '@' . substr($r['url'], strpos($r['url'],'://') + 3, strpos($r['url'],'/profile') - 1);
+                                       $authorsig = '';
                                }
-
-                               if(isset($handle)
-                                       q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
-                                               intval($item['id']),
-                                               dbesc($signed_text),
-                                               dbesc($authorsig),
-                                               dbesc($handle)
-                                       );
                        }
+
+                       if(isset($handle))
+                               q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
+                                       intval($item['id']),
+                                       dbesc($signed_text),
+                                       dbesc($authorsig),
+                                       dbesc($handle)
+                               );
                }
                $drop_id = intval($item['id']);
 
index 68f230a05f8fc6c0640e1f5f905c3997d4cbc541..be50366d5cc2c364ffdbee47f168c55715b7ffc8 100644 (file)
@@ -738,7 +738,7 @@ function notifier_run($argv, $argc){
                                                // unsupported
                                                break;
                                        }
-                                       elseif(($target_item['deleted']) && ($top_level || $followup) && ($target_item['verb'] !== ACTIVITY_LIKE)) {
+                                       elseif(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup) && ($target_item['verb'] !== ACTIVITY_LIKE)) {
                                                // diaspora delete, including relayable_retractions that need to be relayed
                                                diaspora_send_retraction($target_item,$owner,$contact);
                                                break;
@@ -748,7 +748,7 @@ function notifier_run($argv, $argc){
                                                diaspora_send_followup($target_item,$owner,$contact);
                                                break;
                                        }
-                                       elseif($target_item['parent'] != $target_item['id']) {
+                                       elseif($target_item['uri'] !== $target_item['parent-uri']) {
                                                // we are the relay - send comments, likes, unlikes and relayable_retractions to our conversants
                                                diaspora_send_relay($target_item,$owner,$contact);
                                                break;
index 9d534a127a8c8dc2d28e422b5385defc9bd8960d..b542d75ba50462b8a86747638b056fe6ede8d8b5 100644 (file)
@@ -1276,7 +1276,7 @@ function update_1146() {
 
 /*
 function update_xxxx() {
-       $r1 = q("ALTER TABLE `sign` MODIFY `iid` SET DEFAULT '0'");
+       $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
        $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
        $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");  
        if((! $r1) || (! $r2) || (! $r3))
old mode 100644 (file)
new mode 100755 (executable)
index 65559b0..8b67f4d
@@ -5,9 +5,9 @@
       <target_type>$target_type</target_type>
       <parent_guid>$parent_guid</parent_guid>
       <parent_author_signature>$parentsig</parent_author_signature>
-      <author_signature>$authrosig</author_signature>
+      <author_signature>$authorsig</author_signature>
       <positive>$positive</positive>
       <diaspora_handle>$handle</diaspora_handle>
     </like>
   </post>
-</XML>
\ No newline at end of file
+</XML>
old mode 100644 (file)
new mode 100755 (executable)
index 27936f7..73cff83
@@ -3,7 +3,7 @@
     <relayable_retraction>
       <target_type>$target_type</target_type>
       <target_guid>$guid</target_guid>
-      <parent_author_signature>$parentauthorsig</parent_author_signature>
+      <parent_author_signature>$parentsig</parent_author_signature>
       <target_author_signature>$authorsig</target_author_signature>
       <sender_handle>$handle</sender_handle>
     </relayable_retraction>