]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/threadednoticelist.php
better output for registration confirmation
[quix0rs-gnu-social.git] / lib / threadednoticelist.php
index b686e17629e55d7479a0305b929ec7ef19906d39..96be0df0c58d037eb2eb988665c077b84a0739f4 100644 (file)
@@ -50,6 +50,17 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
  */
 class ThreadedNoticeList extends NoticeList
 {
+    protected $userProfile;
+
+    function __construct($notice, $out=null, $profile=-1)
+    {
+        parent::__construct($notice, $out);
+        if (is_int($profile) && $profile == -1) {
+            $profile = Profile::current();
+        }
+        $this->userProfile = $profile;
+    }
+
     /**
      * show the list of notices
      *
@@ -90,7 +101,7 @@ class ThreadedNoticeList extends NoticeList
             $conversations[$convo] = true;
 
             // Get the convo's root notice
-            $root = $notice->conversationRoot();
+            $root = $notice->conversationRoot($this->userProfile);
             if ($root) {
                 $notice = $root;
             }
@@ -123,7 +134,7 @@ class ThreadedNoticeList extends NoticeList
      */
     function newListItem($notice)
     {
-        return new ThreadedNoticeListItem($notice, $this->out);
+        return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile);
     }
 }
 
@@ -146,6 +157,14 @@ class ThreadedNoticeList extends NoticeList
  */
 class ThreadedNoticeListItem extends NoticeListItem
 {
+    protected $userProfile = null;
+
+    function __construct($notice, $out=null, $profile=null)
+    {
+        parent::__construct($notice, $out);
+        $this->userProfile = $profile;
+    }
+
     function initialItems()
     {
         return 3;
@@ -167,7 +186,8 @@ class ThreadedNoticeListItem extends NoticeListItem
     {
         $max = $this->initialItems();
         if (!$this->repeat) {
-            $notice = Notice::conversationStream($this->notice->conversation, 0, $max + 2);
+            $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
+            $notice = $stream->getNotices(0, $max + 2);
             $notices = array();
             $cnt = 0;
             $moreCutoff = null;
@@ -185,33 +205,40 @@ class ThreadedNoticeListItem extends NoticeListItem
                 $notices[] = clone($notice); // *grumble* inefficient as hell
             }
 
-            $this->out->elementStart('ul', 'notices threaded-replies xoxo');
-
-            $item = new ThreadedNoticeListFavesItem($this->notice, $this->out);
-            $hasFaves = $item->show();
-
-            $item = new ThreadedNoticeListRepeatsItem($this->notice, $this->out);
-            $hasRepeats = $item->show();
-
-            if ($notices) {
-                if ($moreCutoff) {
-                    $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out);
-                    $item->show();
+            if (Event::handle('StartShowThreadedNoticeTail', array($this, $this->notice, &$notices))) {
+                $this->out->elementStart('ul', 'notices threaded-replies xoxo');
+
+                $item = new ThreadedNoticeListFavesItem($this->notice, $this->out);
+                $hasFaves = $item->show();
+
+                $item = new ThreadedNoticeListRepeatsItem($this->notice, $this->out);
+                $hasRepeats = $item->show();
+
+                if ($notices) {
+                    if ($moreCutoff) {
+                        $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out);
+                        $item->show();
+                    }
+                    foreach (array_reverse($notices) as $notice) {
+                        if (Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice))) {
+                            $item = new ThreadedNoticeListSubItem($notice, $this->notice, $this->out);
+                            $item->show();
+                            Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice));
+                        }
+                    }
                 }
-                foreach (array_reverse($notices) as $notice) {
-                    $item = new ThreadedNoticeListSubItem($notice, $this->out);
-                    $item->show();
-                }
-            }
-            if ($notices || $hasFaves || $hasRepeats) {
-                // @fixme do a proper can-post check that's consistent
-                // with the JS side
-                if (common_current_user()) {
-                    $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
-                    $item->show();
+
+                if ($notices || $hasFaves || $hasRepeats) {
+                    // @fixme do a proper can-post check that's consistent
+                    // with the JS side
+                    if (common_current_user()) {
+                        $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
+                        $item->show();
+                    }
                 }
+                $this->out->elementEnd('ul');
+                Event::handle('EndShowThreadedNoticeTail', array($this, $this->notice, $notices));
             }
-            $this->out->elementEnd('ul');
         }
 
         parent::showEnd();
@@ -221,6 +248,14 @@ class ThreadedNoticeListItem extends NoticeListItem
 // @todo FIXME: needs documentation.
 class ThreadedNoticeListSubItem extends NoticeListItem
 {
+    protected $root = null;
+
+    function __construct($notice, $root, $out)
+    {
+        $this->root = $root;
+        parent::__construct($notice, $out);
+    }
+
     function avatarSize()
     {
         return AVATAR_STREAM_SIZE; // @fixme would like something in between
@@ -241,6 +276,23 @@ class ThreadedNoticeListSubItem extends NoticeListItem
         //
     }
 
+    function getReplyProfiles()
+    {
+        $all = parent::getReplyProfiles();
+
+        $profiles = array();
+
+        $rootAuthor = $this->root->getProfile();
+
+        foreach ($all as $profile) {
+            if ($profile->id != $rootAuthor->id) {
+                $profiles[] = $profile;
+            }
+        }
+
+        return $profiles;
+    }
+
     function showEnd()
     {
         $item = new ThreadedNoticeListInlineFavesItem($this->notice, $this->out);