Fix read mark for channels

Fixes #178
This commit is contained in:
erroneousboat 2019-05-11 12:20:52 +02:00
parent 609c37cdfe
commit 8475d8d63d
2 changed files with 25 additions and 7 deletions

View File

@ -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)
}

View File

@ -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