3 * @file src/Object/Conversation.php
5 namespace Friendica\Object;
7 use Friendica\BaseObject;
8 use Friendica\Object\Item;
10 require_once 'boot.php';
11 require_once 'include/text.php';
16 * We should think about making this a SPL Iterator
18 class Conversation extends BaseObject
20 private $threads = array();
22 private $writable = false;
23 private $profile_owner = 0;
24 private $preview = false;
29 * @param string $mode The mode
30 * @param boolean $preview boolean value
32 public function __construct($mode, $preview)
34 $this->setMode($mode);
35 $this->preview = $preview;
39 * Set the mode we'll be displayed on
41 * @param string $mode The mode to set
45 private function setMode($mode)
47 if ($this->getMode() == $mode) {
56 $this->profile_owner = local_user();
57 $this->writable = true;
60 $this->profile_owner = $a->profile['profile_uid'];
61 $this->writable = can_write_wall($a, $this->profile_owner);
64 $this->profile_owner = $a->profile['uid'];
65 $this->writable = can_write_wall($a, $this->profile_owner);
68 logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
80 public function getMode()
86 * Check if page is writable
90 public function isWritable()
92 return $this->writable;
96 * Check if page is a preview
100 public function isPreview()
102 return $this->preview;
110 public function getProfileOwner()
112 return $this->profile_owner;
116 * Add a thread to the conversation
118 * @param object $item The item to insert
120 * @return mixed The inserted item on success
123 public function addThread($item)
125 $item_id = $item->getId();
128 logger('[ERROR] Conversation::addThread : Item has no ID!!', LOGGER_DEBUG);
132 if ($this->getThread($item->getId())) {
133 logger('[WARN] Conversation::addThread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG);
138 * Only add will be displayed
140 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
141 logger('[WARN] Conversation::addThread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG);
145 if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
146 logger('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG);
150 $item->setConversation($this);
151 $this->threads[] = $item;
153 return end($this->threads);
157 * Get data in a form usable by a conversation template
159 * We should find a way to avoid using those arguments (at least most of them)
161 * @param object $conv_responses data
163 * @return mixed The data requested on success
166 public function getTemplateData($conv_responses)
172 foreach ($this->threads as $item) {
173 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
177 $item_data = $item->getTemplateData($conv_responses);
180 logger('[ERROR] Conversation::getTemplateData : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG);
183 $result[] = $item_data;
190 * Get a thread based on its item id
192 * @param integer $id Item id
194 * @return mixed The found item on success
197 private function getThread($id)
199 foreach ($this->threads as $item) {
200 if ($item->getId() == $id) {