function get_user_chat_info($chat_id, $user_id){
$builder = $this->db->table('chats cht')
->select('cht.chat_id, cht.room_id, cht.user_id, cht.recipient_id, cht.admin_id, cht.started_at, cht.total_participants, cht.total_messages, cht.last_message_at, COUNT(eu.participant_id) as joined, COUNT(blk.block_id) as blocked')
->join('chat_participants eu', 'eu.room_id=cht.room_id AND eu.user_id='.$user_id, 'LEFT')
->join('blocks blk', 'blk.chat_id=cht.chat_id AND blk.user_id='.$user_id, 'LEFT')
->having('joined > 0 OR COUNT(CASE WHEN cht.user_id = '.$user_id.' OR cht.recipient_id = '.$user_id.' THEN 1 END) >= 1')
->where('cht.chat_id', $chat_id)
->groupBy('cht.chat_id');
$query = $builder->get();
$db_data = $query->getRowArray();
if($db_data){
$select_participant = 'participant_id, room_id, chat_id, user_id, participant_at';
$where_participant = array('chat_id' => $chat_id);
$db_data['participants'] = $this->get_all_chat_participants($where_participant, $select_participant);
}
return $db_data;
}