From 8475d8d63d6702c3d2561d50f3d89c63cc70ff10 Mon Sep 17 00:00:00 2001 From: erroneousboat Date: Sat, 11 May 2019 12:20:52 +0200 Subject: [PATCH] Fix read mark for channels Fixes #178 --- handlers/event.go | 4 ++-- service/slack.go | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/handlers/event.go b/handlers/event.go index 07520f6..8a047c9 100644 --- a/handlers/event.go +++ b/handlers/event.go @@ -270,7 +270,7 @@ func actionSend(ctx *context.AppContext) { // Clear notification icon if there is any channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel] if channelItem.Notification { - ctx.Service.MarkAsRead(channelItem.ID) + ctx.Service.MarkAsRead(channelItem) ctx.View.Channels.MarkAsRead(ctx.View.Channels.SelectedChannel) } termui.Render(ctx.View.Channels) @@ -425,7 +425,7 @@ func actionChangeChannel(ctx *context.AppContext) { // Clear notification icon if there is any channelItem := ctx.View.Channels.ChannelItems[ctx.View.Channels.SelectedChannel] if channelItem.Notification { - ctx.Service.MarkAsRead(channelItem.ID) + ctx.Service.MarkAsRead(channelItem) ctx.View.Channels.MarkAsRead(ctx.View.Channels.SelectedChannel) } diff --git a/service/slack.go b/service/slack.go index 6e91de1..d2c4c7b 100644 --- a/service/slack.go +++ b/service/slack.go @@ -275,11 +275,29 @@ func (s *SlackService) SetUserAsActive() { } // MarkAsRead will set the channel as read -func (s *SlackService) MarkAsRead(channelID string) { - s.Client.SetChannelReadMark( - channelID, fmt.Sprintf("%f", - float64(time.Now().Unix())), - ) +func (s *SlackService) MarkAsRead(channelItem components.ChannelItem) { + switch channelItem.Type { + case components.ChannelTypeChannel: + s.Client.SetChannelReadMark( + channelItem.ID, fmt.Sprintf("%f", + float64(time.Now().Unix())), + ) + case components.ChannelTypeGroup: + s.Client.SetGroupReadMark( + channelItem.ID, fmt.Sprintf("%f", + float64(time.Now().Unix())), + ) + case components.ChannelTypeMpIM: + s.Client.MarkIMChannel( + channelItem.ID, fmt.Sprintf("%f", + float64(time.Now().Unix())), + ) + case components.ChannelTypeIM: + s.Client.MarkIMChannel( + channelItem.ID, fmt.Sprintf("%f", + float64(time.Now().Unix())), + ) + } } // SendMessage will send a message to a particular channel