Exemplo n.º 1
0
/**
 * Get the messages sent to the channel after a given time
 * 
 * @param type $channel_id
 * @param int $time timestamp
 * @return type
 */
function bpchat_get_recent_channel_messages($channel_id, $time)
{
    $messages = BP_Chat_Channel::get_messages_after($time);
    $messages = bpchat_extend_messages($messages);
    return $messages;
}
Exemplo n.º 2
0
 /** check for the new chat requests, list which which we are chatting currently or the messages we have recieved for the user */
 public function get_updates_for_user()
 {
     global $bp, $wpdb;
     $user_id = get_current_user_id();
     $last_fetch_time = $_POST["fetch_time"];
     //$time=gmdate("Y-m-d H:i:s",  time());
     $bpchat = bp_chat();
     // $query = "SELECT msg.id,msg.channel_id, msg.message, msg.sender_id,msg.message,msg.sent_at FROM {$bp->chat->table_chat_messages} msg, WHERE msg.channel_id IN( SELECT channel_id FROM {$bp->chat->table_channel_users} where user_id=%d and status <> 'closed') and msg.sent_at >= '".$last_fetch_time."'  ORDER BY msg.sent_at ASC ";
     $query = "SELECT msg.id,msg.channel_id, msg.message, msg.sender_id,msg.message,msg.sent_at FROM {$bpchat->table_name_messages} msg WHERE msg.channel_id IN( SELECT channel_id FROM {$bpchat->table_name_channel_users} where user_id=%d and status <> 'closed') and msg.sent_at >= '" . $last_fetch_time . "' ORDER BY msg.sent_at ASC ";
     $q = $wpdb->prepare($query, $user_id);
     $messages = $wpdb->get_results($q);
     //array of message objects
     $time = current_time('timestamp');
     $messages = bpchat_extend_messages($messages);
     $query_status = "SELECT c.channel_id,c.status, c.user_id,u.is_online,IF (DATE_ADD( u.last_active_time, INTERVAL 30 SECOND ) >= NOW(), 'active','idle') as user_status  FROM {$bpchat->table_name_channel_users} c,{$bpchat->table_name_users} u WHERE c.channel_id IN( SELECT channel_id FROM {$bpchat->table_name_channel_users} where user_id=%d and status <> 'closed') AND c.user_id!=%d and u.user_id=c.user_id ORDER BY channel_id DESC ";
     $status = $wpdb->get_results($wpdb->prepare($query_status, $user_id, $user_id));
     //update last fetch time for user
     bpchat_update_fetch_time($user_id);
     //update the fetch time
     $response = array("messages" => $messages, "fetch_time" => $time, "status" => $status);
     echo json_encode($response);
     exit(0);
 }