/**
  * Get the thread count of a given message
  * @param type $user_id
  * @param type $conv_id conversation_id
  * @return type
  */
 public function getThreadCount($user_id = null, $conv_id = null)
 {
     if ($conv_id === NULL) {
         $conv_id = $this->conversation_id;
     }
     if ($user_id === NULL) {
         $user_id = Yii::app()->user->id;
     }
     return MsgMessageCopiesView::model()->getTotals('(`conversation_id`=:t1 AND `user_id`=:t2)', array(':t1' => $conv_id, ':t2' => $user_id));
 }
 public function actionGetNotifications($unread = NULL)
 {
     $conditions = '(`user_id`=:t1 and `read`=:t2)';
     $params = array(':t1' => Yii::app()->user->id, ':t2' => 0);
     $new_unread = MsgMessageCopies::model()->getTotals($conditions, $params);
     if ($unread == $new_unread) {
         echo CJSON::encode(array('unread' => $new_unread, 'html' => FALSE));
         Yii::app()->end();
     }
     $data = MsgMessageCopiesView::model()->getData('id,from_user_id,topic,message,from,date_created', $conditions, $params, 'id desc', 5);
     $html = $this->renderPartial('msg.views.layouts._topbar_messages_list', array('data' => $data, 'count' => $new_unread), TRUE, FALSE);
     echo CJSON::encode(array('unread' => $new_unread, 'html' => $html));
 }