Skip to content

Commit

Permalink
Add read mark for channels
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
jpbruinsslot committed Oct 29, 2016
1 parent d3cbfa0 commit e760f7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,7 @@ func (c *Channels) ClearNewMessageIndicator() {
c.List.Items[c.SelectedChannel] = channelName[0]
}
}

func (c *Channels) SetReadMark(svc *service.SlackService) {
svc.SetChannelReadMark(svc.SlackChannels[c.SelectedChannel])
}
3 changes: 3 additions & 0 deletions handlers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func actionChangeChannel(ctx *context.AppContext) {
ctx.Service.Channels[ctx.View.Channels.SelectedChannel].Name,
)

// Set read mark
ctx.View.Channels.SetReadMark(ctx.Service)

termui.Render(ctx.View.Channels)
termui.Render(ctx.View.Chat)
}
Expand Down
13 changes: 12 additions & 1 deletion service/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ func (s *SlackService) GetChannels() []Channel {
return chans
}

// FIXME: timestamp is not yet correct
func (s *SlackService) SetChannelReadMark(channel interface{}) {
switch channel := channel.(type) {
case slack.Channel:
s.Client.SetChannelReadMark(channel.ID, string(time.Now().UnixNano()))
case slack.Group:
s.Client.SetGroupReadMark(channel.ID, string(time.Now().UnixNano()))
case slack.IM:
s.Client.MarkIMChannel(channel.ID, string(time.Now().UnixNano()))
}
}

func (s *SlackService) SendMessage(channel string, message string) {
// https://godoc.org/github.com/nlopes/slack#PostMessageParameters
postParams := slack.PostMessageParameters{
Expand Down Expand Up @@ -135,7 +147,6 @@ func (s *SlackService) GetMessages(channel interface{}, count int) []string {
log.Fatal(err) // FIXME
}
case slack.Group:
// TODO: json: cannot unmarshal number into Go value of type string<Paste>
history, err = s.Client.GetGroupHistory(chnType.ID, historyParams)
if err != nil {
log.Fatal(err) // FIXME
Expand Down

0 comments on commit e760f7d

Please sign in to comment.