Second level channels and categories are now properly filtered.
@@ -78,11 +78,30 @@ func (channelTree *ChannelTree) LoadGuild(guildID string) error {
// Top level channel
state := channelTree.state
for _, channel := range channels {
- channelTree.state.UserChannelPermissions(channelTree.state.User.ID, channel.ID)
if channel.Type != discordgo.ChannelTypeGuildText || channel.ParentID != "" || !hasReadMessagesPermission(channel, state) {
continue
}
+ createTopLevelChannelNodes(channelTree, channel)
+ }
+ // Categories
+ for _, channel := range channels {
+ if channel.Type != discordgo.ChannelTypeGuildCategory || channel.ParentID != "" || !hasReadMessagesPermission(channel, state) {
+ continue
+ }
+ createChannelCategoryNodes(channelTree, channel)
+ }
+ // Second level channel
+ for _, channel := range channels {
+ if channel.Type != discordgo.ChannelTypeGuildText || channel.ParentID == "" || !hasReadMessagesPermission(channel, state) {
+ continue
+ }
+ createSecondLevelChannelNodes(channelTree, channel)
+ }
+ channelTree.internalTreeView.SetCurrentNode(channelTree.internalTreeView.GetRoot())
+ return nil
+}
+func createTopLevelChannelNodes(channelTree *ChannelTree, channel *discordgo.Channel) {
channelNode := createChannelNode(channel)
if !readstate.HasBeenRead(channel.ID, channel.LastMessageID) {
channelTree.channelStates[channelNode] = channelUnread
@@ -91,23 +110,13 @@ func (channelTree *ChannelTree) LoadGuild(guildID string) error {
channelTree.internalTreeView.GetRoot().AddChild(channelNode)
}
- //Category
- for _, channel := range channels {
- if channel.Type != discordgo.ChannelTypeGuildCategory || channel.ParentID != "" {
- continue
- }
-
+func createChannelCategoryNodes(channelTree *ChannelTree, channel *discordgo.Channel) {
channelNode := createChannelNode(channel)
channelNode.SetSelectable(false)
channelTree.internalTreeView.GetRoot().AddChild(channelNode)
}
- //Second level channel
- for _, channel := range channels {
- if channel.Type != discordgo.ChannelTypeGuildText || channel.ParentID == "" {
- continue
- }
-
+func createSecondLevelChannelNodes(channelTree *ChannelTree, channel *discordgo.Channel) {
channelNode := createChannelNode(channel)
for _, node := range channelTree.internalTreeView.GetRoot().GetChildren() {
channelID, ok := node.GetReference().(string)
@@ -123,11 +132,6 @@ func (channelTree *ChannelTree) LoadGuild(guildID string) error {
}
}
- channelTree.internalTreeView.SetCurrentNode(channelTree.internalTreeView.GetRoot())
-
- return nil
-}
-
// Checks if the user has permission to view a specific channel.
func hasReadMessagesPermission(channel *discordgo.Channel, state *discordgo.State) bool {
userPermissions, err := state.UserChannelPermissions(state.User.ID, channel.ID)
