From 360b34de2a713008e6f9d01ca5c6fb79065480eb Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 18 Jul 2020 00:15:54 -0700 Subject: [PATCH] Account for muted channels --- category.go | 2 +- channel.go | 12 ++++++++++-- go.mod | 2 +- go.sum | 4 ++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/category.go b/category.go index 3615b66..e40bf49 100644 --- a/category.go +++ b/category.go @@ -40,7 +40,7 @@ func (c *Category) Name() text.Rich { } return text.Rich{ - Content: t.Name, + Content: "⯆ " + t.Name, } } diff --git a/channel.go b/channel.go index 82be0e8..887a260 100644 --- a/channel.go +++ b/channel.go @@ -478,6 +478,14 @@ func (ch *Channel) TypingSubscribe(ti cchat.TypingIndicator) (func(), error) { }), nil } +// muted returns if this channel is muted. This includes the channel's category +// and guild. +func (ch *Channel) muted() bool { + return (ch.guildID.Valid() && ch.session.MutedState.Guild(ch.guildID, false)) || + ch.session.MutedState.Channel(ch.id) || + ch.session.MutedState.Category(ch.id) +} + func (ch *Channel) UnreadIndicate(indicator cchat.UnreadIndicator) (func(), error) { if rs := ch.session.ReadState.FindLast(ch.id); rs != nil { c, err := ch.self() @@ -485,13 +493,13 @@ func (ch *Channel) UnreadIndicate(indicator cchat.UnreadIndicator) (func(), erro return nil, errors.Wrap(err, "Failed to get self channel") } - if c.LastMessageID > rs.LastMessageID { + if c.LastMessageID > rs.LastMessageID && !ch.muted() { indicator.SetUnread(true, rs.MentionCount > 0) } } return ch.session.ReadState.OnUpdate(func(ev *read.UpdateEvent) { - if ch.id == ev.ChannelID { + if ch.id == ev.ChannelID && !ch.muted() { indicator.SetUnread(ev.Unread, ev.MentionCount > 0) } }), nil diff --git a/go.mod b/go.mod index ba69406..4c04fa1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/diamondburned/arikawa v0.12.4 github.com/diamondburned/cchat v0.0.45 - github.com/diamondburned/ningen v0.1.1-0.20200717013108-297a3bdf84dc + github.com/diamondburned/ningen v0.1.1-0.20200717072304-e483f86c08e6 github.com/dustin/go-humanize v1.0.0 github.com/go-test/deep v1.0.6 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 3a50e15..69fc966 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,10 @@ github.com/diamondburned/ningen v0.1.1-0.20200716061206-b8f3ae446253 h1:Jpdv9ZnV github.com/diamondburned/ningen v0.1.1-0.20200716061206-b8f3ae446253/go.mod h1:Sunqp1b9Tc0+DtWKslhf83Zepgj/TELB6h8J9HZCPqQ= github.com/diamondburned/ningen v0.1.1-0.20200717013108-297a3bdf84dc h1:YZ84Kdlv91tdcyLfGfQ+LG9kWZN8dTKIic0KlEtGV0U= github.com/diamondburned/ningen v0.1.1-0.20200717013108-297a3bdf84dc/go.mod h1:Sunqp1b9Tc0+DtWKslhf83Zepgj/TELB6h8J9HZCPqQ= +github.com/diamondburned/ningen v0.1.1-0.20200717070406-6dc482b394c0 h1:DkzeHISwAeEYIBiynYkxOz4eNuT2DfTjF93DZjyMLmc= +github.com/diamondburned/ningen v0.1.1-0.20200717070406-6dc482b394c0/go.mod h1:Sunqp1b9Tc0+DtWKslhf83Zepgj/TELB6h8J9HZCPqQ= +github.com/diamondburned/ningen v0.1.1-0.20200717072304-e483f86c08e6 h1:YN0cj0aOCa+tKmx0aD5qsbSYaIJnyrA0/+eygMKP+/w= +github.com/diamondburned/ningen v0.1.1-0.20200717072304-e483f86c08e6/go.mod h1:Sunqp1b9Tc0+DtWKslhf83Zepgj/TELB6h8J9HZCPqQ= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=