public function postMessage()
 {
     $parentId = (int) $this->getParameter('pid');
     $message = $this->getRequiredParameter('message');
     if ($parentId > 0) {
         $title = 0;
         $to = MessageUsers::where('message_id', $parentId)->lists('user_id');
     } else {
         $title = $this->getRequiredParameter('title');
         $to = (array) $this->getRequiredParameter('to');
     }
     (new Messages())->sendMessage($title, $message, $to, $parentId, $this->currentUser->id);
 }
 /**
  * @param int $userId
  * @param int $messageId
  * @return bool
  */
 public function deleteByUserId($userId, $messageId)
 {
     MessageUsers::where('user_id', (int) $userId)->where(function ($query) {
         $query->where('message_id', (int) $messageId)->or_where('parent_id', (int) $messageId);
     })->delete();
     $count = (int) MessageUsers::select('COUNT(*) as total')->where('message_id', (int) $messageId)->pluck('total');
     if ($count == 0) {
         $this->deleteById($messageId);
     }
     return TRUE;
 }