]> 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 ce620916a12152b5996732a245484119b7de54c9..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);
@@ -284,9 +336,8 @@ class ThreadedNoticeListMoreItem extends NoticeListItem
         $id = $this->notice->conversation;
         $url = common_local_url('conversationreplies', array('id' => $id));
 
-        $notice = new Notice();
-        $notice->conversation = $id;
-        $n = $notice->count() - 1;
+        $n = Conversation::noticeCount($id) - 1;
+
         // TRANS: Link to show replies for a notice.
         // TRANS: %d is the number of replies to a notice and used for plural.
         $msg = sprintf(_m('Show reply', 'Show all %d replies', $n), $n);
@@ -329,7 +380,7 @@ class ThreadedNoticeListReplyItem extends NoticeListItem
     function showMiniForm()
     {
         $this->out->element('input', array('class' => 'placeholder',
-                                            // TRANS: Field label for reply mini form.
+                                           // TRANS: Field label for reply mini form.
                                            'value' => _('Write a reply...')));
     }
 }
@@ -423,8 +474,7 @@ class ThreadedNoticeListFavesItem extends NoticeListActorsItem
         } else {
             // TRANS: List message for favoured notices.
             // TRANS: %d is the number of users that have favoured a notice.
-            return sprintf(_m('FAVELIST',
-                              'One person has favored this notice.',
+            return sprintf(_m('One person has favored this notice.',
                               '%d people have favored this notice.',
                               $count),
                            $count);
@@ -482,8 +532,7 @@ class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
         } else {
             // TRANS: List message for repeated notices.
             // TRANS: %d is the number of users that have repeated a notice.
-            return sprintf(_m('REPEATLIST',
-                              'One person has repeated this notice.',
+            return sprintf(_m('One person has repeated this notice.',
                               '%d people have repeated this notice.',
                               $count),
                            $count);