$msg = Diaspora::decodeRaw($user, $postdata);
// Check if the user has got this contact
- $cid = getIdForURL($msg['author'], $user['uid']);
+ $cid = Contact::getIdForURL($msg['author'], $user['uid']);
if (!$cid) {
// Otherwise there should be a public contact
- $cid = getIdForURL($msg['author']);
+ $cid = Contact::getIdForURL($msg['author']);
if (!$cid) {
logger('Contact not found for address ' . $msg['author']);
System::xmlExit(3, 'Contact not found');
// Now we should be able to import it
$ret = DFRN::import($msg['message'], $importer);
- System::xmlExit($ret, 'Processed');
+ System::xmlExit($ret, 'Done');
} else {
require_once 'mod/salmon.php';
salmon_post($a, $postdata);
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
+use Friendica\Protocol\Diaspora;
use dba;
use DOMDocument;
use DOMXPath;
return intval($res->status);
}
+ /**
+ * @brief Delivers items to the contacts via the Diaspora transport layer
+ *
+ * @param array $owner Owner record
+ * @param array $contact Contact record of the receiver
+ * @param array $items Items that will be transmitted
+ *
+ * @return int HTTP Deliver status
+ */
+ public static function buildAndTransmit($owner, $contact, $items)
+ {
+ $a = get_app();
+
+ // Currently disabled, at first we will not use the batch delivery
+ // $public_batch = !$items[0]['private'];
+ $public_batch = false;
+
+ $msg = DFRN::entries($items, $owner);
+
+ $fcontact = Diaspora::personByHandle($contact['addr']);
+ if (empty($fcontact)) {
+ logger("unable to find contact details");
+ return;
+ }
+
+ $envelope = Diaspora::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $fcontact['pubkey'], $public_batch);
+
+ $dest_url = ($public_batch ? $fcontact["batch"] : $contact["notify"]);
+
+ $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
+
+ $ret = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
+
+ /// @ToDo: Add better treating of return codes
+ return $a->get_curl_code();
+ }
+
/**
* @brief Add new birthday event for this person
*
*
* @return string The message that will be transmitted to other servers
*/
- private static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false)
+ public static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false)
{
// The message is put into an envelope with the sender's signature
$envelope = self::buildMagicEnvelope($msg, $user);