]> git.mxchange.org Git - friendica.git/commitdiff
Support for threaded comments
authorMichael <heluecht@pirati.ca>
Tue, 27 Dec 2016 12:59:15 +0000 (12:59 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 27 Dec 2016 12:59:15 +0000 (12:59 +0000)
include/diaspora.php
object/Item.php

index e4c81dca49aae0ca6aaaec8a348ba75268d33a88..77ca376b7d82ba9c2e82f3334416dd90d3e713ce 100644 (file)
@@ -1157,6 +1157,23 @@ class Diaspora {
                        return $author.":".$guid;
        }
 
+       /**
+        * @brief Fetch the guid from our database with a given uri
+        *
+        * @param string $author Author handle
+        * @param string $uri Message uri
+        *
+        * @return string The post guid
+        */
+       private static function get_guid_from_uri($uri, $uid) {
+
+               $r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($uri), intval($uid));
+               if (dbm::is_result($r))
+                       return $r[0]["guid"];
+               else
+                       return false;
+       }
+
        /**
         * @brief Processes an incoming comment
         *
@@ -2922,7 +2939,7 @@ class Diaspora {
 
                $public = (($item["private"]) ? "false" : "true");
 
-               $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d H:i:s \U\T\C');
+               $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
 
                // Detect a share element and do a reshare
                if (!$item['private'] AND ($ret = self::is_reshare($item["body"]))) {
@@ -3050,12 +3067,20 @@ class Diaspora {
                $parent = $p[0];
 
                $text = html_entity_decode(bb2diaspora($item["body"]));
+               $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
 
-               return(array("guid" => $item["guid"],
+               $comment = array("guid" => $item["guid"],
                                "parent_guid" => $parent["guid"],
                                "author_signature" => "",
                                "text" => $text,
-                               "diaspora_handle" => self::my_handle($owner)));
+                               /// @todo Currently disabled until Diaspora supports it: "created_at" => $created,
+                               "diaspora_handle" => self::my_handle($owner));
+
+               // Send the thread parent guid only if it is a threaded comment
+               if ($item['thr-parent'] != $item['parent-uri']) {
+                       $comment['thread_parent_guid'] = self::get_guid_from_uri($item['thr-parent'], $item['uid']);
+               }
+               return($comment);
        }
 
        /**
@@ -3267,13 +3292,13 @@ class Diaspora {
                $conv = array(
                        "guid" => $cnv["guid"],
                        "subject" => $cnv["subject"],
-                       "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d H:i:s \U\T\C'),
+                       "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
                        "diaspora_handle" => $cnv["creator"],
                        "participant_handles" => $cnv["recips"]
                );
 
                $body = bb2diaspora($item["body"]);
-               $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d H:i:s \U\T\C');
+               $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
 
                $signed_text = $item["guid"].";".$cnv["guid"].";".$body.";".$created.";".$myaddr.";".$cnv['guid'];
                $sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
@@ -3295,7 +3320,7 @@ class Diaspora {
                } else {
                        $message = array("guid" => $cnv["guid"],
                                        "subject" => $cnv["subject"],
-                                       "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d H:i:s \U\T\C'),
+                                       "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
                                        "message" => $msg,
                                        "diaspora_handle" => $cnv["creator"],
                                        "participant_handles" => $cnv["recips"]);
index 1c6eaf5f940cca401a28c3dea85960948d015221..4b3dfd56426249170bf3f6ead4cc66e4a4d8052d 100644 (file)
@@ -347,16 +347,18 @@ class Item extends BaseObject {
                        unset($buttons["like"]);
                }
 
+               // Disabled for testing purposes
+
                // Diaspora isn't able to do likes on comments - but red does
-               if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
-                       !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) {
-                       unset($buttons["like"]);
-               }
+               //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
+               //      !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) {
+               //      unset($buttons["like"]);
+               //}
 
                // Diaspora doesn't has multithreaded comments
-               if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) {
-                       unset($comment);
-               }
+               //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) {
+               //      unset($comment);
+               //}
 
                // Facebook can like comments - but it isn't programmed in the connector yet.
                if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) {