]> git.mxchange.org Git - friendica.git/commitdiff
Receive participation messages and processes them
authorMichael <heluecht@pirati.ca>
Fri, 12 Jan 2018 20:52:43 +0000 (20:52 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 12 Jan 2018 20:52:43 +0000 (20:52 +0000)
boot.php
src/Database/DBStructure.php
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index b10ba7a63f178b5d4726678c71fbd215d0eaf3f3..51594b21723b45309ad5863943e4df83fa2d2ae3 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -43,7 +43,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
 define('FRIENDICA_CODENAME',     'Asparagus');
 define('FRIENDICA_VERSION',      '3.6-dev');
 define('DFRN_PROTOCOL_VERSION',  '2.23');
-define('DB_UPDATE_VERSION',      1240);
+define('DB_UPDATE_VERSION',      1241);
 define('NEW_UPDATE_ROUTINE_VERSION', 1170);
 
 /**
index 11bf40aec4acf9fcf0fbf8d84f1c35f9bba91560..6ceeb573fed80b149eb357317277b37af45f59cc 100644 (file)
@@ -1299,6 +1299,16 @@ class DBStructure {
                                                "created" => array("created"),
                                                )
                                );
+               $database["participation"] = array(
+                               "fields" => array(
+                                               "item" => array("type" => "int(10) unsigned", "not null" => "1", "primary" => "1", "relation" => array("item" => "id")),
+                                               "contact" => array("type" => "int(10) unsigned", "not null" => "1", "relation" => array("contact" => "id")),
+                                               "server" => array("type" => "varchar(60)", "not null" => "1", "primary" => "1"),
+                                               ),
+                               "indexes" => array(
+                                               "PRIMARY" => array("item", "server")
+                                               )
+                               );
                $database["pconfig"] = array(
                                "fields" => array(
                                                "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
index 23220d04cd0ed2981a3c796f3878f494aac6e9e9..49134e2220cd0fcfda2086a4938b09a32f2fcaa3 100644 (file)
@@ -99,6 +99,54 @@ class Diaspora
                return $relay;
        }
 
+       /**
+        * @brief Return a list of participating contacts for a thread
+        *
+        * This is used for the participation feature.
+        * One of the parameters is a contact array.
+        * This is done to avoid duplicates.
+        *
+        * @param integer $thread   The id of the thread
+        * @param array   $contacts The previously fetched contacts
+        *
+        * @return array of relay servers
+        */
+       public static function ParticipationsForThread($thread, $contacts)
+       {
+               $relais = q("SELECT `batch`, `id`, `name`,`network` FROM `contact` WHERE `uid` = 0 AND `batch` = '%s' LIMIT 1", dbesc($batch));
+               $r = dba::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`,
+                               `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
+                               INNER JOIN `contact` ON `contact`.`id` = `participation`.`contact`
+                               LEFT JOIN `fcontact` ON `fcontact`.`url` = `contact`.`url`
+                               WHERE `participation`.`item` = ?", $thread);
+
+               while ($contact = dba::fetch($r)) {
+                       if (!empty($contact['fnetwork'])) {
+                               $contact['network'] = $contact['fnetwork'];
+                       }
+                       unset($contact['fnetwork']);
+
+                       if (empty($contact['batch']) && !empty($contact['fbatch'])) {
+                               $contact['batch'] = $contact['fbatch'];
+                       }
+                       unset($contact['fbatch']);
+
+                       $exists = false;
+                       foreach ($contacts as $entry) {
+                               if ($entry['batch'] == $contact['batch']) {
+                                       $exists = true;
+                               }
+                       }
+
+                       if (!$exists) {
+                               $contacts[] = $contact;
+                       }
+               }
+               dba::close($r);
+
+               return $contacts;
+       }
+
        /**
         * @brief repairs a signature that was double encoded
         *
@@ -542,7 +590,7 @@ class Diaspora
                        case "message":
                                return self::receiveMessage($importer, $fields);
 
-                       case "participation": // Not implemented
+                       case "participation":
                                return self::receiveParticipation($importer, $fields);
 
                        case "photo": // Not implemented
@@ -2128,7 +2176,32 @@ class Diaspora
         */
        private static function receiveParticipation($importer, $data)
        {
-               // I'm not sure if we can fully support this message type
+               $author = strtolower(notags(unxmlify($data->author)));
+               $parent_guid = notags(unxmlify($data->parent_guid));
+
+               $contact_id = Contact::getIdForURL($author);
+               if (!$contact_id) {
+                       logger('Author not found: '.$author);
+                       return false;
+               }
+
+               $item = dba::selectFirst('item', ['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
+               if (!DBM::is_result($item)) {
+                       logger('Item not found: '.$parent_guid);
+                       return false;
+               }
+
+               $author_parts = explode('@', $author);
+               if (isset($author_parts[1])) {
+                       $server = $author_parts[1];
+               } else {
+                       // Should never happen
+                       $server = $author;
+               }
+
+               logger('Received participation for ID: '.$item['id'].' - Contact: '.$contact_id.' - Server: '.$server);
+               dba::insert('participation', ['item' => $item['id'], 'contact' => $contact_id, 'server' => $server]);
+
                return true;
        }
 
index 710bcfa13b55f6ad89d9eb87e7f341d5715569b5..da6d45084eac09e7e66064467c9a5386bb78cda0 100644 (file)
@@ -522,6 +522,11 @@ class Notifier {
                                        intval($owner['uid']),
                                        intval(CONTACT_IS_SHARING)
                                );
+
+                               // Fetch the participation list
+                               // The function will ensure that there are no duplicates
+                               $r1 = Diaspora::ParticipationsForThread($item_id, $r1);
+
                        }
 
                        $r2 = q("SELECT `id`, `name`,`network` FROM `contact`
@@ -531,7 +536,8 @@ class Notifier {
                                intval(CONTACT_IS_SHARING)
                        );
 
-                       $r = array_merge($r2,$r1,$r0);
+
+                       $r = array_merge($r2, $r1, $r0);
 
                        if (DBM::is_result($r)) {
                                logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG);