From cc7dcf1648f53aef8d476d3a12ae9c7e79acd3e9 Mon Sep 17 00:00:00 2001 From: erroneousboat Date: Fri, 7 Oct 2016 22:08:39 +0200 Subject: [PATCH] Remove unsubscribed or closed channels This seems only an issue for IM channels. However there isn't a `excludeArchived` for IM channels. So we will only add users that aren't deleted to the UserCache. When we are adding the IM channels we will check if the name is present in the UserCache, when it isn't we will ignore it. Resulting in channels without IM channels that are from delete users. Fixes #3 --- src/service/slack.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/service/slack.go b/src/service/slack.go index 4d71b30..74b4467 100644 --- a/src/service/slack.go +++ b/src/service/slack.go @@ -39,7 +39,10 @@ func NewSlackService(token string) *SlackService { // the uncovering of usernames of messages users, _ := svc.Client.GetUsers() for _, user := range users { - svc.UserCache[user.ID] = user.Name + // only add non-deleted users + if !user.Deleted { + svc.UserCache[user.ID] = user.Name + } } // Get user associated with token, mainly @@ -89,12 +92,14 @@ func (s *SlackService) GetChannels() []Channel { for _, im := range slackIM { s.SlackChannels = append(s.SlackChannels, im) - // Uncover name + // Uncover name, when we can't uncover name for + // IM channel this is then probably a deleted + // user, because we wont add deleted users + // to the UserCache, so we skip it name, ok := s.UserCache[im.User] - if !ok { - name = im.User + if ok { + chans = append(chans, Channel{im.ID, name}) } - chans = append(chans, Channel{im.ID, name}) } s.Channels = chans