We now use the new Diaspora format while sending

pull/3537/head
Michael 2017-06-15 20:50:53 +00:00
rodzic de5a0dadb0
commit 6482495001
1 zmienionych plików z 50 dodań i 31 usunięć

Wyświetl plik

@ -29,6 +29,8 @@ require_once 'include/cache.php';
*/ */
class Diaspora { class Diaspora {
private static $new = false;
/** /**
* @brief Return a list of relay servers * @brief Return a list of relay servers
* *
@ -2949,7 +2951,11 @@ class Diaspora {
*/ */
public static function build_post_xml($type, $message) { public static function build_post_xml($type, $message) {
$data = array("XML" => array("post" => array($type => $message))); if (!self::$new) {
$data = array("XML" => array("post" => array($type => $message)));
} else {
$data = array($type => $message);
}
return xml::from_array($data, $xml); return xml::from_array($data, $xml);
} }
@ -3193,6 +3199,8 @@ class Diaspora {
*/ */
public static function build_status($item, $owner) { public static function build_status($item, $owner) {
self::$new = true;
$cachekey = "diaspora:build_status:".$item['guid']; $cachekey = "diaspora:build_status:".$item['guid'];
$result = Cache::get($cachekey); $result = Cache::get($cachekey);
@ -3206,15 +3214,17 @@ class Diaspora {
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z'); $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
//self::$new = Config::get('system', 'new_diaspora', null, true);
// Detect a share element and do a reshare // Detect a share element and do a reshare
if (!$item['private'] && ($ret = self::is_reshare($item["body"]))) { if (!$item['private'] && ($ret = self::is_reshare($item["body"]))) {
$message = array("root_diaspora_id" => $ret["root_handle"], $message = array("author" => $myaddr,
"root_guid" => $ret["root_guid"],
"guid" => $item["guid"], "guid" => $item["guid"],
"diaspora_handle" => $myaddr,
"public" => $public,
"created_at" => $created, "created_at" => $created,
"provider_display_name" => $item["app"]); "root_author" => $ret["root_handle"],
"root_guid" => $ret["root_guid"],
"provider_display_name" => $item["app"],
"public" => $public);
$type = "reshare"; $type = "reshare";
} else { } else {
@ -3248,13 +3258,13 @@ class Diaspora {
$location["lng"] = $coord[1]; $location["lng"] = $coord[1];
} }
$message = array("raw_message" => $body, $message = array("author" => $myaddr,
"location" => $location,
"guid" => $item["guid"], "guid" => $item["guid"],
"diaspora_handle" => $myaddr,
"public" => $public,
"created_at" => $created, "created_at" => $created,
"provider_display_name" => $item["app"]); "public" => $public,
"text" => $body,
"provider_display_name" => $item["app"],
"location" => $location);
// Diaspora rejects messages when they contain a location without "lat" or "lng" // Diaspora rejects messages when they contain a location without "lat" or "lng"
if (!isset($location["lat"]) || !isset($location["lng"])) { if (!isset($location["lat"]) || !isset($location["lng"])) {
@ -3267,7 +3277,7 @@ class Diaspora {
$message['event'] = $event; $message['event'] = $event;
/// @todo Once Diaspora supports it, we will remove the body /// @todo Once Diaspora supports it, we will remove the body
// $message['raw_message'] = ''; // $message['text'] = '';
} }
} }
@ -3308,6 +3318,8 @@ class Diaspora {
*/ */
private static function construct_like($item, $owner) { private static function construct_like($item, $owner) {
self::$new = true;
$p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1", $p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"])); dbesc($item["thr-parent"]));
if (!dbm::is_result($p)) if (!dbm::is_result($p))
@ -3322,12 +3334,12 @@ class Diaspora {
$positive = "false"; $positive = "false";
} }
return(array("positive" => $positive, return(array("author" => self::my_handle($owner),
"guid" => $item["guid"], "guid" => $item["guid"],
"target_type" => $target_type,
"parent_guid" => $parent["guid"], "parent_guid" => $parent["guid"],
"author_signature" => "", "parent_type" => $target_type,
"diaspora_handle" => self::my_handle($owner))); "positive" => $positive,
"author_signature" => ""));
} }
/** /**
@ -3340,6 +3352,8 @@ class Diaspora {
*/ */
private static function construct_attend($item, $owner) { private static function construct_attend($item, $owner) {
self::$new = true;
$p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1", $p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"])); dbesc($item["thr-parent"]));
if (!dbm::is_result($p)) if (!dbm::is_result($p))
@ -3379,6 +3393,8 @@ class Diaspora {
*/ */
private static function construct_comment($item, $owner) { private static function construct_comment($item, $owner) {
self::$new = true;
$cachekey = "diaspora:construct_comment:".$item['guid']; $cachekey = "diaspora:construct_comment:".$item['guid'];
$result = Cache::get($cachekey); $result = Cache::get($cachekey);
@ -3399,12 +3415,12 @@ class Diaspora {
$text = html_entity_decode(bb2diaspora($item["body"])); $text = html_entity_decode(bb2diaspora($item["body"]));
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z'); $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
$comment = array("guid" => $item["guid"], $comment = array("author" => self::my_handle($owner),
"guid" => $item["guid"],
"created_at" => $created,
"parent_guid" => $parent["guid"], "parent_guid" => $parent["guid"],
"author_signature" => "",
"text" => $text, "text" => $text,
/// @todo Currently disabled until Diaspora supports it: "created_at" => $created, "author_signature" => "");
"diaspora_handle" => self::my_handle($owner));
// Send the thread parent guid only if it is a threaded comment // Send the thread parent guid only if it is a threaded comment
if ($item['thr-parent'] != $item['parent-uri']) { if ($item['thr-parent'] != $item['parent-uri']) {
@ -3612,6 +3628,8 @@ class Diaspora {
*/ */
public static function send_mail($item, $owner, $contact) { public static function send_mail($item, $owner, $contact) {
self::$new = true;
$myaddr = self::my_handle($owner); $myaddr = self::my_handle($owner);
$r = q("SELECT * FROM `conv` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `conv` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@ -3626,11 +3644,11 @@ class Diaspora {
$cnv = $r[0]; $cnv = $r[0];
$conv = array( $conv = array(
"author" => $cnv["creator"],
"guid" => $cnv["guid"], "guid" => $cnv["guid"],
"subject" => $cnv["subject"], "subject" => $cnv["subject"],
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'), "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
"diaspora_handle" => $cnv["creator"], "participants" => $cnv["recips"]
"participant_handles" => $cnv["recips"]
); );
$body = bb2diaspora($item["body"]); $body = bb2diaspora($item["body"]);
@ -3640,26 +3658,27 @@ class Diaspora {
$sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256")); $sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
$msg = array( $msg = array(
"author" => $myaddr,
"guid" => $item["guid"], "guid" => $item["guid"],
"parent_guid" => $cnv["guid"], "conversation_guid" => $cnv["guid"],
"parent_author_signature" => $sig,
"author_signature" => $sig,
"text" => $body, "text" => $body,
"created_at" => $created, "created_at" => $created,
"diaspora_handle" => $myaddr, //"parent_guid" => $cnv["guid"],
"conversation_guid" => $cnv["guid"] //"parent_author_signature" => $sig,
//"author_signature" => $sig,
); );
if ($item["reply"]) { if ($item["reply"]) {
$message = $msg; $message = $msg;
$type = "message"; $type = "message";
} else { } else {
$message = array("guid" => $cnv["guid"], $message = array(
"author" => $cnv["creator"],
"guid" => $cnv["guid"],
"subject" => $cnv["subject"], "subject" => $cnv["subject"],
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'), "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
"message" => $msg, "participants" => $cnv["recips"],
"diaspora_handle" => $cnv["creator"], "message" => $msg);
"participant_handles" => $cnv["recips"]);
$type = "conversation"; $type = "conversation";
} }