<commit_before>//
// Roomlist
//
var RoomListView = Backbone.View.extend({
    el: '#room-list',
    initialize: function() {
        var self = this;
        this.$list = this.$('.room-list');
        this.template = $('#js-tmpl-room-list-item').html();
        this.userTemplate = $('#js-tmpl-room-list-user').html();
        this.collection = this.options.collection;
        this.collection.bind('add', function(room) {
            self.add(_.extend(room.toJSON(), {
                lastActive: moment(room.get('lastActive')).calendar()
            }));
            //
            // Room meta update
            //
            room.bind('change', function(room) {
                self.updateRoom(_.extend(room.toJSON(), {
                    lastActive: moment(room.get('lastActive')).calendar()
                }));
            });
            //
            //  User events
            //
            room.users.bind('add', function(user, users) {
                var matches = users.where({
                    uid: user.get('uid'),
                    room: user.get('room')
                })
                if (matches.length == 1) {
                    self.addUser(user.toJSON());
                }
            });
            room.users.bind('remove', function(user, users) {
                var matches = users.where({
                    uid: user.get('uid'),
                    room: user.get('room')
                })
                if (matches.length < 1) {
                    self.removeUser(user.toJSON());
                }
            });
        });
        this.collection.bind('remove', function(room) {
            self.remove(room.id);
        });
        this.collection.bind('reset', function() {
            self.empty();
        });
        self.$list.masonry({
            itemSelector: '.room'
        });
        // Masonry shims
        this.options.notifications.on('homeselected', function() {
            self.updateMasonry(true);
        });
    },
    add: function(room) {
        var item = Mustache.to_html(this.template, room);
        this.$list.prepend(item);
        this.updateMasonry();
    },
    remove: function(id) {
        this.$('.room[data-id=' + id + ']').remove();
        this.updateMasonry();
    },
    addUser: function(user) {
        var html = Mustache.to_html(this.userTemplate, user);
        this.$('.room[data-id=' + user.room + '] .users').prepend(html);
        this.updateMasonry();
    },
    removeUser: function(user) {
        this.$('.room[data-id=' + user.room + ']')
          .find('.user[data-uid=' + user.uid + ']').remove();
        this.updateMasonry();
    },
    updateRoom: function(room) {
        var $room = this.$('.room[data-id=' + room.id + ']');
        $room.find('.name').text(room.name);
        $room.find('.description').text(room.description);
        $room.find('.last-active .value').text(room.lastActive);
    },
    //
    // Sort rooms by users in dom
    //
    sortRooms: function() {
        this.$('.room').tsort('', {
            sortFunction: function(a, b){
                var aCount = a.e.find('.user').length;
                var bCount = b.e.find('.user').length;
                return aCount === bCount ? 0 : (aCount < bCount ? 1 : -1);
            }
        });
    },
    updateMasonry: function(sort) {
        // Only sort when invisible since its annoying
        if (sort) {
            this.sortRooms();
        }
        this.$list.masonry('reload');
    },
    empty: function() {
        this.$list.empty();
    }
});

