]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Conversation.php
Rename PROTOCOL_* constants to Model\Conversation::PARCEL_*
[friendica.git] / src / Model / Conversation.php
index e6888ca8f6cc01fa930a220939303bd2ef5adbe7..6bf31db6e6f9202a7e3183e5ab252ca6a7c4a330 100644 (file)
@@ -4,13 +4,24 @@
  */
 namespace Friendica\Model;
 
-use Friendica\Database\DBM;
-use dba;
+use Friendica\Database\DBA;
+use Friendica\Util\DateTimeFormat;
 
 require_once "include/dba.php";
 
 class Conversation
 {
+       /*
+        * These constants represent the parcel format used to transport a conversation independently of the message protocol.
+        * It currently is stored in the "protocol" field for legacy reasons.
+        */
+       const PARCEL_UNKNOWN            = 0;
+       const PARCEL_DFRN               = 1;
+       const PARCEL_DIASPORA           = 2;
+       const PARCEL_SALMON             = 3;
+       const PARCEL_FEED               = 4; // Deprecated
+       const PARCEL_SPLIT_CONVERSATION = 6;
+
        /**
         * @brief Store the conversation data
         *
@@ -19,7 +30,7 @@ class Conversation
         */
        public static function insert($arr) {
                if (in_array(defaults($arr, 'network', NETWORK_PHANTOM), [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS]) && !empty($arr['uri'])) {
-                       $conversation = ['item-uri' => $arr['uri'], 'received' => DBM::date()];
+                       $conversation = ['item-uri' => $arr['uri'], 'received' => DateTimeFormat::utcNow()];
 
                        if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
                                $conversation['reply-to-uri'] = $arr['parent-uri'];
@@ -44,24 +55,24 @@ class Conversation
                                $conversation['source'] = $arr['source'];
                        }
 
-                       $old_conv = dba::fetch_first("SELECT `item-uri`, `reply-to-uri`, `conversation-uri`, `conversation-href`, `protocol`, `source`
-                                       FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']);
-                       if (DBM::is_result($old_conv)) {
+                       $fields = ['item-uri', 'reply-to-uri', 'conversation-uri', 'conversation-href', 'protocol', 'source'];
+                       $old_conv = DBA::selectFirst('conversation', $fields, ['item-uri' => $conversation['item-uri']]);
+                       if (DBA::isResult($old_conv)) {
                                // Don't update when only the source has changed.
                                // Only do this when there had been no source before.
                                if ($old_conv['source'] != '') {
                                        unset($old_conv['source']);
                                }
                                // Update structure data all the time but the source only when its from a better protocol.
-                               if (($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
+                               if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
                                        unset($conversation['protocol']);
                                        unset($conversation['source']);
                                }
-                               if (!dba::update('conversation', $conversation, ['item-uri' => $conversation['item-uri']], $old_conv)) {
-                                       logger('Conversation: update for '.$conversation['item-uri'].' from '.$conv['protocol'].' to '.$conversation['protocol'].' failed', LOGGER_DEBUG);
+                               if (!DBA::update('conversation', $conversation, ['item-uri' => $conversation['item-uri']], $old_conv)) {
+                                       logger('Conversation: update for '.$conversation['item-uri'].' from '.$old_conv['protocol'].' to '.$conversation['protocol'].' failed', LOGGER_DEBUG);
                                }
                        } else {
-                               if (!dba::insert('conversation', $conversation, true)) {
+                               if (!DBA::insert('conversation', $conversation, true)) {
                                        logger('Conversation: insert for '.$conversation['item-uri'].' (protocol '.$conversation['protocol'].') failed', LOGGER_DEBUG);
                                }
                        }