<commit_before>var React = require('react');
var Actions = require('./Actions');

var Room = React.createClass({
    getInitialState: function(a, b, c, d) {
        return {
            unread: 0,
            read: 0,
        };
    },
    componentWillReceiveProps: function(a, b, c, d) {
        this.updateReadCount(this.props.currentRoom, this.props.room.chatlog);
    },
    handleSwitchClick: function(e) {
        Actions.switchRooms(this.props.room.id);
    },
    handleJoinClick: function(e) {
        Actions.joinRoom(this.props.room.id);
        Actions.switchRooms(this.props.room.id);
    },
    handleLeaveClick: function(e) {
        Actions.leaveRoom(this.props.room.id);
    },
    handleRemoveRoomClick: function(e) {
        Actions.closeRoom(this.props.room.id);
    },
    updateReadCount: function(currentRoom, chats) {
        var oldRead = this.state.read;
        var oldUnread = this.state.unread;
        var newRead, newUnread;
        if (this.props.room.id === currentRoom) {
            // If currentroom, then consider everything read;
            newRead = chats.length;
            newUnread = 0;
        } else {
            // Otherwise, consider any new messages unread
            newRead = oldRead;
            newUnread = chats.length - newRead;
        }
        this.setState({
            read: newRead,
            unread: newUnread
        });
    },
    render: function() {
        var currentRoom = this.props.currentRoom;
        var room = this.props.room;
        var rid = room.id;
        var self = this.props.self;
        var myId = self.id;
        var roomClass = "room ";
        var roomText = room.name;
        var myRoom = false;
        if (room.owner.id && myId === room.owner.id) {
            myRoom = true;
            roomClass += "myRoom ";
        }
        if (rid === currentRoom) {
            roomClass += "selected";
            var leaveRoom = "";
            if (!myRoom) {
                leaveRoom = <span onClick={this.handleLeaveClick}> - Leave room</span>;
            } else {
                leaveRoom = <span onClick={this.handleRemoveRoomClick}> - Remove room</span>;
            }
            return (
                <div className={roomClass}>
                    <div>{roomText}{leaveRoom}</div>
                    <ul>{
                        Object.keys(room.subscribers).
                            sort(function(a, b){
                                return room.subscribers[a].name.toLowerCase() > room.subscribers[b].name.toLowerCase();
                            }).map(function(uid){
                                return (<li key={rid + uid}>{room.subscribers[uid].name}</li>);
                            })
                    }</ul>
                </div>
            );
        } else if (room.subscribers.hasOwnProperty(myId)) {
            var unread = this.state.unread;
            if (unread > 0) {
                roomText += " - " + unread + " unread";
                roomClass += " unread";
            }
            return (
                <div className={roomClass}>
                    <div onClick={this.handleSwitchClick}>{roomText}</div>
                </div>
            );
        } else {
            roomText += " - Join";
            return (
                <div className={roomClass}>
                    <div onClick={this.handleJoinClick}>{roomText}</div>
                </div>
            );
        }
    }
});

module.exports = Room;<commit_msg>Prevent actions prior to login<commit_after>var React = require('react');
var Actions = require('./Actions');

var Room = React.createClass({
    getInitialState: function(a, b, c, d) {
        return {
            unread: 0,
            read: 0,
        };
    },
    componentWillReceiveProps: function(a, b, c, d) {
        this.updateReadCount(this.props.currentRoom, this.props.room.chatlog);
    },
    handleSwitchClick: function(e) {
        Actions.switchRooms(this.props.room.id);
    },
    handleJoinClick: function(e) {
        if (this.props.readyState === 1) {
            Actions.joinRoom(this.props.room.id);
            Actions.switchRooms(this.props.room.id);
        }
    },
    handleLeaveClick: function(e) {
        if (this.props.readyState === 1) {
            Actions.leaveRoom(this.props.room.id);
        }
    },
    handleRemoveRoomClick: function(e) {
        if (this.props.readyState === 1) {
            Actions.closeRoom(this.props.room.id);
        }
    },
    updateReadCount: function(currentRoom, chats) {
        var oldRead = this.state.read;
        var oldUnread = this.state.unread;
        var newRead, newUnread;
        if (this.props.room.id === currentRoom) {
            // If currentroom, then consider everything read;
            newRead = chats.length;
            newUnread = 0;
        } else {
            // Otherwise, consider any new messages unread
            newRead = oldRead;
            newUnread = chats.length - newRead;
        }
        this.setState({
            read: newRead,
            unread: newUnread
        });
    },
    render: function() {
        var currentRoom = this.props.currentRoom;
        var room = this.props.room;
        var rid = room.id;
        var self = this.props.self;
        var myId = self.id;
        var roomClass = "room ";
        var roomText = room.name;
        var myRoom = false;
        if (room.owner.id && myId === room.owner.id) {
            myRoom = true;
            roomClass += "myRoom ";
        }
        if (rid === currentRoom) {
            roomClass += "selected";
            var leaveRoom = "";
            if (!myRoom) {
                leaveRoom = <span onClick={this.handleLeaveClick}> - Leave room</span>;
            } else {
                leaveRoom = <span onClick={this.handleRemoveRoomClick}> - Remove room</span>;
            }
            return (
                <div className={roomClass}>
                    <div>{roomText}{leaveRoom}</div>
                    <ul>{
                        Object.keys(room.subscribers).
                            sort(function(a, b){
                                return room.subscribers[a].name.toLowerCase() > room.subscribers[b].name.toLowerCase();
                            }).map(function(uid){
                                return (<li key={rid + uid}>{room.subscribers[uid].name}</li>);
                            })
                    }</ul>
                </div>
            );
        } else if (room.subscribers.hasOwnProperty(myId)) {
            var unread = this.state.unread;
            if (unread > 0) {
                roomText += " - " + unread + " unread";
                roomClass += " unread";
            }
            return (
                <div className={roomClass}>
                    <div onClick={this.handleSwitchClick}>{roomText}</div>
                </div>
            );
        } else {
            roomText += " - Join";
            return (
                <div className={roomClass}>
                    <div onClick={this.handleJoinClick}>{roomText}</div>
                </div>
            );
        }
    }
});

module.exports = Room;
{'fraction_non_alphanumeric': 0.12664060318346831, 'fraction_numerical': 0.0015358838313320302, 'mean_word_length': 1.4191151637960149, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 47, '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': '713997', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1951, 'n_words': 380}