Fix message persistence

This commit is contained in:
erroneousboat 2016-09-29 19:09:30 +02:00
parent 544397dee9
commit a0603698f9
3 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,6 @@
Bugs:
- [ ] when switching channels sometimes messages are persisted in the new
- [x] when switching channels sometimes messages are persisted in the new
channel, the Buffer() in Chat will probably not go further than the
latest message. Could be that items are added to List and not cleared
when switching channels

View File

@ -12,6 +12,7 @@ type Chat struct {
SelectedChannel string
}
// CreateChat is the constructor for the Chat struct
func CreateChat(svc *service.SlackService, inputHeight int, selectedChannel SlackChannel) *Chat {
chat := &Chat{
List: termui.NewList(),
@ -129,6 +130,8 @@ func (c *Chat) SetY(y int) {
c.List.SetY(y)
}
// GetMessages will get an array of strings for a specific channel which will
// contain messages in turn all these messages will be added to List.Items
func (c *Chat) GetMessages(svc *service.SlackService, channel string) {
// Get the count of message that fit in the pane
count := c.List.InnerBounds().Max.Y - c.List.InnerBounds().Min.Y
@ -139,15 +142,22 @@ func (c *Chat) GetMessages(svc *service.SlackService, channel string) {
}
}
// AddMessage adds a single message to List.Items
func (c *Chat) AddMessage(message string) {
c.List.Items = append(c.List.Items, message)
}
// ClearMessages clear the List.Items
func (c *Chat) ClearMessages() {
c.List.Items = []string{}
}
func (c *Chat) ScrollUp() {
}
func (c *Chat) ScrollDown() {}
// SetBorderLabel will set Label of the Chat pane to the specified string
func (c *Chat) SetBorderLabel(label string) {
c.List.BorderLabel = label
}

View File

@ -197,28 +197,25 @@ func actionGetChannels(ctx *context.AppContext) {
func actionMoveCursorUpChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorUp()
ctx.View.Chat.GetMessages(
ctx.Service,
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].ID,
)
ctx.View.Chat.SetBorderLabel(
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].Name,
)
termui.Render(ctx.View.Channels)
termui.Render(ctx.View.Chat)
actionChangeChannel(ctx)
}
func actionMoveCursorDownChannels(ctx *context.AppContext) {
ctx.View.Channels.MoveCursorDown()
actionChangeChannel(ctx)
}
func actionChangeChannel(ctx *context.AppContext) {
// Clear messages from Chat pane
ctx.View.Chat.ClearMessages()
// Get message for the new channel
ctx.View.Chat.GetMessages(
ctx.Service,
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].ID,
)
// Set channel name for the Chat pane
ctx.View.Chat.SetBorderLabel(
ctx.View.Channels.SlackChannels[ctx.View.Channels.SelectedChannel].Name,
)