Add skeleton for channel tree
ADD
internal/ui/channeltree.go
+package ui
+
+import (
+ "github.com/Bios-Marcel/discordgo"
+ "github.com/Bios-Marcel/tview"
+)
+
+type channelState int
+
+const (
+ channelLoaded channelState = iota
+ channelUnread
+ channelMentioned
+ channelRead
+)
+
+// ChannelTree is the component that displays the channel hierarchy of the
+// currently loaded guild and allows interactions with those channels.
+type ChannelTree struct {
+ internalTreeView *tview.TreeView
+
+ onLoad func(channelID string)
+ channelStates map[*tview.TreeNode]channelState
+}
+
+// NewChannelTree creates a new ready-to-be-used ChannelTree
+func NewChannelTree() *ChannelTree {
+ channelTree := &ChannelTree{
+ internalTreeView: tview.NewTreeView(),
+ channelStates: make(map[*tview.TreeNode]channelState),
+ }
+
+ return channelTree
+}
+
+// LoadGuild accesses the state in order to load all locally present channels
+// for the passed guild.
+func (channelTree *ChannelTree) LoadGuild(guildID string) {
+
+}
+
+// AddOrUpdateChannel either adds a new node for the given channel or updates
+// its current node.
+func (channelTree *ChannelTree) AddOrUpdateChannel(channel *discordgo.Channel) {
+
+}
+
+// RemoveChannel removes a channels node from the tree.
+func (channelTree *ChannelTree) RemoveChannel(channelID string) {
+
+}
+
+// MarkChannelAsUnread marks a channel as unread.
+func (channelTree *ChannelTree) MarkChannelAsUnread(channelID string) {
+
+}
+
+// MarkChannelAsMentioned marks a channel as mentioned.
+func (channelTree *ChannelTree) MarkChannelAsMentioned(channelID string) {
+
+}
+
+// MarkChannelAsLoaded marks a channel as loaded and therefore marks all other
+// channels as either unread, read or mentioned.
+func (channelTree *ChannelTree) MarkChannelAsLoaded(channelID string) {
+
+}
+
+// SetOnLoad sets the handler that reacts to channel selection events.
+func (channelTree *ChannelTree) SetOnLoad(handler func(channelID string)) {
+ channelTree.onLoad = handler
+}

MODIFY
internal/ui/privatechats.go
internal/ui/privatechats.go
@@ -9,10 +9,10 @@ import (
"github.com/Bios-Marcel/tview"
)
-type nodeState int
+type privateChannelState int
const (
- loaded nodeState = iota
+ loaded privateChannelState = iota
unread
read
)
@@ -29,7 +29,7 @@ type PrivateChatList struct {
onChannelSelect func(node *tview.TreeNode, channelID string)
onFriendSelect func(userID string)
- nodeStates map[*tview.TreeNode]nodeState
+ privateChannelStates map[*tview.TreeNode]privateChannelState
userChannels map[string]*tview.TreeNode
friends map[string]*tview.TreeNode
@@ -44,7 +44,7 @@ func NewPrivateChatList(state *discordgo.State) *PrivateChatList {
chatsNode: tview.NewTreeNode("Chats"),
friendsNode: tview.NewTreeNode("Friends"),
- nodeStates: make(map[*tview.TreeNode]nodeState, 0),
+ privateChannelStates: make(map[*tview.TreeNode]privateChannelState, 0),
}
privateList.internalTreeView.
@@ -179,7 +179,7 @@ func (privateList *PrivateChatList) RemoveChannel(channel *discordgo.Channel) {
if !ok || ok && channelID != referenceChannelID {
newChildren = append(newChildren, node)
} else {
- delete(privateList.nodeStates, node)
+ delete(privateList.privateChannelStates, node)
}
}
@@ -201,7 +201,7 @@ func (privateList *PrivateChatList) MarkChannelAsUnread(channel *discordgo.Chann
for _, node := range privateList.chatsNode.GetChildren() {
referenceChannelID, ok := node.GetReference().(string)
if ok && referenceChannelID == channel.ID {
- privateList.nodeStates[node] = unread
+ privateList.privateChannelStates[node] = unread
node.SetColor(tcell.ColorRed)
break
}
@@ -213,7 +213,7 @@ func (privateList *PrivateChatList) MarkChannelAsRead(channel *discordgo.Channel
for _, node := range privateList.chatsNode.GetChildren() {
referenceChannelID, ok := node.GetReference().(string)
if ok && referenceChannelID == channel.ID {
- privateList.nodeStates[node] = read
+ privateList.privateChannelStates[node] = read
node.SetColor(tcell.ColorWhite)
break
}
@@ -223,9 +223,9 @@ func (privateList *PrivateChatList) MarkChannelAsRead(channel *discordgo.Channel
// MarkChannelAsLoaded marks a channel as loaded, coloring it blue (teal). If
// a different channel had loaded before, it's set to read.
func (privateList *PrivateChatList) MarkChannelAsLoaded(channel *discordgo.Channel) {
- for node, state := range privateList.nodeStates {
+ for node, state := range privateList.privateChannelStates {
if state == loaded {
- privateList.nodeStates[node] = read
+ privateList.privateChannelStates[node] = read
node.SetColor(tcell.ColorWhite)
break
}
@@ -234,7 +234,7 @@ func (privateList *PrivateChatList) MarkChannelAsLoaded(channel *discordgo.Chann
for _, node := range privateList.chatsNode.GetChildren() {
referenceChannelID, ok := node.GetReference().(string)
if ok && referenceChannelID == channel.ID {
- privateList.nodeStates[node] = loaded
+ privateList.privateChannelStates[node] = loaded
node.SetColor(tcell.ColorTeal)
break
}

Add skeleton for channel tree