Commit e6bd58cb authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4979 (Instant Messaging problems with conversation-detection)

parent 6819ba50
Loading
Loading
Loading
Loading
+0 −0

File changed.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+1 −1
Original line number Diff line number Diff line
@@ -465,7 +465,7 @@ class Module_chat
        // Starting an IM? The IM will popup by AJAX once the page loads, because it's in the system now
        $enter_im = get_param_integer('enter_im', null);
        if ((!is_null($enter_im)) && (!is_guest())) {
            $test = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval($enter_im) . '%') . '\'');
            $test = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE ' . sql_members_in_im_conversation(array(get_member(), $enter_im)));
            $found_one = false;
            foreach ($test as $t) {
                if ((check_chatroom_access($t, true, $enter_im)) && (check_chatroom_access($t, true, get_member()))) {
+17 −2
Original line number Diff line number Diff line
@@ -422,7 +422,7 @@ function _chat_messages_script_ajax($room_id, $backlog = false, $message_id = nu
        }
        $welcome = ((array_key_exists(get_member(), get_chatters_in_room($room_id))) || (!$backlog) || (get_param_integer('no_reenter_message', 0) == 1)) ? null : $room_row['c_welcome'];
    } else {
        $room_check = $GLOBALS['SITE_DB']->query('SELECT id,is_im,c_welcome,allow_list_groups,disallow_list_groups,allow_list,disallow_list,room_owner FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval(get_member()) . '%') . '\'');
        $room_check = $GLOBALS['SITE_DB']->query('SELECT id,is_im,c_welcome,allow_list_groups,disallow_list_groups,allow_list,disallow_list,room_owner FROM ' . get_table_prefix() . 'chat_rooms WHERE ' . sql_members_in_im_conversation(array(get_member())));

        $welcome = null;
    }
@@ -523,7 +523,7 @@ function _chat_messages_script_ajax($room_id, $backlog = false, $message_id = nu
    // IM events and invitations, but only for the lobby IM interface
    $invitations_output = '';
    if ($room_id < 0) {
        $room_check = list_to_map('id', $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE is_im=1 AND allow_list LIKE \'' . db_encode_like('%' . strval(get_member()) . '%') . '\''));
        $room_check = list_to_map('id', $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'chat_rooms WHERE ' . sql_members_in_im_conversation(array(get_member()))));
        foreach ($room_check as $room) {
            if (check_chatroom_access($room, true, null, true)) {
                if ((($room['allow_list'] == strval(get_member()) . ',' . strval(get_member())/*Opened room with self? Weird*/) || ($room['allow_list'] == strval(get_member()))) && (is_null($event_id)/*Only on fresh start, not repeat AJAX requests*/)) { // If it's just you in the room, close that room down
@@ -1622,3 +1622,18 @@ function get_chat_sound_tpl()
    $sound_effects = get_effect_settings(true, null, true);
    return do_template('CHAT_SOUND', array('_GUID' => '102c9574a2563143683970595df74011', 'SOUND_EFFECTS' => $sound_effects));
}

/**
 * Get SQL for finding an IM conversation between certain members.
 *
 * @param array $member_ids The member IDs
 * @return string SQL
 */
function sql_members_in_im_conversation($member_ids)
{
    $sql = 'is_im=1';
    foreach ($member_ids as $member_id) {
        $sql .= ' AND ' . db_function('CONCAT', array('\',\'', 'allow_list', '\',\'')) . ' LIKE \'' . db_encode_like('%,' . strval($member_id) . ',%') . '\'';
    }
    return $sql;
}