]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Conversation.php
Merge branch 'fixes/private_scope_on_tags' into social-master
[quix0rs-gnu-social.git] / classes / Conversation.php
old mode 100755 (executable)
new mode 100644 (file)
index 033b993..56f61c6
@@ -44,7 +44,7 @@ class Conversation extends Managed_DataObject
         return array(
             'fields' => array(
                 'id' => array('type' => 'int', 'not null' => true, 'description' => 'should be set from root notice id (since 2014-03-01 commit)'),
-                'uri' => array('type' => 'varchar', 'length' => 255, 'description' => 'URI of the conversation'),
+                'uri' => array('type' => 'varchar', 'not null'=>true, 'length' => 255, 'description' => 'URI of the conversation'),
                 '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'),
             ),
@@ -56,11 +56,14 @@ class Conversation extends Managed_DataObject
     }
 
     /**
-     * Factory method for creating a new conversation
+     * Factory method for creating a new conversation.
+     *
+     * Use this for locally initiated conversations. Remote notices should
+     * preferrably supply their own conversation URIs in the OStatus feed.
      *
      * @return Conversation the new conversation DO
      */
-    static function create(Notice $notice)
+    static function create(Notice $notice, $uri=null)
     {
         if (empty($notice->id)) {
             throw new ServerException(_('Tried to create conversation for not yet inserted notice'));
@@ -68,7 +71,11 @@ class Conversation extends Managed_DataObject
         $conv = new Conversation();
         $conv->created = common_sql_now();
         $conv->id = $notice->id;
-        $conv->uri = common_local_url('conversation', array('id' => $notice->id), null, null, false);
+        $conv->uri = $uri ?: sprintf('%s%s=%d:%s=%s:%s=%x',
+                             TagURI::mint(),
+                             'noticeId', $notice->id,
+                             'objectType', 'thread',
+                             'crc32', crc32($notice->content));
         $result = $conv->insert();
 
         if ($result === false) {
@@ -91,6 +98,7 @@ class Conversation extends Managed_DataObject
 
         $notice               = new Notice();
         $notice->conversation = $id;
+        $notice->whereAddIn('verb', array(ActivityVerb::POST, ActivityUtils::resolveUri(ActivityVerb::POST, true)), $notice->columnType('verb'));
         $cnt                  = $notice->count();
 
         self::cacheSet($keypart, $cnt);
@@ -115,4 +123,15 @@ class Conversation extends Managed_DataObject
         return common_local_url('conversation', array('id' => $this->id)) .
                 ($noticeId===null ? '' : "#notice-{$noticeId}");
     }
+
+    // FIXME: ...will 500 ever be too low? Taken from ConversationAction::MAX_NOTICES
+    public function getNotices($offset=0, $limit=500, Profile $scoped=null)
+    {
+        if ($scoped === null) {
+            $scoped = Profile::current();
+        }
+        $stream = new ConversationNoticeStream($this->id, $scoped);
+        $notices = $stream->getNotices($offset, $limit);
+        return $notices;
+    }
 }