2025-02-19 00:34:02
define('home/collections/UserManagedChannelCollection',[
    'underscore',
 
    'core/api',
 
    'home/collections/ChannelCollection',
], function (
    _,
 
    api,
 
    ChannelCollection
) {
    'use strict';
 
    /**
     * A collection of Channel models that are managed by the given user
     * ie: created or moderated by the given user.
     */
    var UserManagedChannelCollection = ChannelCollection.extend({
        // listModeratedChannels includes channels that are owned
        url: api.getURL('users/listModeratedChannels'),
 
        initialize: function (_models, options) {
            this.user = options.user;
            this.listenTo(this.user, 'change:id', this.sort);
        },
 
        /**
         * Sorts the collection so that channels created by the given user
         * appear above channels that are moderated by the given user.
         * Within each section, channels are sorted alphabetically by name,
         * case-insensitive.
         */
        comparator: function (channel1, channel2) {
            var userId = this.user.get('id');
            var sessionUserOwnsChannel1 = channel1.get('owner_id') === userId;
            var sessionUserOwnsChannel2 = channel2.get('owner_id') === userId;
 
            // If both channels are (not) owned, compare their names. Don't need
            // to handle name equality, as channel names are unique.
            if (sessionUserOwnsChannel1 === sessionUserOwnsChannel2) {
                return channel1.get('name').toLowerCase() < channel2.get('name').toLowerCase() ?
                    -1 : 1;
            }
 
            // If channel1 is owned and channel2 is not, channel1 should appear
            // above channel2.
            if (sessionUserOwnsChannel1)
                return -1;
 
            // If channel2 is owned and channel1 is not, channel2 should appear
            // above channel1.
            return 1;
        },
 
        fetch: function (options) {
            return ChannelCollection.prototype.fetch.call(this, _.defaults({
                data: {
                    user: 'username:' + this.user.get('username'),
                    // TODO: remove this once D18919 deploys to make excludeOwned false by default
                    excludeOwned: 0,
                },
            }, options));
        },
    });
 
    return UserManagedChannelCollection;
});
 
// https://c.disquscdn.com/next/current/home/js/collections/UserManagedChannelCollection.js
Invalid Email or Password