<commit_before>const Notifications = require('react-notification-system-redux');
import Connection from '../../sockets/Connection';
import Player from '../players/Player';
import AI from '../players/AI';
import Game from '../games/Game';
import Message from './Message';

export default class Room {
    private _players: Player [];
    private _messages: Message [];
    private _priv: boolean;
    private _id: number;
    private _voiceChat: boolean;
    private _maxPlayers: number;
    private _name: string;
    private _time: any;
    private gameStartAction: string;
    private newMoveAction: string;
    private timer: any = null;
    
    static numRooms: number = 0;
    
    constructor(private io: any, private _game: Game) {
        this._messages = []; //a list of all the messages stored for that room
        this._players = []; //a list of all players in the room
        Room.numRooms++;
        this._id = Room.numRooms;
        // set up the action string depending on game type
        switch (this.getGameType()) {
            case "four-player":
                this.gameStartAction = "four-game-started";
                this.newMoveAction = "four-new-move";
                break;
            case "standard":
            case "crazyhouse":
            case "crazyhouse960":
            default:
                this.gameStartAction = "game-started";
                this.newMoveAction = "new-move";
                break;
        }
    }
    
    setRoomAttributes(roomObj: any): boolean {
        if( typeof roomObj.private == undefined
            || typeof roomObj.voiceChat == undefined 
            || typeof roomObj.maxPlayers == undefined
            || typeof roomObj.name == undefined) {
            return false;        
        }
        this._priv = roomObj.private;
        this._voiceChat = roomObj.voiceChat;
        this._maxPlayers = roomObj.maxPlayers;
        this._name = roomObj.name;
        return true;
    }
    
    getRoom(): Object {
        let game;
        
        if(this._game) {
            
            let times = this._game.times;
            game = this._game.getGame();
            return {
                id: this._id,
                room: {
                    name: this._name,
                    private: this._priv,
                    voiceChat: this._voiceChat,
                    maxPlayers: this._maxPlayers
                },
                gameType: this._game.gameType,
                users: this.getAllRoomPlayersWithoutSockets(),
                messages: this.getLast30Messages(),
                numMessages: this._messages.length,
                time: this._time,
                times: times,
                game: game
            };
        }
    }
    
    getRoomCondensed(): Object {
        return {
            id: this._id,
            room: {
                name: this._name,
                private: this._priv,
                voiceChat: this._voiceChat,
                maxPlayers: this._maxPlayers
            },
            gameType: this._game.gameType,
            numPlayers: this._players.length,
            time: this._time,
        };
    }
    
    getNumberOfPlayers() {
        return this._players.length;
    }
    
    getLast30Messages() {
        let mess = [];
        let tmp = this._messages.slice(Math.max(this._messages.length - 30, 1));
        tmp.map(message => {
            mess.push(message.getMessage());
        });
        
        return mess;
    }
    
    getAllMessages() {
        let mess = [];
        this._messages.map(message => {
            mess.push(message.getMessage()); 
        });
        
        return mess;
    }
    
    addPlayer(playerObj: Player) {
        playerObj.socket.join(this._name);<commit_msg>Fix fetching chat messages<commit_after>const Notifications = require('react-notification-system-redux');
import Connection from '../../sockets/Connection';
import Player from '../players/Player';
import AI from '../players/AI';
import Game from '../games/Game';
import Message from './Message';

export default class Room {
    private _players: Player [];
    private _messages: Message [];
    private _priv: boolean;
    private _id: number;
    private _voiceChat: boolean;
    private _maxPlayers: number;
    private _name: string;
    private _time: any;
    private gameStartAction: string;
    private newMoveAction: string;
    private timer: any = null;
    
    static numRooms: number = 0;
    
    constructor(private io: any, private _game: Game) {
        this._messages = []; //a list of all the messages stored for that room
        this._players = []; //a list of all players in the room
        Room.numRooms++;
        this._id = Room.numRooms;
        // set up the action string depending on game type
        switch (this.getGameType()) {
            case "four-player":
                this.gameStartAction = "four-game-started";
                this.newMoveAction = "four-new-move";
                break;
            case "standard":
            case "crazyhouse":
            case "crazyhouse960":
            default:
                this.gameStartAction = "game-started";
                this.newMoveAction = "new-move";
                break;
        }
    }
    
    setRoomAttributes(roomObj: any): boolean {
        if( typeof roomObj.private == undefined
            || typeof roomObj.voiceChat == undefined 
            || typeof roomObj.maxPlayers == undefined
            || typeof roomObj.name == undefined) {
            return false;        
        }
        this._priv = roomObj.private;
        this._voiceChat = roomObj.voiceChat;
        this._maxPlayers = roomObj.maxPlayers;
        this._name = roomObj.name;
        return true;
    }
    
    getRoom(): Object {
        let game;
        
        if(this._game) {
            
            let times = this._game.times;
            game = this._game.getGame();
            return {
                id: this._id,
                room: {
                    name: this._name,
                    private: this._priv,
                    voiceChat: this._voiceChat,
                    maxPlayers: this._maxPlayers
                },
                gameType: this._game.gameType,
                users: this.getAllRoomPlayersWithoutSockets(),
                messages: this.getLastNMessages(30),
                numMessages: this._messages.length,
                time: this._time,
                times: times,
                game: game
            };
        }
    }
    
    getRoomCondensed(): Object {
        return {
            id: this._id,
            room: {
                name: this._name,
                private: this._priv,
                voiceChat: this._voiceChat,
                maxPlayers: this._maxPlayers
            },
            gameType: this._game.gameType,
            numPlayers: this._players.length,
            time: this._time,
        };
    }
    
    getNumberOfPlayers() {
        return this._players.length;
    }
    
    getLastNMessages(n) {
        return this.getAllMessages().slice(-n);
    }
    
    getAllMessages() {
        return this._messages.map(m => m.getMessage());
    }
    
    addPlayer(playerObj: Player) {
        playerObj.socket.join(this._name);
{'fraction_non_alphanumeric': 0.10135970333745364, 'fraction_numerical': 0.002334844114819393, 'mean_word_length': 1.529350468912817, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797415', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1872, 'n_words': 456}