/**
  * The POST handler for status changes from the admin table
  *
  * @author caseypatrickdriscoll
  *
  * @created 2015-07-18 17:49:02
  * @edited  2015-07-24 19:56:52 - Refactors to use move function
  * @edited  2015-08-28 18:12:26 - Adds user validation on change_chat_status
  *
  * TODO: Validate and sanitize fields
  *
  */
 public static function change_chat_status()
 {
     if (!is_user_logged_in()) {
         wp_send_json_error('Not logged in');
     }
     $chat = array('ID' => $_POST['chat_id'], 'prev_status' => $_POST['prev_status'], 'post_status' => $_POST['status']);
     $response = PatchChat_Controller::change_chat_status($chat);
     if ($response) {
         wp_send_json_success($response);
     } else {
         wp_send_json_error(0);
     }
 }
 /**
  * Changes the post_status of the given chat
  *
  * @author  caseypatrickdriscoll
  *
  * @created 2015-08-27 15:13:52
  * @edited  2015-08-28 17:58:30 - Refactors to prevent open and closed transient states
  * @edited  2015-08-28 18:14:09 - Adds fast update by returning user state on change_status
  * @edited  2015-08-28 20:38:24 - Adds auto comment for every status change
  * @edited  2015-08-29 18:45:34 - Adds PatchChat_Settings::status_change_message() for dynamic messages
  * 
  */
 public static function change_chat_status($chat)
 {
     // TODO: Assign agent when becomes 'open'
     // TODO: Create idea of assigned agents
     // TODO: Figure out security and sanitized stuff (although low priority as comes from select in admin POST)
     // TODO: Handle error situations, including missing data and error on update
     // TODO: Bulk status change in bulk editor
     // TODO: Style the selector based on status
     // TODO: Add thumbs up or signal if POST is success
     // 1. Update the post status and appropriate transients
     wp_update_post($chat);
     PatchChat_Transient::update($chat['ID'], 'status', $chat['post_status']);
     // 2. Add the comment
     $user = wp_get_current_user();
     $options = array('chatid' => $chat['ID'], 'agentname' => $user->display_name, 'status' => $chat['post_status']);
     $comment = array('comment_type' => 'auto', 'comment_post_ID' => $chat['ID'], 'comment_content' => PatchChat_Settings::status_change_message($options));
     if (self::add_comment($comment)) {
         return PatchChat_Controller::get_user_state();
     }
 }