]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Conversation.php
Fix typo on 986030060b84
[quix0rs-gnu-social.git] / classes / Conversation.php
index 1dba2c1f4a346ae6db4decc850376d53fed7581d..d18321deba657e8c49d61c2131860669f0beb625 100644 (file)
@@ -36,6 +36,7 @@ class Conversation extends Managed_DataObject
     public $__table = 'conversation';        // table name
     public $id;                              // int(4)  primary_key not_null auto_increment
     public $uri;                             // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
+    public $url;                             // varchar(191)  unique_key   not 255 because utf8mb4 takes more space
     public $created;                         // datetime   not_null
     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
 
@@ -45,6 +46,7 @@ class Conversation extends Managed_DataObject
             'fields' => array(
                 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique identifier, (again) unrelated to notice id since 2016-01-06'),
                 'uri' => array('type' => 'varchar', 'not null'=>true, 'length' => 191, 'description' => 'URI of the conversation'),
+                'url' => array('type' => 'varchar', 'length' => 191, 'description' => 'Resolvable URL, preferrably remote (local can be generated on the fly)'),
                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
             ),
@@ -89,15 +91,21 @@ class Conversation extends Managed_DataObject
      *
      * @return Conversation the new conversation DO
      */
-    static function create($uri=null, $created=null)
+    static function create(ActivityContext $ctx=null, $created=null)
     {
         // Be aware that the Notice does not have an id yet since it's not inserted!
         $conv = new Conversation();
         $conv->created = $created ?: common_sql_now();
-        $conv->uri = $uri ?: sprintf('%s%s=%s:%s=%s',
+        if ($ctx instanceof ActivityContext) {
+            $conv->uri = $ctx->conversation;
+            $conv->url = $ctx->conversation_url;
+        } else {
+            $conv->uri = sprintf('%s%s=%s:%s=%s',
                              TagURI::mint(),
                              'objectType', 'thread',
                              'nonce', common_random_hexstr(8));
+            $conv->url = null;  // locally generated Conversation objects don't get static URLs stored
+        }
         // This insert throws exceptions on failure
         $conv->insert();