Initial support for channel categories

This commit is contained in:
Jeremy Zhang 2017-09-09 21:46:00 +00:00
parent 1dad3f1d3a
commit 25cd964403
7 changed files with 86 additions and 17 deletions

View File

@ -149,7 +149,7 @@ class SocketIOInterface:
await self.io.emit('CHANNEL_CREATE', data=chan, room=str("GUILD_"+channel.server.id), namespace='/gateway')
async def on_channel_update(self, channel):
if str(channel.type) != "text":
if str(channel.type) not in ["text", "category"]:
return
chan = self.get_formatted_channel(channel)
await self.io.emit('CHANNEL_UPDATE', data=chan, room=str("GUILD_"+channel.server.id), namespace='/gateway')

View File

@ -64,7 +64,7 @@ def get_roles_list(guildroles):
def get_channels_list(guildchannels):
channels = []
for channel in guildchannels:
if str(channel.type) == "text":
if str(channel.type) in ["text", "category"]:
overwrites = []
for target, overwrite in channel.overwrites:
if isinstance(target, discord.Role):
@ -80,14 +80,17 @@ def get_channels_list(guildchannels):
"allow": allow,
"deny": deny,
})
parent = channel.parent
if parent:
parent = parent.id
channels.append({
"id": channel.id,
"name": channel.name,
"topic": channel.topic,
"position": channel.position,
"type": str(channel.type),
"permission_overwrites": overwrites
"permission_overwrites": overwrites,
"parent_id": parent,
})
return channels

View File

@ -179,7 +179,7 @@ def fetch():
chan = filter_guild_channel(guild_id, channel_id)
if not chan:
abort(404)
if not chan.get("read"):
if not chan.get("read") or chan["channel"]["type"] != "text":
status_code = 401
else:
messages = get_channel_messages(guild_id, channel_id, after_snowflake)
@ -200,7 +200,7 @@ def fetch_visitor():
chan = filter_guild_channel(guild_id, channel_id, True)
if not chan:
abort(404)
if not chan.get("read"):
if not chan.get("read") or chan["channel"]["type"] != "text":
status_code = 401
else:
messages = get_channel_messages(guild_id, channel_id, after_snowflake)
@ -233,7 +233,7 @@ def post():
status_code = 401
else:
chan = filter_guild_channel(guild_id, channel_id)
if not chan.get("write"):
if not chan.get("write") or chan["channel"]["type"] != "text":
status_code = 401
elif not illegal_post:
userid = session["user_id"]

View File

@ -82,6 +82,10 @@ nav .brand-logo {
color: #eceff1;
}
.side-nav li>a[id^=channel] {
margin-left: 7px;
}
.side-nav .subheader {
color: #cfd8dc;
font-variant: small-caps;
@ -213,6 +217,10 @@ nav .brand-logo {
-webkit-filter: brightness(150%);
}
.subheader .channel-category {
text-transform: uppercase;
}
.chatusername {
font-weight: bold;
color: #eceff1;

View File

@ -371,20 +371,74 @@
guild_channels_list = channels;
var template = $('#mustache_channellistings').html();
Mustache.parse(template);
var template_category = $('#mustache_channelcategory').html();
Mustache.parse(template_category);
$("#channels-list").empty();
var curr_default_channel = selected_channel;
var categories = [{
"channel": {id: null, name: "Uncategorized"},
"children": [],
"read": true,
}];
for (var i = 0; i < channels.length; i++) {
var chan = channels[i];
guild_channels[chan.channel.id] = chan;
if (chan.read) {
var rendered = Mustache.render(template, {"channelid": chan.channel.id, "channelname": chan.channel.name});
$("#channels-list").append(rendered);
$("#channel-" + chan.channel.id.toString()).click({"channel_id": chan.channel.id.toString()}, function(event) {
select_channel(event.data.channel_id);
});
if (!selected_channel && (!curr_default_channel || chan.channel.position < curr_default_channel.channel.position)) {
curr_default_channel = chan;
}
if (chan.channel.type == "category") {
chan.children = [];
categories.push(chan);
}
}
categories.sort(function(a, b) {
return parseInt(a.channel.position) - parseInt(b.channel.position);
});
for (var i = 0; i < channels.length; i++) {
var chan = channels[i];
if (chan.channel.type == "text") {
var cate = chan.channel.parent_id;
for (var j = 0; j < categories.length; j++) {
var thiscategory = categories[j];
if (thiscategory.channel.id == cate) {
thiscategory.children.push(chan);
break;
}
}
}
}
for (var i = 0; i < categories.length; i++) {
var cate = categories[i];
cate.read = false;
for (var j = 0; j < cate.children.length; j++) {
var chan = cate.children[j];
if (chan.channel.type == "text" && chan.read) {
cate.read = true;
break;
}
}
}
for (var i = 0; i < categories.length; i++) {
var cate = categories[i];
var children = cate.children;
children.sort(function(a, b) {
return parseInt(a.channel.position) - parseInt(b.channel.position);
});
if (i != 0) {
if (cate.read) {
var rendered_category = Mustache.render(template_category, {"name": cate.channel.name});
$("#channels-list").append(rendered_category);
}
}
for (var j = 0; j < children.length; j++) {
var chan = children[j];
if (chan.read) {
var rendered_channel = Mustache.render(template, {"channelid": chan.channel.id, "channelname": chan.channel.name});
$("#channels-list").append(rendered_channel);
$("#channel-" + chan.channel.id.toString()).click({"channel_id": chan.channel.id.toString()}, function(event) {
select_channel(event.data.channel_id);
});
if (!selected_channel && (!curr_default_channel || chan.channel.position < curr_default_channel.channel.position)) {
curr_default_channel = chan;
}
}
}
}
if (typeof curr_default_channel == "object") {

View File

@ -211,6 +211,10 @@
<script id="mustache_memberrole" type="text/template">
<li><a class="subheader role-title">{{name}}</a></li>
</script>
<script id="mustache_channelcategory" type="text/template">
<li><a class="subheader channel-category">{{name}}</a></li>
</script>
<script id="mustache_message_emoji" type="text/template">
<img class="message_emoji tooltipped" src='https://cdn.discordapp.com/emojis/{{id}}.png' data-position="top" data-delay="200" data-tooltip=":{{name}}:" alt=":{{name}}:" />

View File

@ -117,7 +117,7 @@ def get_guild_channels(guild_id, force_everyone=False):
guild_owner = str(dbguild.owner_id)
result_channels = []
for channel in guild_channels:
if channel['type'] == "text":
if channel['type'] in ["text", "category"]:
result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_roles, session.get("user_id"), force_everyone)
bot_result = get_channel_permission(channel, guild_id, guild_owner, guild_roles, bot_member_roles, config["client-id"], False)
if not bot_result["read"]: