New implementation is now live.

This commit is contained in:
Michael Vogel 2016-03-13 19:47:02 +01:00 committed by Roland Haeder
parent e90af0be68
commit d176fff214
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
4 changed files with 144 additions and 102 deletions

View file

@ -68,7 +68,7 @@ function delivery_run(&$argv, &$argc){
dbesc($contact_id)
);
if((! $item_id) || (! $contact_id))
if (!$item_id || !$contact_id)
continue;
$expire = false;
@ -230,7 +230,7 @@ function delivery_run(&$argv, &$argc){
$relay_to_owner = false;
if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
if (!$top_level && ($parent['wall'] == 0) && !$expire && stristr($target_item['uri'],$localhost)) {
$relay_to_owner = true;
}
@ -294,7 +294,7 @@ function delivery_run(&$argv, &$argc){
continue;
// private emails may be in included in public conversations. Filter them.
if(($public_message) && $item['private'])
if ($public_message && $item['private'])
continue;
$item_contact = get_item_contact($item,$icontacts);
@ -349,8 +349,8 @@ function delivery_run(&$argv, &$argc){
if ($x && count($x)) {
$write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
q("update contact set writable = 1 where id = %d",
if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) {
q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d",
intval($x[0]['id'])
);
$x[0]['writable'] = 1;
@ -439,7 +439,7 @@ function delivery_run(&$argv, &$argc){
// only expose our real email address to true friends
if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked'])) {
if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
if ($reply_to) {
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n";
$headers .= 'Sender: '.$local_user[0]['email']."\n";
@ -500,14 +500,15 @@ function delivery_run(&$argv, &$argc){
break;
if ($mail) {
diaspora_send_mail($item,$owner,$contact);
diaspora::send_mail($item,$owner,$contact);
//diaspora_send_mail($item,$owner,$contact);
break;
}
if (!$normal_mode)
break;
if((! $contact['pubkey']) && (! $public_message))
if (!$contact['pubkey'] && !$public_message)
break;
$unsupported_activities = array(ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
@ -523,22 +524,25 @@ function delivery_run(&$argv, &$argc){
// top-level retraction
logger('delivery: diaspora retract: '.$loc);
diaspora_send_retraction($target_item,$owner,$contact,$public_message);
diaspora::send_retraction($target_item,$owner,$contact,$public_message);
//diaspora_send_retraction($target_item,$owner,$contact,$public_message);
break;
} elseif ($followup) {
// send comments and likes to owner to relay
diaspora_send_followup($target_item,$owner,$contact,$public_message);
diaspora::send_followup($target_item,$owner,$contact,$public_message);
//diaspora_send_followup($target_item,$owner,$contact,$public_message);
break;
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
// we are the relay - send comments, likes and relayable_retractions to our conversants
logger('delivery: diaspora relay: '.$loc);
diaspora_send_relay($target_item,$owner,$contact,$public_message);
diaspora::send_relay($target_item,$owner,$contact,$public_message);
//diaspora_send_relay($target_item,$owner,$contact,$public_message);
break;
} elseif(($top_level) && (! $walltowall)) {
} elseif ($top_level && !$walltowall) {
// currently no workable solution for sending walltowall
logger('delivery: diaspora status: '.$loc);
diaspora_send_status($target_item,$owner,$contact,$public_message);
diaspora::send_status($target_item,$owner,$contact,$public_message);
//diaspora_send_status($target_item,$owner,$contact,$public_message);
break;
}

View file

@ -15,6 +15,7 @@ require_once('include/lock.php');
require_once('include/threads.php');
require_once('mod/share.php');
require_once('include/enotify.php');
require_once('include/diaspora2.php');
function diaspora_dispatch_public($msg) {

View file

@ -284,6 +284,8 @@ class diaspora {
$type = $fields->getName();
logger("Received message type ".$type." from ".$sender." for user ".$importer["uid"], LOGGER_DEBUG);
switch ($type) {
case "account_deletion":
return self::receive_account_deletion($importer, $fields);
@ -654,7 +656,7 @@ class diaspora {
return false;
}
if (!self::post_allow($importer, $contact, false)) {
if (!self::post_allow($importer, $contact, $is_comment)) {
logger("The handle: ".$handle." is not allowed to post to user ".$importer["uid"]);
return false;
}
@ -669,10 +671,10 @@ class diaspora {
if($r) {
logger("message ".$guid." already exists for user ".$uid);
return false;
return true;
}
return true;
return false;
}
private function fetch_guid($item) {
@ -774,11 +776,13 @@ class diaspora {
}
if (!$r) {
logger("parent item not found: parent: ".$guid." item: ".$guid);
logger("parent item not found: parent: ".$guid." - user: ".$uid);
return false;
} else
} else {
logger("parent item found: parent: ".$guid." - user: ".$uid);
return $r[0];
}
}
private function author_contact_by_url($contact, $person, $uid) {
@ -892,6 +896,9 @@ class diaspora {
$message_id = item_store($datarray);
if ($message_id)
logger("Stored comment ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
// If we are the origin of the parent we store the original data and notify our followers
if($message_id AND $parent_item["origin"]) {
@ -1175,6 +1182,9 @@ class diaspora {
$message_id = item_store($datarray);
if ($message_id)
logger("Stored like ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
// If we are the origin of the parent we store the original data and notify our followers
if($message_id AND $parent_item["origin"]) {
@ -1358,6 +1368,8 @@ class diaspora {
update_gcontact($gcontact);
logger("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], LOGGER_DEBUG);
return true;
}
@ -1654,6 +1666,9 @@ class diaspora {
self::fetch_guid($datarray);
$message_id = item_store($datarray);
if ($message_id)
logger("Stored reshare ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return $message_id;
}
@ -1695,6 +1710,8 @@ class diaspora {
);
delete_thread($r[0]["id"], $r[0]["parent-uri"]);
logger("Deleted target ".$target_guid." from user ".$importer["uid"], LOGGER_DEBUG);
// Now check if the retraction needs to be relayed by us
if($p[0]["origin"]) {
@ -1822,7 +1839,8 @@ class diaspora {
self::fetch_guid($datarray);
$message_id = item_store($datarray);
logger("Stored item with message id ".$message_id, LOGGER_DEBUG);
if ($message_id)
logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
return $message_id;
}
@ -2329,8 +2347,21 @@ class diaspora {
/// @todo Change all signatur storing functions to the new format
if ($signature['signed_text'] AND $signature['signature'] AND $signature['signer'])
$message = self::message_from_signatur($item, $signature);
else // New way
$message = json_decode($signature['signed_text']);
else {// New way
$msg = json_decode($signature['signed_text'], true);
$message = array();
foreach ($msg AS $field => $data) {
if (!$item["deleted"]) {
if ($field == "author")
$field = "diaspora_handle";
if ($field == "parent_type")
$field = "target_type";
}
$message[$field] = $data;
}
}
if ($item["deleted"]) {
$signed_text = $message["target_guid"].';'.$message["target_type"];
@ -2338,6 +2369,8 @@ class diaspora {
} else
$message["parent_author_signature"] = self::signature($owner, $message);
logger("Relayed data ".print_r($message, true), LOGGER_DEBUG);
return self::build_and_transmit($owner, $contact, $type, $message, $public_batch, $item["guid"]);
}

View file

@ -53,7 +53,8 @@ function receive_post(&$a) {
logger('mod-diaspora: message is okay', LOGGER_DEBUG);
$msg = diaspora_decode($importer,$xml);
$msg = diaspora::decode($importer,$xml);
//$msg = diaspora_decode($importer,$xml);
logger('mod-diaspora: decoded', LOGGER_DEBUG);
@ -65,10 +66,13 @@ function receive_post(&$a) {
logger('mod-diaspora: dispatching', LOGGER_DEBUG);
$ret = 0;
if($public)
diaspora_dispatch_public($msg);
else
$ret = diaspora_dispatch($importer,$msg);
if($public) {
diaspora::dispatch_public($msg);
//diaspora_dispatch_public($msg);
} else {
$ret = diaspora::dispatch($importer,$msg);
//$ret = diaspora_dispatch($importer,$msg);
}
http_status_exit(($ret) ? $ret : 200);
// NOTREACHED