2 if (class_exists('Conversation')) {
6 require_once('boot.php');
7 require_once('object/BaseObject.php');
8 require_once('object/Item.php');
9 require_once('include/text.php');
14 * We should think about making this a SPL Iterator
16 class Conversation extends BaseObject {
17 private $threads = array();
19 private $writable = false;
20 private $profile_owner = 0;
21 private $preview = false;
23 public function __construct($mode, $preview) {
24 $this->set_mode($mode);
25 $this->preview = $preview;
29 * Set the mode we'll be displayed on
31 private function set_mode($mode) {
32 if ($this->get_mode() == $mode)
35 $a = $this->get_app();
40 $this->profile_owner = local_user();
41 $this->writable = true;
44 $this->profile_owner = $a->profile['profile_uid'];
45 $this->writable = can_write_wall($a,$this->profile_owner);
48 $this->profile_owner = $a->profile['uid'];
49 $this->writable = can_write_wall($a,$this->profile_owner);
52 logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
62 public function get_mode() {
67 * Check if page is writable
69 public function is_writable() {
70 return $this->writable;
74 * Check if page is a preview
76 public function is_preview() {
77 return $this->preview;
83 public function get_profile_owner() {
84 return $this->profile_owner;
88 * Add a thread to the conversation
91 * _ The inserted item on success
94 public function add_thread($item) {
95 $item_id = $item->get_id();
97 logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
100 if ($this->get_thread($item->get_id())) {
101 logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
106 * Only add will be displayed
108 if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
109 logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG);
112 if ($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
113 logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG);
116 $item->set_conversation($this);
117 $this->threads[] = $item;
118 return end($this->threads);
122 * Get data in a form usable by a conversation template
124 * We should find a way to avoid using those arguments (at least most of them)
127 * _ The data requested on success
130 public function get_template_data($conv_responses) {
136 foreach ($this->threads as $item) {
137 if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
141 $item_data = $item->get_template_data($conv_responses);
144 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
147 $result[] = $item_data;
154 * Get a thread based on its item id
157 * _ The found item on success
160 private function get_thread($id) {
161 foreach ($this->threads as $item) {
162 if ($item->get_id() == $id) {