mirror of https://github.com/calzoneman/sync.git
Refactor channel packing
This commit is contained in:
parent
02ac983fba
commit
f3eb999a76
|
@ -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;
|
||||
|
|
|
@ -379,8 +379,10 @@ function showChannelDetailModal(c) {
|
|||
$("<td/>").text(c.pagetitle).appendTo(tr);
|
||||
|
||||
tr = $("<tr/>").appendTo(table);
|
||||
$("<td/>").text("Media Title").appendTo(tr);
|
||||
$("<td/>").text(c.mediatitle).appendTo(tr);
|
||||
$("<td/>").text("Current Media").appendTo(tr);
|
||||
$("<a/>").attr("href", c.mediaLink).text(c.mediatitle).appendTo(
|
||||
$("<td/>").appendTo(tr)
|
||||
);
|
||||
|
||||
tr = $("<tr/>").appendTo(table);
|
||||
$("<td/>").text("User Count").appendTo(tr);
|
||||
|
@ -402,6 +404,14 @@ function showChannelDetailModal(c) {
|
|||
$("<td/>").text("ActiveLock Count").appendTo(tr);
|
||||
$("<td/>").text(c.activeLockCount).appendTo(tr);
|
||||
|
||||
tr = $("<tr/>").appendTo(table);
|
||||
$("<td/>").text("Chat Filter Count").appendTo(tr);
|
||||
$("<td/>").text(c.chatFilterCount).appendTo(tr);
|
||||
|
||||
tr = $("<tr/>").appendTo(table);
|
||||
$("<td/>").text("Emote Count").appendTo(tr);
|
||||
$("<td/>").text(c.emoteCount).appendTo(tr);
|
||||
|
||||
$("<h3/>").text("Recent Chat").appendTo(body);
|
||||
$("<pre/>").text(c.chat.map(function (data) {
|
||||
var msg = "<" + data.username;
|
||||
|
@ -422,6 +432,7 @@ function showChannelDetailModal(c) {
|
|||
}
|
||||
|
||||
socket.on("acp-list-activechannels", function (channels) {
|
||||
console.log(channels[0]);
|
||||
var tbl = $("#acp-loaded-channels table");
|
||||
tbl.find("tbody").remove();
|
||||
|
||||
|
@ -449,12 +460,16 @@ socket.on("acp-list-activechannels", function (channels) {
|
|||
var public = $("<td/>").text(c.public).appendTo(tr);
|
||||
var controlOuter = $("<td/>").appendTo(tr);
|
||||
var controlInner = $("<div/>").addClass("btn-group").appendTo(controlOuter);
|
||||
$("<button/>").addClass("btn btn-default btn-xs").text("Details")
|
||||
$("<button/>").addClass("btn btn-default btn-xs")
|
||||
.html("<span class='glyphicon glyphicon-list-alt'></span>")//.text("Details")
|
||||
.attr("title", "Details")
|
||||
.appendTo(controlInner)
|
||||
.click(function () {
|
||||
showChannelDetailModal(c);
|
||||
});
|
||||
$("<button/>").addClass("btn btn-danger btn-xs").text("Force Unload")
|
||||
$("<button/>").addClass("btn btn-danger btn-xs")
|
||||
.html("<span class='glyphicon glyphicon-remove'></span>")//.text("Force Unload")
|
||||
.attr("title", "Unload")
|
||||
.appendTo(controlInner)
|
||||
.click(function () {
|
||||
if (confirm("Are you sure you want to unload /r/" + c.name + "?")) {
|
||||
|
|
Loading…
Reference in New Issue