3 * @file src/Object/Thread.php
5 namespace Friendica\Object;
7 use Friendica\BaseObject;
8 use Friendica\Object\Post;
10 require_once 'boot.php';
11 require_once 'include/text.php';
16 * We should think about making this a SPL Iterator
18 class Thread extends BaseObject
20 private $parents = array();
22 private $writable = false;
23 private $profile_owner = 0;
24 private $preview = false;
29 * @param string $mode The mode
30 * @param boolean $preview Are we in the preview mode?
31 * @param boolean $writable Override the writable check
33 public function __construct($mode, $preview, $writable = false)
35 $this->setMode($mode, $writable);
36 $this->preview = $preview;
40 * Set the mode we'll be displayed on
42 * @param string $mode The mode to set
43 * @param boolean $writable Override the writable check
47 private function setMode($mode, $writable)
49 if ($this->getMode() == $mode) {
58 $this->profile_owner = local_user();
59 $this->writable = true;
62 $this->profile_owner = $a->profile['profile_uid'];
63 $this->writable = can_write_wall($this->profile_owner);
66 $this->profile_owner = $a->profile['uid'];
67 $this->writable = can_write_wall($this->profile_owner) || $writable;
70 $this->profile_owner = 0;
71 $this->writable = $writable;
74 logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
86 public function getMode()
92 * Check if page is writable
96 public function isWritable()
98 return $this->writable;
102 * Check if page is a preview
106 public function isPreview()
108 return $this->preview;
116 public function getProfileOwner()
118 return $this->profile_owner;
122 * Add a thread to the conversation
124 * @param object $item The item to insert
126 * @return mixed The inserted item on success
129 public function addParent(Post $item)
131 $item_id = $item->getId();
134 logger('[ERROR] Conversation::addThread : Item has no ID!!', LOGGER_DEBUG);
138 if ($this->getParent($item->getId())) {
139 logger('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG);
144 * Only add will be displayed
146 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
147 logger('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG);
151 if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
152 logger('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG);
156 $item->setThread($this);
157 $this->parents[] = $item;
159 return end($this->parents);
163 * Get data in a form usable by a conversation template
165 * We should find a way to avoid using those arguments (at least most of them)
167 * @param object $conv_responses data
169 * @return mixed The data requested on success
172 public function getTemplateData($conv_responses)
178 foreach ($this->parents as $item) {
179 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
183 $item_data = $item->getTemplateData($conv_responses);
186 logger('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG);
189 $result[] = $item_data;
196 * Get a thread based on its item id
198 * @param integer $id Item id
200 * @return mixed The found item on success
203 private function getParent($id)
205 foreach ($this->parents as $item) {
206 if ($item->getId() == $id) {