//
// Userlist
//
var UserListView = Backbone.View.extend({
    initialize: function() {
        var self = this;
        this.template = $('#js-tmpl-user-item').html();
        this.model.bind('add remove', function(users, users) {
            self.count(_.uniq(_.pluck(users.toJSON(), 'uid')).length);
        });
        this.model.bind('add', function(user, users) {
            var matches = users.where({
                uid: user.get('uid'),
                room: user.get('room')
            })
            if (matches.length == 1) {
                self.add(user.toJSON());
            }
        });
        this.model.bind('remove', function(user, users) {
            var matches = users.where({
                uid: user.get('uid'),
                room: user.get('room')
            })
            if (matches.length < 1) {
                self.remove(user.get('uid'));
            }
        });
        this.model.bind('change', function(user, users) {
            self.update(user.toJSON());
        });
        this.model.bind('reset', function() {
            self.empty();
        });
        //
        // User profile update
        //
        self.options.notifications.on('updateuser', function(profile) {
            var matches = self.model.where({
                uid: profile.id
            })
            _.each(matches, function(user) {
                user.set(profile);
            });
        });
    },
    count: function(count) {
        this.$el.closest('.item-list').find('.count').text(count);
    },
    add: function(user) {
        var html = Mustache.to_html(this.template, user);
        this.$el.append(html);
    },
    remove: function(id) {
        this.$('.user[data-uid=' + id + ']').remove();
    },
    update: function(user) {
        var $user = this.$('.user[data-uid=' + user.id + ']');
        $user.addClass('has-status', user.status);
        $user.find('.status').text(user.status);
    },
    empty: function() {
        this.$el.empty();
    }
});<commit_msg>Fix has-status class toggle in userlist<commit_after>//
// Roomlist
//
var RoomListView = Backbone.View.extend({
    el: '#room-list',
    initialize: function() {
        var self = this;
        this.$list = this.$('.room-list');
        this.template = $('#js-tmpl-room-list-item').html();
        this.userTemplate = $('#js-tmpl-room-list-user').html();
        this.collection = this.options.collection;
        this.collection.bind('add', function(room) {
            self.add(_.extend(room.toJSON(), {
                lastActive: moment(room.get('lastActive')).calendar()
            }));
            //
            // Room meta update
            //
            room.bind('change', function(room) {
                self.updateRoom(_.extend(room.toJSON(), {
                    lastActive: moment(room.get('lastActive')).calendar()
                }));
            });
            //
            //  User events
            //
            room.users.bind('add', function(user, users) {
                var matches = users.where({
                    uid: user.get('uid'),
                    room: user.get('room')
                })
                if (matches.length == 1) {
                    self.addUser(user.toJSON());
                }
            });
            room.users.bind('remove', function(user, users) {
                var matches = users.where({
                    uid: user.get('uid'),
                    room: user.get('room')
                })
                if (matches.length < 1) {
                    self.removeUser(user.toJSON());
                }
            });
        });
        this.collection.bind('remove', function(room) {
            self.remove(room.id);
        });
        this.collection.bind('reset', function() {
            self.empty();
        });
        self.$list.masonry({
            itemSelector: '.room'
        });
        // Masonry shims
        this.options.notifications.on('homeselected', function() {
            self.updateMasonry(true);
        });
    },
    add: function(room) {
        var item = Mustache.to_html(this.template, room);
        this.$list.prepend(item);
        this.updateMasonry();
    },
    remove: function(id) {
        this.$('.room[data-id=' + id + ']').remove();
        this.updateMasonry();
    },
    addUser: function(user) {
        var html = Mustache.to_html(this.userTemplate, user);
        this.$('.room[data-id=' + user.room + '] .users').prepend(html);
        this.updateMasonry();
    },
    removeUser: function(user) {
        this.$('.room[data-id=' + user.room + ']')
          .find('.user[data-uid=' + user.uid + ']').remove();
        this.updateMasonry();
    },
    updateRoom: function(room) {
        var $room = this.$('.room[data-id=' + room.id + ']');
        $room.find('.name').text(room.name);
        $room.find('.description').text(room.description);
        $room.find('.last-active .value').text(room.lastActive);
    },
    //
    // Sort rooms by users in dom
    //
    sortRooms: function() {
        this.$('.room').tsort('', {
            sortFunction: function(a, b){
                var aCount = a.e.find('.user').length;
                var bCount = b.e.find('.user').length;
                return aCount === bCount ? 0 : (aCount < bCount ? 1 : -1);
            }
        });
    },
    updateMasonry: function(sort) {
        // Only sort when invisible since its annoying
        if (sort) {
            this.sortRooms();
        }
        this.$list.masonry('reload');
    },
    empty: function() {
        this.$list.empty();
    }
});

//
// Userlist
//
var UserListView = Backbone.View.extend({
    initialize: function() {
        var self = this;
        this.template = $('#js-tmpl-user-item').html();
        this.model.bind('add remove', function(users, users) {
            self.count(_.uniq(_.pluck(users.toJSON(), 'uid')).length);
        });
        this.model.bind('add', function(user, users) {
            var matches = users.where({
                uid: user.get('uid'),
                room: user.get('room')
            })
            if (matches.length == 1) {
                self.add(user.toJSON());
            }
        });
        this.model.bind('remove', function(user, users) {
            var matches = users.where({
                uid: user.get('uid'),
                room: user.get('room')
            })
            if (matches.length < 1) {
                self.remove(user.get('uid'));
            }
        });
        this.model.bind('change', function(user, users) {
            self.update(user.toJSON());
        });
        this.model.bind('reset', function() {
            self.empty();
        });
        //
        // User profile update
        //
        self.options.notifications.on('updateuser', function(profile) {
            var matches = self.model.where({
                uid: profile.id
            })
            _.each(matches, function(user) {
                user.set(profile);
            });
        });
    },
    count: function(count) {
        this.$el.closest('.item-list').find('.count').text(count);
    },
    add: function(user) {
        var html = Mustache.to_html(this.template, user);
        this.$el.append(html);
    },
    remove: function(id) {
        this.$('.user[data-uid=' + id + ']').remove();
    },
    update: function(user) {
        var $user = this.$('.user[data-uid=' + user.id + ']');
        $user.toggleClass('has-status', user.status && user.status.length > 0);
        $user.find('.status').text(user.status);
    },
    empty: function() {
        this.$el.empty();
    }
});
{'fraction_non_alphanumeric': 0.175698598339434, 'fraction_numerical': 0.0013391661458798322, 'mean_word_length': 1.5235413381392204, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, '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': '4693488', 'n_tokens_mistral': 3251, 'n_tokens_neox': 3183, 'n_words': 513}