Update retrieval of messages from slack

This commit is contained in:
erroneousboat 2016-09-26 22:07:38 +02:00
parent 555184a033
commit ae642f6a14
2 changed files with 13 additions and 6 deletions

View File

@ -131,7 +131,9 @@ func (c *Chat) SetY(y int) {
}
func (c *Chat) GetMessages(svc *service.SlackService) {
messages := svc.GetMessages(c.SelectedChannel)
// Get the count of message that fit in the pane
count := c.List.InnerBounds().Max.Y - c.List.InnerBounds().Min.Y
messages := svc.GetMessages(c.SelectedChannel, count)
for _, message := range messages {
c.AddMessage(message)

View File

@ -52,12 +52,10 @@ func (s *SlackService) GetChannels() []Channel {
func (s *SlackService) SendMessage(message string) {}
func (s *SlackService) GetMessages(channel string) []string {
func (s *SlackService) GetMessages(channel string, count int) []string {
// https://api.slack.com/methods/channels.history
historyParams := slack.HistoryParameters{
// Latest: "now",
// Oldest: 0,
Count: 50,
Count: count,
Inclusive: false,
Unreads: false,
}
@ -84,5 +82,12 @@ func (s *SlackService) GetMessages(channel string) []string {
messages = append(messages, msg)
}
return messages
// Reverse the order of the messages, we want the newest in
// the last place
var messagesReversed []string
for i := len(messages) - 1; i >= 0; i-- {
messagesReversed = append(messagesReversed, messages[i])
}
return messagesReversed
}