Fix message notification when current user sends message

Fixes #8
This commit is contained in:
erroneousboat 2016-10-05 21:57:43 +02:00
parent 6a15950505
commit 6c2ac43bda
3 changed files with 18 additions and 3 deletions

View File

@ -47,4 +47,6 @@ build-mac:
run: build
./bin/slack-term
.PHONY: default test build run
build-all: build build-linux build-mac
.PHONY: default test build build-linux build-mac run

View File

@ -85,8 +85,11 @@ func incomingMessageHandler(ctx *context.AppContext) {
// Set new message indicator for channel, I'm leaving
// this here because I also want to be notified when
// I'm currently in a channel but not in the terminal
// window (tmux)
actionNewMessage(ctx, ev.Channel)
// window (tmux). But only create a notification when
// it comes from someone else but the current user.
if ev.User != ctx.Service.CurrentUserID {
actionNewMessage(ctx, ev.Channel)
}
}
}
}

View File

@ -15,6 +15,7 @@ type SlackService struct {
SlackChannels []interface{}
Channels []Channel
UserCache map[string]string
CurrentUserID string
}
type Channel struct {
@ -41,6 +42,15 @@ func NewSlackService(token string) *SlackService {
svc.UserCache[user.ID] = user.Name
}
// Get user associated with token, mainly
// used to identify user when new messages
// arrives
authTest, err := svc.Client.AuthTest()
if err != nil {
log.Fatal("Client.AuthTest() failed")
}
svc.CurrentUserID = authTest.UserID
return svc
}