]> git.mxchange.org Git - friendica.git/commitdiff
Receiving was tested, sending is implemented and tested as well, currently unused
authorMichael <heluecht@pirati.ca>
Mon, 2 Apr 2018 12:53:48 +0000 (12:53 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 2 Apr 2018 12:53:48 +0000 (12:53 +0000)
mod/dfrn_notify.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php

index a43c316b0c3c9d241f618d23c42e35fc8008d037..7eddd4f3d576e05b59b787a2fb4eb05321b14176 100644 (file)
@@ -32,10 +32,10 @@ function dfrn_notify_post(App $a) {
                        $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');
@@ -59,7 +59,7 @@ function dfrn_notify_post(App $a) {
 
                        // 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);
index cb23c4bf122b551d5bdd1c5c94f804e5e7a431a2..43fe16c317bc72560a448a3ed0d8979bf96baa9b 100644 (file)
@@ -31,6 +31,7 @@ use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
+use Friendica\Protocol\Diaspora;
 use dba;
 use DOMDocument;
 use DOMXPath;
@@ -1368,6 +1369,43 @@ class DFRN
                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
         *
index 23bc575dd071ac8ce5d75df0bf9fabdc5a049c65..4b8ae2110215d93d2c2247b7cb2b83b01858f7e2 100644 (file)
@@ -3205,7 +3205,7 @@ class Diaspora
         *
         * @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);