2 if(class_exists('Conversation'))
5 require_once('boot.php');
6 require_once('object/BaseObject.php');
7 require_once('object/Item.php');
8 require_once('include/text.php');
13 * We should think about making this a SPL Iterator
15 class Conversation extends BaseObject {
16 private $threads = array();
18 private $writable = false;
19 private $profile_owner = 0;
20 private $preview = false;
22 public function __construct($mode, $preview) {
23 $this->set_mode($mode);
24 $this->preview = $preview;
28 * Set the mode we'll be displayed on
30 private function set_mode($mode) {
31 if($this->get_mode() == $mode)
34 $a = $this->get_app();
39 $this->profile_owner = local_user();
40 $this->writable = true;
43 $this->profile_owner = $a->profile['profile_uid'];
44 $this->writable = can_write_wall($a,$this->profile_owner);
47 $this->profile_owner = $a->profile['uid'];
48 $this->writable = can_write_wall($a,$this->profile_owner);
51 logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
61 public function get_mode() {
66 * Check if page is writable
68 public function is_writable() {
69 return $this->writable;
73 * Check if page is a preview
75 public function is_preview() {
76 return $this->preview;
82 public function get_profile_owner() {
83 return $this->profile_owner;
87 * Add a thread to the conversation
90 * _ The inserted item on success
93 public function add_thread($item) {
94 $item_id = $item->get_id();
96 logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
99 if($this->get_thread($item->get_id())) {
100 logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
105 * Only add will be displayed
107 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
108 logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG);
111 if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
112 logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG);
115 $item->set_conversation($this);
116 $this->threads[] = $item;
117 return end($this->threads);
121 * Get data in a form usable by a conversation template
123 * We should find a way to avoid using those arguments (at least most of them)
126 * _ The data requested on success
129 public function get_template_data($alike, $dlike) {
133 foreach($this->threads as $item) {
134 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
136 $item_data = $item->get_template_data($alike, $dlike);
138 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
141 $result[] = $item_data;
144 //$a->mark_timestamp();
149 * Get a thread based on its item id
152 * _ The found item on success
155 private function get_thread($id) {
156 foreach($this->threads as $item) {
157 if($item->get_id() == $id)