From c0af6dbb1a5507dcf0fffaf13b42cfd71b0d0c50 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Thu, 31 May 2012 19:40:12 -0600 Subject: Implement relaying of relayable_retractions Also: some whitespace cleanup, fix Diaspora parent DB query --- include/items.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 0ed16217f..8858ca64f 100644 --- a/include/items.php +++ b/include/items.php @@ -3278,7 +3278,36 @@ function drop_item($id,$interactive = true) { q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']) ); - } + } + + // 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 + // 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'; + + 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); + } + + 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']); -- cgit v1.2.3 From 77962aa79df5671e206635cc6980e4b1ac969bf9 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sat, 2 Jun 2012 16:11:31 -0600 Subject: Fix bugs in the retraction code 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/items.php | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 8858ca64f..897036c26 100644 --- a/include/items.php +++ b/include/items.php @@ -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']); -- cgit v1.2.3 From cde0de965f8f2fde2b289ebcb1c1814ffa303ca6 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sat, 2 Jun 2012 23:56:42 -0600 Subject: first shot at getting like/unlike functions to work consistently --- include/items.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php index 897036c26..6b16810b2 100644 --- a/include/items.php +++ b/include/items.php @@ -3281,9 +3281,11 @@ 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/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 + // 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 // check the parent_author_signature of retractions that it doesn't have to relay further + // + // I don't think this function gets called for an "unlike," but I'll check anyway $signed_text = $item['guid'] . ';' . ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); if(local_user() == $item['uid']) { @@ -3296,6 +3298,8 @@ function drop_item($id,$interactive = true) { $item['contact-id'] ); if(count($r)) { + // The below handle only works for NETWORK_DFRN. I think that's ok, because this function + // only handles DFRN deletes $handle = $r['nick'] . '@' . substr($r['url'], strpos($r['url'],'://') + 3, strpos($r['url'],'/profile') - 1); $authorsig = ''; } -- cgit v1.2.3 From 9920fb39e566a10c44aa7ead9603ff3d1893a01a Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Sun, 3 Jun 2012 14:32:17 -0600 Subject: Debugged implementation of Diaspora relayable_retractions Diaspora "relayable_retraction" is now supported by Friendica. The following should now work: Friendica top-level post: Diaspora comment deleted, disappears in Friendica Friendica comment deleted, disappears in Diaspora Diaspora like retracted, disappears in Friendica Friendica like retracted, disappears in Diaspora Diaspora top-level post: Same There are still exceptions, however. First, Friendica and Diaspora seem to frequently reject comments with an "invalid signature" error. This can probably be fixed. Also, some comments/likes/retractions seem to just disappear on the Diaspora side. In the Diaspora log these seem to be accompanied by a "not a valid object" error, often preceeded by a "received a comment but no corresponding post" error. These seem to be purely internal, since sometimes it works for some Diaspora contacts but not others. --- include/items.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100644 => 100755 include/items.php (limited to 'include/items.php') diff --git a/include/items.php b/include/items.php old mode 100644 new mode 100755 index 6b16810b2..4513db1db --- a/include/items.php +++ b/include/items.php @@ -3300,7 +3300,9 @@ function drop_item($id,$interactive = true) { if(count($r)) { // The below handle only works for NETWORK_DFRN. I think that's ok, because this function // only handles DFRN deletes - $handle = $r['nick'] . '@' . substr($r['url'], strpos($r['url'],'://') + 3, strpos($r['url'],'/profile') - 1); + $handle_baseurl_start = strpos($r['url'],'://') + 3; + $handle_baseurl_length = strpos($r['url'],'/profile') - $handle_baseurl_start; + $handle = $r['nick'] . '@' . substr($r['url'], $handle_baseurl_start, $handle_baseurl_length); $authorsig = ''; } } -- cgit v1.2.3