Support for dynamic default channel

This commit is contained in:
Jeremy Zhang 2017-08-09 01:26:11 +00:00
parent 335d9f569e
commit 146b2311cf
2 changed files with 17 additions and 12 deletions

View File

@ -18,7 +18,7 @@
var fetchtimeout; // fetch routine timer var fetchtimeout; // fetch routine timer
var currently_fetching; // fetch lock- if true, do not fetch var currently_fetching; // fetch lock- if true, do not fetch
var last_message_id; // last message tracked var last_message_id; // last message tracked
var selected_channel = guild_id; // user selected channel, defaults to #general channel var selected_channel = null; // user selected channel
var guild_channels = {}; // all server channels used to highlight channels in messages var guild_channels = {}; // all server channels used to highlight channels in messages
var emoji_store = {}; // all server emojis var emoji_store = {}; // all server emojis
var times_fetched = 0; // kept track of how many times that it has fetched var times_fetched = 0; // kept track of how many times that it has fetched
@ -315,7 +315,6 @@
for (var i = 0; i < guildchannels.length; i++) { for (var i = 0; i < guildchannels.length; i++) {
if (guildchannels[i].channel.id == defaultChannel) { if (guildchannels[i].channel.id == defaultChannel) {
selected_channel = defaultChannel; selected_channel = defaultChannel;
debugger;
return; return;
} }
} }
@ -335,6 +334,7 @@
var template = $('#mustache_channellistings').html(); var template = $('#mustache_channellistings').html();
Mustache.parse(template); Mustache.parse(template);
$("#channels-list").empty(); $("#channels-list").empty();
var curr_default_channel = selected_channel;
for (var i = 0; i < channels.length; i++) { for (var i = 0; i < channels.length; i++) {
var chan = channels[i]; var chan = channels[i];
guild_channels[chan.channel.id] = chan; guild_channels[chan.channel.id] = chan;
@ -344,18 +344,23 @@
$("#channel-" + chan.channel.id.toString()).click({"channel_id": chan.channel.id.toString()}, function(event) { $("#channel-" + chan.channel.id.toString()).click({"channel_id": chan.channel.id.toString()}, function(event) {
select_channel(event.data.channel_id); select_channel(event.data.channel_id);
}); });
if (chan.channel.id == selected_channel) { if (!selected_channel && (!curr_default_channel || chan.channel.position < curr_default_channel.channel.position)) {
if (chan.write) { curr_default_channel = chan;
$("#messagebox").prop('disabled', false);
$("#messagebox").prop('placeholder', "Enter message");
} else {
$("#messagebox").prop('disabled', true);
$("#messagebox").prop('placeholder', "Messages is disabled in this channel.");
}
$("#channeltopic").text(chan.channel.topic);
} }
} }
} }
if (typeof curr_default_channel == "object") {
selected_channel = curr_default_channel.channel.id;
}
var this_channel = guild_channels[selected_channel];
if (this_channel.write) {
$("#messagebox").prop('disabled', false);
$("#messagebox").prop('placeholder', "Enter message");
} else {
$("#messagebox").prop('disabled', true);
$("#messagebox").prop('placeholder', "Messages is disabled in this channel.");
}
$("#channeltopic").text(this_channel.channel.topic);
$("#channel-"+selected_channel).parent().addClass("active"); $("#channel-"+selected_channel).parent().addClass("active");
} }

View File

@ -15,7 +15,7 @@
</li> </li>
<li class="collection-item"> <li class="collection-item">
<strong>defaultchannel=&lt;snowflake&gt;</strong> <br> <strong>defaultchannel=&lt;snowflake&gt;</strong> <br>
Instead of having your #general channel as the first channel your users see, you may change it. Enable Discord's Developer mode in the Appearances tab of the User Settings and copy the channel ID. <br> Instead of having the top channel as the first channel your users see, you may change it. Enable Discord's Developer mode in the Appearances tab of the User Settings and copy the channel ID. <br>
<em>Eg: defaultchannel=1234567890</em> <em>Eg: defaultchannel=1234567890</em>
</li> </li>
<li class="collection-item"> <li class="collection-item">