]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/threadednoticelistitem.php
Faster inboxnoticestream.php by XRevan86.
[quix0rs-gnu-social.git] / lib / threadednoticelistitem.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 /**
6  * widget for displaying a single notice
7  *
8  * This widget has the core smarts for showing a single notice: what to display,
9  * where, and under which circumstances. Its key method is show(); this is a recipe
10  * that calls all the other show*() methods to build up a single notice. The
11  * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
12  * author info (since that's implicit by the data in the page).
13  *
14  * @category UI
15  * @package  StatusNet
16  * @author   Evan Prodromou <evan@status.net>
17  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
18  * @link     http://status.net/
19  * @see      NoticeList
20  * @see      ProfileNoticeListItem
21  */
22 class ThreadedNoticeListItem extends NoticeListItem
23 {
24     protected $userProfile = null;
25
26     function __construct(Notice $notice, Action $out=null, $profile=null)
27     {
28         parent::__construct($notice, $out);
29         $this->userProfile = $profile;
30     }
31
32     function initialItems()
33     {
34         return 3;
35     }
36
37     /**
38      * finish the notice
39      *
40      * Close the last elements in the notice list item
41      *
42      * @return void
43      */
44     function showEnd()
45     {
46         $max = $this->initialItems();
47         if (!$this->repeat instanceof Notice) {
48             $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
49             $notice = $stream->getNotices(0, $max + 2);
50             $notices = array();
51             $cnt = 0;
52             $moreCutoff = null;
53             while ($notice->fetch()) {
54                 if (Event::handle('StartAddNoticeReply', array($this, $this->notice, $notice))) {
55                     // Don't list repeats as separate notices in a conversation
56                     if (!empty($notice->repeat_of)) {
57                         continue;
58                     }
59
60                     if ($notice->id == $this->notice->id) {
61                         // Skip!
62                         continue;
63                     }
64
65                     if (!$notice->isVerb([ActivityVerb::POST])) {
66                         continue;
67                     }
68
69                     $cnt++;
70                     if ($cnt > $max) {
71                         // boo-yah
72                         $moreCutoff = clone($notice);
73                         break;
74                     }
75                     $notices[] = clone($notice); // *grumble* inefficient as hell
76                     Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice));
77                 }
78             }
79
80             if (Event::handle('StartShowThreadedNoticeTail', array($this, $this->notice, &$notices))) {
81                 $threadActive = count($notices) > 0; // has this thread had any activity?
82
83                 $this->out->elementStart('ul', 'notices threaded-replies xoxo');
84
85                 if (Event::handle('StartShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive))) {
86                     // Repeats and Faves/Likes are handled in plugins.
87                     Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
88                 }
89
90                 if (count($notices)>0) {
91                     if ($moreCutoff) {
92                         $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
93                         $item->show();
94                     }
95                     foreach (array_reverse($notices) as $notice) {
96                         if (Event::handle('StartShowThreadedNoticeSub', array($this, $this->notice, $notice))) {
97                             $item = new ThreadedNoticeListSubItem($notice, $this->notice, $this->out);
98                             $item->show();
99                             Event::handle('EndShowThreadedNoticeSub', array($this, $this->notice, $notice));
100                         }
101                     }
102                 }
103
104                 Event::handle('EndShowThreadedNoticeTail', array($this, $this->notice, $notices));
105                 $this->out->elementEnd('ul');
106             }
107         }
108
109         parent::showEnd();
110     }
111 }