3 * @file src/Core/Conversation.php
5 namespace Friendica\Core;
7 if (class_exists('Conversation')) {
11 use Friendica\Core\BaseObject;
12 use Friendica\Core\Item;
14 require_once 'boot.php';
15 require_once 'include/text.php';
20 * We should think about making this a SPL Iterator
22 class Conversation extends BaseObject
24 private $threads = array();
26 private $writable = false;
27 private $profile_owner = 0;
28 private $preview = false;
30 public function __construct($mode, $preview)
32 $this->set_mode($mode);
33 $this->preview = $preview;
37 * Set the mode we'll be displayed on
39 private function set_mode($mode)
41 if ($this->get_mode() == $mode) {
45 $a = $this->get_app();
50 $this->profile_owner = local_user();
51 $this->writable = true;
54 $this->profile_owner = $a->profile['profile_uid'];
55 $this->writable = can_write_wall($a, $this->profile_owner);
58 $this->profile_owner = $a->profile['uid'];
59 $this->writable = can_write_wall($a, $this->profile_owner);
62 logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
72 public function get_mode()
78 * Check if page is writable
80 public function is_writable()
82 return $this->writable;
86 * Check if page is a preview
88 public function is_preview()
90 return $this->preview;
96 public function get_profile_owner()
98 return $this->profile_owner;
102 * Add a thread to the conversation
105 * _ The inserted item on success
108 public function add_thread($item)
110 $item_id = $item->getId();
113 logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
117 if ($this->get_thread($item->getId())) {
118 logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->getId() .').', LOGGER_DEBUG);
123 * Only add will be displayed
125 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
126 logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->getId() .').', LOGGER_DEBUG);
130 if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
131 logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->getId() .').', LOGGER_DEBUG);
135 $item->setConversation($this);
136 $this->threads[] = $item;
138 return end($this->threads);
142 * Get data in a form usable by a conversation template
144 * We should find a way to avoid using those arguments (at least most of them)
147 * _ The data requested on success
150 public function get_template_data($conv_responses)
156 foreach ($this->threads as $item) {
157 if ($item->getDataValue('network') === NETWORK_MAIL && local_user() != $item->getDataValue('uid')) {
161 $item_data = $item->getTemplateData($conv_responses);
164 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->getId() .').', LOGGER_DEBUG);
167 $result[] = $item_data;
174 * Get a thread based on its item id
177 * _ The found item on success
180 private function get_thread($id)
182 foreach ($this->threads as $item) {
183 if ($item->getId() == $id) {