Start with different threads setup
This commit is contained in:
parent
cfcf6469d6
commit
74e9ac15b3
@ -108,13 +108,13 @@ type Channels struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateChannels is the constructor for the Channels component
|
// CreateChannels is the constructor for the Channels component
|
||||||
func CreateChannelsComponent(inputHeight int) *Channels {
|
func CreateChannelsComponent(height int) *Channels {
|
||||||
channels := &Channels{
|
channels := &Channels{
|
||||||
List: termui.NewList(),
|
List: termui.NewList(),
|
||||||
}
|
}
|
||||||
|
|
||||||
channels.List.BorderLabel = "Channels"
|
channels.List.BorderLabel = "Channels"
|
||||||
channels.List.Height = termui.TermHeight() - inputHeight
|
channels.List.Height = height
|
||||||
|
|
||||||
channels.SelectedChannel = 0
|
channels.SelectedChannel = 0
|
||||||
channels.Offset = 0
|
channels.Offset = 0
|
||||||
@ -148,11 +148,10 @@ func (c *Channels) Buffer() termui.Buffer {
|
|||||||
// Append ellipsis when overflows
|
// Append ellipsis when overflows
|
||||||
cells = termui.DTrimTxCls(cells, c.List.InnerWidth())
|
cells = termui.DTrimTxCls(cells, c.List.InnerWidth())
|
||||||
|
|
||||||
x := 0
|
x := c.List.InnerBounds().Min.X
|
||||||
for _, cell := range cells {
|
for _, cell := range cells {
|
||||||
width := cell.Width()
|
buf.Set(x, y, cell)
|
||||||
buf.Set(c.List.InnerBounds().Min.X+x, y, cell)
|
x += cell.Width()
|
||||||
x += width
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When not at the end of the pane fill it up empty characters
|
// When not at the end of the pane fill it up empty characters
|
||||||
|
26
components/threads.go
Normal file
26
components/threads.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package components
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/erroneousboat/termui"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Threads struct {
|
||||||
|
*Channels
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateThreadsComponent(height int) *Threads {
|
||||||
|
threads := &Threads{
|
||||||
|
Channels: &Channels{
|
||||||
|
List: termui.NewList(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
threads.List.BorderLabel = "Threads"
|
||||||
|
threads.List.Height = height
|
||||||
|
|
||||||
|
threads.SelectedChannel = 0
|
||||||
|
threads.Offset = 0
|
||||||
|
threads.CursorPosition = threads.List.InnerBounds().Min.Y
|
||||||
|
|
||||||
|
return threads
|
||||||
|
}
|
@ -87,11 +87,13 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version
|
|||||||
|
|
||||||
// Setup the interface
|
// Setup the interface
|
||||||
if flgDebug {
|
if flgDebug {
|
||||||
|
// FIXME: threads width configurable
|
||||||
termui.Body.AddRows(
|
termui.Body.AddRows(
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
||||||
termui.NewCol(config.MainWidth-5, 0, view.Chat),
|
termui.NewCol(config.MainWidth-5, 0, view.Chat),
|
||||||
termui.NewCol(config.MainWidth-6, 0, view.Debug),
|
termui.NewCol(config.MainWidth-10, 0, view.Threads),
|
||||||
|
termui.NewCol(config.MainWidth-7, 0, view.Debug),
|
||||||
),
|
),
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
||||||
@ -99,10 +101,12 @@ func CreateAppContext(flgConfig string, flgToken string, flgDebug bool, version
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
// FIXME: threads width configurable
|
||||||
termui.Body.AddRows(
|
termui.Body.AddRows(
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
termui.NewCol(config.SidebarWidth, 0, view.Channels),
|
||||||
termui.NewCol(config.MainWidth, 0, view.Chat),
|
termui.NewCol(config.MainWidth-1, 0, view.Chat),
|
||||||
|
termui.NewCol(config.MainWidth-10, 0, view.Threads),
|
||||||
),
|
),
|
||||||
termui.NewRow(
|
termui.NewRow(
|
||||||
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
termui.NewCol(config.SidebarWidth, 0, view.Mode),
|
||||||
|
@ -332,7 +332,7 @@ func actionSearchMode(ctx *context.AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func actionGetMessages(ctx *context.AppContext) {
|
func actionGetMessages(ctx *context.AppContext) {
|
||||||
msgs, err := ctx.Service.GetMessages(
|
msgs, _, err := ctx.Service.GetMessages(
|
||||||
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
||||||
ctx.View.Chat.GetMaxItems(),
|
ctx.View.Chat.GetMaxItems(),
|
||||||
)
|
)
|
||||||
@ -418,7 +418,7 @@ func actionChangeChannel(ctx *context.AppContext) {
|
|||||||
|
|
||||||
// Get messages of the SelectedChannel, and get the count of messages
|
// Get messages of the SelectedChannel, and get the count of messages
|
||||||
// that fit into the Chat component
|
// that fit into the Chat component
|
||||||
msgs, err := ctx.Service.GetMessages(
|
msgs, threads, err := ctx.Service.GetMessages(
|
||||||
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].ID,
|
||||||
ctx.View.Chat.GetMaxItems(),
|
ctx.View.Chat.GetMaxItems(),
|
||||||
)
|
)
|
||||||
@ -436,6 +436,9 @@ func actionChangeChannel(ctx *context.AppContext) {
|
|||||||
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].GetChannelName(),
|
ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel].GetChannelName(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set threads
|
||||||
|
ctx.View.Threads.SetChannels(threads)
|
||||||
|
|
||||||
// Clear notification icon if there is any
|
// Clear notification icon if there is any
|
||||||
channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel]
|
channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel]
|
||||||
if channelItem.Notification {
|
if channelItem.Notification {
|
||||||
@ -444,6 +447,7 @@ func actionChangeChannel(ctx *context.AppContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
termui.Render(ctx.View.Channels)
|
termui.Render(ctx.View.Channels)
|
||||||
|
termui.Render(ctx.View.Threads)
|
||||||
termui.Render(ctx.View.Chat)
|
termui.Render(ctx.View.Chat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ func (s *SlackService) SendCommand(channelID string, message string) (bool, erro
|
|||||||
|
|
||||||
// GetMessages will get messages for a channel, group or im channel delimited
|
// GetMessages will get messages for a channel, group or im channel delimited
|
||||||
// by a count.
|
// by a count.
|
||||||
func (s *SlackService) GetMessages(channelID string, count int) ([]components.Message, error) {
|
func (s *SlackService) GetMessages(channelID string, count int) ([]components.Message, []components.ChannelItem, error) {
|
||||||
|
|
||||||
// https://godoc.org/github.com/nlopes/slack#GetConversationHistoryParameters
|
// https://godoc.org/github.com/nlopes/slack#GetConversationHistoryParameters
|
||||||
historyParams := slack.GetConversationHistoryParameters{
|
historyParams := slack.GetConversationHistoryParameters{
|
||||||
@ -418,14 +418,28 @@ func (s *SlackService) GetMessages(channelID string, count int) ([]components.Me
|
|||||||
|
|
||||||
history, err := s.Client.GetConversationHistory(&historyParams)
|
history, err := s.Client.GetConversationHistory(&historyParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the messages
|
// Construct the messages
|
||||||
var messages []components.Message
|
var messages []components.Message
|
||||||
|
var threads []components.ChannelItem
|
||||||
for _, message := range history.Messages {
|
for _, message := range history.Messages {
|
||||||
msg := s.CreateMessage(message, channelID)
|
msg := s.CreateMessage(message, channelID)
|
||||||
messages = append(messages, msg)
|
messages = append(messages, msg)
|
||||||
|
|
||||||
|
// FIXME: create boolean isThread
|
||||||
|
if msg.Thread != "" {
|
||||||
|
|
||||||
|
threads = append(threads, components.ChannelItem{
|
||||||
|
ID: msg.ID,
|
||||||
|
Name: msg.Thread,
|
||||||
|
Type: components.ChannelTypeGroup,
|
||||||
|
StylePrefix: s.Config.Theme.Channel.Prefix,
|
||||||
|
StyleIcon: s.Config.Theme.Channel.Icon,
|
||||||
|
StyleText: s.Config.Theme.Channel.Text,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse the order of the messages, we want the newest in
|
// Reverse the order of the messages, we want the newest in
|
||||||
@ -435,7 +449,7 @@ func (s *SlackService) GetMessages(channelID string, count int) ([]components.Me
|
|||||||
messagesReversed = append(messagesReversed, messages[i])
|
messagesReversed = append(messagesReversed, messages[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
return messagesReversed, nil
|
return messagesReversed, threads, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateMessage will create a string formatted message that can be rendered
|
// CreateMessage will create a string formatted message that can be rendered
|
||||||
|
@ -13,6 +13,7 @@ type View struct {
|
|||||||
Input *components.Input
|
Input *components.Input
|
||||||
Chat *components.Chat
|
Chat *components.Chat
|
||||||
Channels *components.Channels
|
Channels *components.Channels
|
||||||
|
Threads *components.Threads
|
||||||
Mode *components.Mode
|
Mode *components.Mode
|
||||||
Debug *components.Debug
|
Debug *components.Debug
|
||||||
}
|
}
|
||||||
@ -22,7 +23,8 @@ func CreateView(config *config.Config, svc *service.SlackService) (*View, error)
|
|||||||
input := components.CreateInputComponent()
|
input := components.CreateInputComponent()
|
||||||
|
|
||||||
// Channels: create the component
|
// Channels: create the component
|
||||||
channels := components.CreateChannelsComponent(input.Par.Height)
|
sideBarHeight := termui.TermHeight() - input.Par.Height
|
||||||
|
channels := components.CreateChannelsComponent(sideBarHeight)
|
||||||
|
|
||||||
// Channels: fill the component
|
// Channels: fill the component
|
||||||
slackChans, err := svc.GetChannels()
|
slackChans, err := svc.GetChannels()
|
||||||
@ -33,11 +35,14 @@ func CreateView(config *config.Config, svc *service.SlackService) (*View, error)
|
|||||||
// Channels: set channels in component
|
// Channels: set channels in component
|
||||||
channels.SetChannels(slackChans)
|
channels.SetChannels(slackChans)
|
||||||
|
|
||||||
|
// Threads: create component
|
||||||
|
threads := components.CreateThreadsComponent(sideBarHeight)
|
||||||
|
|
||||||
// Chat: create the component
|
// Chat: create the component
|
||||||
chat := components.CreateChatComponent(input.Par.Height)
|
chat := components.CreateChatComponent(input.Par.Height)
|
||||||
|
|
||||||
// Chat: fill the component
|
// Chat: fill the component
|
||||||
msgs, err := svc.GetMessages(
|
msgs, thds, err := svc.GetMessages(
|
||||||
channels.ChannelItems[channels.SelectedChannel].ID,
|
channels.ChannelItems[channels.SelectedChannel].ID,
|
||||||
chat.GetMaxItems(),
|
chat.GetMaxItems(),
|
||||||
)
|
)
|
||||||
@ -52,6 +57,9 @@ func CreateView(config *config.Config, svc *service.SlackService) (*View, error)
|
|||||||
channels.ChannelItems[channels.SelectedChannel].GetChannelName(),
|
channels.ChannelItems[channels.SelectedChannel].GetChannelName(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Threads: set threads in component
|
||||||
|
threads.SetChannels(thds)
|
||||||
|
|
||||||
// Debug: create the component
|
// Debug: create the component
|
||||||
debug := components.CreateDebugComponent(input.Par.Height)
|
debug := components.CreateDebugComponent(input.Par.Height)
|
||||||
|
|
||||||
@ -62,6 +70,7 @@ func CreateView(config *config.Config, svc *service.SlackService) (*View, error)
|
|||||||
Config: config,
|
Config: config,
|
||||||
Input: input,
|
Input: input,
|
||||||
Channels: channels,
|
Channels: channels,
|
||||||
|
Threads: threads,
|
||||||
Chat: chat,
|
Chat: chat,
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
Debug: debug,
|
Debug: debug,
|
||||||
@ -75,6 +84,7 @@ func (v *View) Refresh() {
|
|||||||
v.Input,
|
v.Input,
|
||||||
v.Chat,
|
v.Chat,
|
||||||
v.Channels,
|
v.Channels,
|
||||||
|
v.Threads,
|
||||||
v.Mode,
|
v.Mode,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user