Refactor channel packing
This commit is contained in:
parent
02ac983fba
commit
f3eb999a76
9 changed files with 112 additions and 46 deletions
|
|
@ -613,4 +613,42 @@ Channel.prototype.broadcastAll = function (msg, data) {
|
|||
this._broadcast(msg, data, this.name);
|
||||
};
|
||||
|
||||
Channel.prototype.packInfo = function (isAdmin) {
|
||||
var data = {
|
||||
name: this.name,
|
||||
usercount: this.users.length,
|
||||
users: [],
|
||||
registered: this.is(Flags.C_REGISTERED)
|
||||
};
|
||||
|
||||
for (var i = 0; i < this.users.length; i++) {
|
||||
if (this.users[i].name !== "") {
|
||||
var name = this.users[i].getName();
|
||||
var rank = this.users[i].account.effectiveRank;
|
||||
if (rank >= 255) {
|
||||
name = "!" + name;
|
||||
} else if (rank >= 4) {
|
||||
name = "~" + name;
|
||||
} else if (rank >= 3) {
|
||||
name = "&" + name;
|
||||
} else if (rank >= 2) {
|
||||
name = "@" + name;
|
||||
}
|
||||
data.users.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (isAdmin) {
|
||||
data.activeLockCount = this.activeLock.count;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var keys = Object.keys(this.modules);
|
||||
keys.forEach(function (k) {
|
||||
self.modules[k].packInfo(data, isAdmin);
|
||||
});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
module.exports = Channel;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,10 @@ ChatModule.prototype.save = function (data) {
|
|||
data.chatmuted = Array.prototype.slice.call(this.muted);
|
||||
};
|
||||
|
||||
ChatModule.prototype.packInfo = function (data, isAdmin) {
|
||||
data.chat = Array.prototype.slice.call(this.buffer);
|
||||
};
|
||||
|
||||
ChatModule.prototype.onUserPostJoin = function (user) {
|
||||
var self = this;
|
||||
user.waitFlag(Flags.U_LOGGED_IN, function () {
|
||||
|
|
|
|||
|
|
@ -107,6 +107,12 @@ EmoteModule.prototype.save = function (data) {
|
|||
data.emotes = this.emotes.pack();
|
||||
};
|
||||
|
||||
EmoteModule.prototype.packInfo = function (data, isAdmin) {
|
||||
if (isAdmin) {
|
||||
data.emoteCount = this.emotes.emotes.length;
|
||||
}
|
||||
};
|
||||
|
||||
EmoteModule.prototype.onUserPostJoin = function (user) {
|
||||
user.socket.on("updateEmote", this.handleUpdateEmote.bind(this, user));
|
||||
user.socket.on("importEmotes", this.handleImportEmotes.bind(this, user));
|
||||
|
|
|
|||
|
|
@ -171,6 +171,12 @@ ChatFilterModule.prototype.save = function (data) {
|
|||
data.filters = this.filters.pack();
|
||||
};
|
||||
|
||||
ChatFilterModule.prototype.packInfo = function (data, isAdmin) {
|
||||
if (isAdmin) {
|
||||
data.chatFilterCount = this.filters.filters.length;
|
||||
}
|
||||
};
|
||||
|
||||
ChatFilterModule.prototype.onUserPostJoin = function (user) {
|
||||
user.socket.on("updateFilter", this.handleUpdateFilter.bind(this, user));
|
||||
user.socket.on("importFilters", this.handleImportFilters.bind(this, user));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ ChannelModule.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called to pack info, e.g. for channel detail view
|
||||
*/
|
||||
packInfo: function (data, isAdmin) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when a user is attempting to join a channel.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ OptionsModule.prototype.save = function (data) {
|
|||
data.opts = this.opts;
|
||||
};
|
||||
|
||||
OptionsModule.prototype.packInfo = function (data, isAdmin) {
|
||||
data.pagetitle = this.opts.pagetitle;
|
||||
data.public = this.opts.show_public;
|
||||
if (isAdmin) {
|
||||
data.hasPassword = this.opts.password !== false;
|
||||
}
|
||||
};
|
||||
|
||||
OptionsModule.prototype.get = function (key) {
|
||||
return this.opts[key];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -171,6 +171,28 @@ PlaylistModule.prototype.unload = function () {
|
|||
this.channel = null;
|
||||
};
|
||||
|
||||
PlaylistModule.prototype.packInfo = function (data, isAdmin) {
|
||||
if (this.current) {
|
||||
data.mediatitle = this.current.media.title;
|
||||
if (isAdmin) {
|
||||
data.mediaLink = util.formatLink(this.current.media.id, this.current.media.type);
|
||||
}
|
||||
} else {
|
||||
data.mediatitle = "(Nothing Playing)";
|
||||
if (isAdmin) {
|
||||
data.mediaLink = "#";
|
||||
}
|
||||
}
|
||||
|
||||
if (isAdmin) {
|
||||
if (this.leader) {
|
||||
data.leader = this.leader.getName();
|
||||
} else {
|
||||
data.leader = "[server]";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PlaylistModule.prototype.onUserPostJoin = function (user) {
|
||||
this.sendPlaylist([user]);
|
||||
this.sendChangeMedia([user]);
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ Server.prototype.unloadChannel = function (chan) {
|
|||
chan.dead = true;
|
||||
};
|
||||
|
||||
Server.prototype.packChannelList = function (publicOnly, showMeta) {
|
||||
Server.prototype.packChannelList = function (publicOnly, isAdmin) {
|
||||
var channels = this.channels.filter(function (c) {
|
||||
if (!publicOnly) {
|
||||
return true;
|
||||
|
|
@ -205,50 +205,10 @@ Server.prototype.packChannelList = function (publicOnly, showMeta) {
|
|||
|
||||
var self = this;
|
||||
return channels.map(function (c) {
|
||||
return self.packChannel(c, showMeta);
|
||||
return c.packInfo(isAdmin);
|
||||
});
|
||||
};
|
||||
|
||||
Server.prototype.packChannel = function (c, showMeta) {
|
||||
var opts = c.modules.options;
|
||||
var pl = c.modules.playlist;
|
||||
var chat = c.modules.chat;
|
||||
var data = {
|
||||
name: c.name,
|
||||
pagetitle: opts.pagetitle ? opts.pagetitle : c.name,
|
||||
mediatitle: pl && pl.current ? pl.current.media.title : "-",
|
||||
usercount: c.users.length,
|
||||
users: [],
|
||||
chat: chat ? Array.prototype.slice.call(chat.buffer) : [],
|
||||
registered: c.is(Flags.C_REGISTERED),
|
||||
public: opts && opts.get("show_public")
|
||||
};
|
||||
|
||||
for (var i = 0; i < c.users.length; i++) {
|
||||
if (c.users[i].name !== "") {
|
||||
var name = c.users[i].getName();
|
||||
var rank = c.users[i].account.effectiveRank;
|
||||
if (rank >= 255) {
|
||||
name = "!" + name;
|
||||
} else if (rank >= 4) {
|
||||
name = "~" + name;
|
||||
} else if (rank >= 3) {
|
||||
name = "&" + name;
|
||||
} else if (rank >= 2) {
|
||||
name = "@" + name;
|
||||
}
|
||||
data.users.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add in some extra data- intended to be site admin only */
|
||||
if (showMeta) {
|
||||
data.activeLockCount = c.activeLock.count;
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
Server.prototype.announce = function (data) {
|
||||
if (data == null) {
|
||||
this.announcement = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue