3 * @file src/Object/Thread.php
5 namespace Friendica\Object;
7 use Friendica\BaseObject;
8 use Friendica\Core\Protocol;
9 use Friendica\Object\Post;
11 require_once 'boot.php';
12 require_once 'include/text.php';
17 * We should think about making this a SPL Iterator
19 class Thread extends BaseObject
21 private $parents = [];
23 private $writable = false;
24 private $profile_owner = 0;
25 private $preview = false;
30 * @param string $mode The mode
31 * @param boolean $preview Are we in the preview mode?
32 * @param boolean $writable Override the writable check
34 public function __construct($mode, $preview, $writable = false)
36 $this->setMode($mode, $writable);
37 $this->preview = $preview;
41 * Set the mode we'll be displayed on
43 * @param string $mode The mode to set
44 * @param boolean $writable Override the writable check
48 private function setMode($mode, $writable)
50 if ($this->getMode() == $mode) {
59 $this->profile_owner = local_user();
60 $this->writable = true;
63 $this->profile_owner = $a->profile['profile_uid'];
64 $this->writable = can_write_wall($this->profile_owner);
67 $this->profile_owner = $a->profile['uid'];
68 $this->writable = can_write_wall($this->profile_owner) || $writable;
71 $this->profile_owner = 0;
72 $this->writable = $writable;
75 logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
87 public function getMode()
93 * Check if page is writable
97 public function isWritable()
99 return $this->writable;
103 * Check if page is a preview
107 public function isPreview()
109 return $this->preview;
117 public function getProfileOwner()
119 return $this->profile_owner;
123 * Add a thread to the conversation
125 * @param object $item The item to insert
127 * @return mixed The inserted item on success
130 public function addParent(Post $item)
132 $item_id = $item->getId();
135 logger('[ERROR] Conversation::addThread : Item has no ID!!', LOGGER_DEBUG);
139 if ($this->getParent($item->getId())) {
140 logger('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG);
145 * Only add will be displayed
147 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
148 logger('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG);
152 if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
153 logger('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG);
157 $item->setThread($this);
158 $this->parents[] = $item;
160 return end($this->parents);
164 * Get data in a form usable by a conversation template
166 * We should find a way to avoid using those arguments (at least most of them)
168 * @param object $conv_responses data
170 * @return mixed The data requested on success
173 public function getTemplateData($conv_responses)
179 foreach ($this->parents as $item) {
180 if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
184 $item_data = $item->getTemplateData($conv_responses);
187 logger('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG);
190 $result[] = $item_data;
197 * Get a thread based on its item id
199 * @param integer $id Item id
201 * @return mixed The found item on success
204 private function getParent($id)
206 foreach ($this->parents as $item) {
207 if ($item->getId() == $id) {