3 * StatusNet, the distributed open-source microblogging tool
5 * widget for displaying a list of notices
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Brion Vibber <brion@status.net>
25 * @copyright 2011 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('GNUSOCIAL')) { exit(1); }
33 * widget for displaying a list of notices
35 * There are a number of actions that display a list of notices, in
36 * reverse chronological order. This widget abstracts out most of the
37 * code for UI for notice lists. It's overridden to hide some
38 * data for e.g. the profile page.
42 * @author Evan Prodromou <evan@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
47 * @see ProfileNoticeList
49 class ThreadedNoticeList extends NoticeList
51 protected $userProfile;
53 function __construct(Notice $notice, Action $out=null, $profile=-1)
55 parent::__construct($notice, $out);
56 if (is_int($profile) && $profile == -1) {
57 $profile = Profile::current();
59 $this->userProfile = $profile;
63 * show the list of notices
65 * "Uses up" the stream by looping through it. So, probably can't
66 * be called twice on the same list.
68 * @return int count of notices listed.
72 $this->out->elementStart('div', array('id' =>'notices_primary'));
73 // TRANS: Header for Notices section.
74 $this->out->element('h2', null, _m('HEADER','Notices'));
75 $this->out->elementStart('ol', array('class' => 'notices threaded-notices xoxo'));
77 $notices = $this->notice->fetchAll();
78 $total = count($notices);
79 $notices = array_slice($notices, 0, NOTICES_PER_PAGE);
81 $allnotices = self::_allNotices($notices);
82 self::prefill($allnotices);
84 $conversations = array();
86 foreach ($notices as $notice) {
88 // Collapse repeats into their originals...
90 if ($notice->repeat_of) {
91 $orig = Notice::getKV('id', $notice->repeat_of);
92 if ($orig instanceof Notice) {
96 $convo = $notice->conversation;
97 if (!empty($conversations[$convo])) {
98 // Seen this convo already -- skip!
101 $conversations[$convo] = true;
103 // Get the convo's root notice
104 $root = $notice->conversationRoot($this->userProfile);
105 if ($root instanceof Notice) {
110 $item = $this->newListItem($notice);
112 } catch (Exception $e) {
113 // we log exceptions and continue
114 common_log(LOG_ERR, $e->getMessage());
119 $this->out->elementEnd('ol');
120 $this->out->elementEnd('div');
125 function _allNotices($notices)
128 foreach ($notices as $notice) {
129 $convId[] = $notice->conversation;
131 $convId = array_unique($convId);
132 $allMap = Notice::listGet('conversation', $convId);
134 foreach ($allMap as $convId => $convNotices) {
135 $allArray = array_merge($allArray, $convNotices);
141 * returns a new list item for the current notice
143 * Recipe (factory?) method; overridden by sub-classes to give
144 * a different list item class.
146 * @param Notice $notice the current notice
148 * @return NoticeListItem a list item for displaying the notice
150 function newListItem(Notice $notice)
152 return new ThreadedNoticeListItem($notice, $this->out, $this->userProfile);