예제 #1
0
 public function thread($username)
 {
     if ($username) {
         if ($username != $this->session->userdata["user_username"]) {
             $custom_model = new Custom_model();
             $redis_functions = new Redisfunctions();
             $data = array();
             $user_id = $this->session->userdata["user_id"];
             $user_to_records = $redis_functions->get_user_profile_data($username);
             $records = $custom_model->get_chat_history($user_id, $user_to_records['user_id']);
             $chat_list_records = $custom_model->get_inbox_list($user_id);
             //            Setting and getting unread chats username to redis
             $redis_functions->set_unread_chats_username($this->session->userdata["user_username"]);
             $unread_chats_username = $redis_functions->get_unread_chats_username($this->session->userdata["user_username"]);
             //            Marking previous messages as read
             if (!empty($records)) {
                 $latest_message_id = $records[count($records) - 1]['message_id'];
                 $this->mark_previous_messages_as_read($latest_message_id, $user_id, $user_to_records['user_id']);
             }
             $to_user_fullname = stripslashes($user_to_records['user_fullname']);
             $to_user_username = stripslashes($user_to_records['user_username']);
             $page_title = $to_user_fullname;
             $input_arr = array(base_url() => 'Home', base_url('my-chats') => 'My Chats', '#' => $page_title);
             $breadcrumbs = get_breadcrumbs($input_arr);
             $data["breadcrumbs"] = $breadcrumbs;
             $data["chat_list_records"] = $chat_list_records;
             $data["unread_chats_username"] = $unread_chats_username;
             $data["records"] = $records;
             $data["page_title"] = $page_title;
             $data["to_user_fullname"] = $to_user_fullname;
             $data["to_user_username"] = $to_user_username;
             $data['meta_title'] = $page_title . ' | ' . $this->redis_functions->get_site_setting('SITE_NAME');
             $data['display_thread'] = TRUE;
             $this->template->write_view("content", "pages/messages/list", $data);
             $this->template->render();
         } else {
             $this->session->set_flashdata('error', 'You should socialize more and not just chat with yourself');
             redirect(base_url('my-chats'));
         }
     } else {
         redirect(base_url('my-chats'));
     }
 }