From e8ef515b6136ee79ff17e1c143a15e29691d3d81 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 3 Sep 2014 05:09:43 -0700 Subject: store diaspora meta info in the item table. It has to go there or it will kill us with complex joins. We can phase out the sign table once this all checks out. --- boot.php | 2 +- include/diaspora.php | 54 ++++++++++++++++++++++++++-------------------------- include/identity.php | 27 +++++++++++--------------- include/items.php | 13 ++++++++++++- install/database.sql | 1 + install/update.php | 11 ++++++++++- mod/xrd.php | 17 +++++------------ 7 files changed, 67 insertions(+), 58 deletions(-) diff --git a/boot.php b/boot.php index 344a2a7ca..cb70b898b 100755 --- a/boot.php +++ b/boot.php @@ -47,7 +47,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1128 ); +define ( 'DB_UPDATE_VERSION', 1129 ); define ( 'EOL', '
' . "\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/diaspora.php b/include/diaspora.php index c2f2b1ac9..fabcafa79 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1343,6 +1343,11 @@ function diaspora_comment($importer,$xml,$msg) { $datarray['body'] = $body; $datarray['app'] = 'Diaspora'; + + if(! $parent_author_signature) { + $datarray['diaspora_meta'] = array('signer' => $diaspora_handle, 'body' => $text, + 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); + } $result = item_store($datarray); @@ -1908,6 +1913,12 @@ EOT; $arr['unseen'] = 1; $arr['last-child'] = 0; + if(! $parent_author_signature) { + $datarray['diaspora_meta'] = array('signer' => $diaspora_handle, 'body' => $text, + 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature)); + } + + $message_id = item_store($arr); @@ -2551,28 +2562,15 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $tpl = get_markup_template('diaspora_comment_relay.tpl'); } - - // fetch the original signature if the relayable was created by a Diaspora, Friendica-over Diaspora, - // or zot user. Relayables for other networks are not supported. - - $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1", - intval($item['id']) - ); - if($r) { - $orig_sign = $r[0]; - $signed_text = $orig_sign['signed_text']; - $authorsig = $orig_sign['signature']; - $handle = $orig_sign['signer']; + $diaspora_meta = (($item['diaspora_meta']) ? json_decode($item['diaspora_meta'],true) : ''); + if($diaspora_meta) { + $sender_signed_text = $diaspora_meta['signed_text']; + $authorsig = $diaspora_meta['signature']; + $handle = $diaspora_meta['signer']; + $text = $diaspora_meta['body']; } - else { - // Author signature information (for likes, comments, and retractions of likes or comments, - // whether from Diaspora or Friendica) must be placed in the `sign` table before this - // function is called -// $authorsig = $item['sig']; + else logger('diaspora_send_relay: original author signature not found'); -// ignore - see below -// return; - } /* Since the author signature is only checked by the parent, not by the relay recipients, * I think it may not be necessary for us to do so much work to preserve all the original @@ -2585,7 +2583,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { * * */ - +// bug - nomadic identity may/will affect diaspora_handle_from_contact if(! $handle) { if($item['author_xchan'] === $owner['channel_hash']) $handle = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); @@ -2597,12 +2595,14 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { return; } - if($relay_retract) - $sender_signed_text = $item['mid'] . ';' . $target_type; - elseif($like) - $sender_signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $handle; - else - $sender_signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $handle; + if(! $sender_signed_text) { + if($relay_retract) + $sender_signed_text = $item['mid'] . ';' . $target_type; + elseif($like) + $sender_signed_text = $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $positive . ';' . $handle; + else + $sender_signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $handle; + } // Sign the relayable with the top-level owner's signature // diff --git a/include/identity.php b/include/identity.php index 8b742f53e..282d323be 100644 --- a/include/identity.php +++ b/include/identity.php @@ -774,22 +774,17 @@ logger('online: ' . $profile['online']); ? trim(substr($profile['channel_name'],0,strpos($profile['channel_name'],' '))) : $profile['channel_name']); $lastname = (($firstname === $profile['channel_name']) ? '' : trim(substr($profile['channel_name'],strlen($firstname)))); - if(get_config('system','diaspora_enabled')) { - $diaspora = array( - 'podloc' => z_root(), - 'searchable' => (($block) ? 'false' : 'true'), - 'nickname' => $profile['channel_address'], - 'fullname' => $profile['channel_name'], - 'firstname' => $firstname, - 'lastname' => $lastname, - 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', - 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', - 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg', - ); - } - else - $diaspora = null; - + $diaspora = array( + 'podloc' => z_root(), + 'searchable' => (($block) ? 'false' : 'true'), + 'nickname' => $profile['channel_address'], + 'fullname' => $profile['channel_name'], + 'firstname' => $firstname, + 'lastname' => $lastname, + 'photo300' => z_root() . '/photo/profile/300/' . $profile['uid'] . '.jpg', + 'photo100' => z_root() . '/photo/profile/100/' . $profile['uid'] . '.jpg', + 'photo50' => z_root() . '/photo/profile/50/' . $profile['uid'] . '.jpg', + ); $contact_block = contact_block(); diff --git a/include/items.php b/include/items.php index b3b9d28cd..9d80b3a81 100755 --- a/include/items.php +++ b/include/items.php @@ -795,7 +795,7 @@ function get_item_elements($x) { $arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : ''); - + $arr['diaspora_meta'] = (($x['diaspora_meta']) ? $x['diaspora_meta'] : ''); $arr['object'] = activity_sanitise($x['object']); $arr['target'] = activity_sanitise($x['target']); @@ -1194,6 +1194,7 @@ function encode_mail($item) { $x['message_parent'] = $item['parent_mid']; $x['created'] = $item['created']; $x['expires'] = $item['expires']; + $x['diaspora_meta'] = $item['diaspora_meta']; $x['title'] = $item['title']; $x['body'] = $item['body']; $x['from'] = encode_item_xchan($item['from']); @@ -1748,6 +1749,7 @@ function item_store($arr,$allow_exec = false) { $arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : ''); $arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : ''); + $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : ''); $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : ''); $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : ''); $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : ''); @@ -2236,6 +2238,8 @@ function item_store_update($arr,$allow_exec = false) { $arr['commented'] = $orig[0]['commented']; $arr['received'] = datetime_convert(); $arr['changed'] = datetime_convert(); + + $arr['diaspora_meta'] = ((x($arr,'diaspora_meta')) ? $arr['diaspora_meta'] : $orig[0]['diaspora_meta']); $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']); $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : $orig[0]['coord']); $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']); @@ -2370,6 +2374,13 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id) else $authorsig = ''; + $x = array('signer' => $diaspora_handle, 'body' => $signed_body, 'signed_text' => $signed_text, 'signature' => base64_encode($authorsig)); + + $r = q("update item set diaspora_meta = '%s' where id = %d limit 1", + dbesc(json_encode($x)), + intval($post_id) + ); + $r = q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($post_id), dbesc($signed_text), diff --git a/install/database.sql b/install/database.sql index c773fab10..a49bd377c 100644 --- a/install/database.sql +++ b/install/database.sql @@ -535,6 +535,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `resource_type` char(16) NOT NULL DEFAULT '', `attach` mediumtext NOT NULL DEFAULT '', `sig` text NOT NULL DEFAULT '', + `diaspora_meta` mediumtext NOT NULL DEFAULT '', `location` char(255) NOT NULL DEFAULT '', `coord` char(255) NOT NULL DEFAULT '', `public_policy` char(255) NOT NULL DEFAULT '', diff --git a/install/update.php b/install/update.php index 92cb200a3..0b1fa5d2e 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ $a->get_baseurl(), - '$dspr_guid' => $r[0]['channel_guid'], - '$dspr_key' => base64_encode(pemtorsa($r[0]['channel_pubkey'])) - )); - } - else - $dspr = ''; - - + $dspr = replace_macros(get_markup_template('xrd_diaspora.tpl'),array( + '$baseurl' => $a->get_baseurl(), + '$dspr_guid' => $r[0]['channel_guid'], + '$dspr_key' => base64_encode(pemtorsa($r[0]['channel_pubkey'])) + )); $salmon_key = salmon_key($r[0]['channel_pubkey']); -- cgit v1.2.3