Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion components/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
IconIM = "●"
IconMpIM = "☰"
IconNotification = "*"
IconImportant = "!"

PresenceAway = "away"
PresenceActive = "active"
Expand All @@ -34,6 +35,7 @@ type ChannelItem struct {
UserID string
Presence string
Notification bool
Mention bool

StylePrefix string
StyleIcon string
Expand All @@ -46,7 +48,11 @@ type ChannelItem struct {
func (c ChannelItem) ToString() string {
var prefix string
if c.Notification {
prefix = IconNotification
if c.Mention {
prefix = IconImportant
} else {
prefix = IconNotification
}
} else {
prefix = " "
}
Expand Down Expand Up @@ -208,13 +214,19 @@ func (c *Channels) SetChannels(channels []ChannelItem) {

func (c *Channels) MarkAsRead(channelID int) {
c.ChannelItems[channelID].Notification = false
c.ChannelItems[channelID].Mention = false
}

func (c *Channels) MarkAsUnread(channelID string) {
index := c.FindChannel(channelID)
c.ChannelItems[index].Notification = true
}

func (c *Channels) MarkAsMention(channelID string) {
index := c.FindChannel(channelID)
c.ChannelItems[index].Mention = true
}

func (c *Channels) SetPresence(channelID string, presence string) {
index := c.FindChannel(channelID)
c.ChannelItems[index].Presence = presence
Expand Down
7 changes: 0 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ func NewConfig(filepath string) (*Config, error) {

cfg.MainWidth = 12 - cfg.SidebarWidth

switch cfg.Notify {
case NotifyAll, NotifyMention, "":
break
default:
return &cfg, fmt.Errorf("unsupported setting for notify: %s", cfg.Notify)
}

termui.ColorMap = map[string]termui.Attribute{
"fg": termui.StringToAttribute(cfg.Theme.View.Fg),
"bg": termui.StringToAttribute(cfg.Theme.View.Bg),
Expand Down
25 changes: 22 additions & 3 deletions handlers/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,15 @@ func actionNewMessage(ctx *context.AppContext, ev *slack.MessageEvent) {
ctx.View.Channels.MarkAsUnread(ev.Channel)
termui.Render(ctx.View.Channels)

// Terminal bell
fmt.Print("\a")

// Desktop notification
if ctx.Config.Notify == config.NotifyMention {
if isMention(ctx, ev) {
createNotifyMessage(ctx, ev)
}
} else if ctx.Config.Notify == config.NotifyAll {
createNotifyMessage(ctx, ev)
} else if isHighlight(ctx, ev) {
createNotifyMessage(ctx, ev)
}
}

Expand Down Expand Up @@ -545,7 +544,27 @@ func isMention(ctx *context.AppContext, ev *slack.MessageEvent) bool {
return false
}

// isHighlight check if the message contains a notify keyword
func isHighlight(ctx *context.AppContext, ev *slack.MessageEvent) bool {
for _, substr := range strings.Split(ctx.Config.Notify, ",") {
if strings.Compare(substr, config.NotifyMention) == 0 {
if isMention(ctx, ev) {
return true
}
} else if strings.Contains(ev.Text, substr) {
return true
}
}

return false
}

func createNotifyMessage(ctx *context.AppContext, ev *slack.MessageEvent) {
// Terminal bell
fmt.Print("\a")
// Mark as mentioned
ctx.View.Channels.MarkAsMention(ev.Channel)
// Desktop notification
go func() {
if notifyTimer != nil {
notifyTimer.Stop()
Expand Down