mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-11-22 14:12:47 +00:00
Bumped Ningen; added unread
This commit is contained in:
parent
5ec2584509
commit
6e52197039
26
channel.go
26
channel.go
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/diamondburned/cchat"
|
||||
"github.com/diamondburned/cchat-discord/segments"
|
||||
"github.com/diamondburned/cchat/text"
|
||||
"github.com/diamondburned/ningen/states/read"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -75,6 +76,7 @@ var (
|
|||
_ cchat.ServerMessageEditor = (*Channel)(nil)
|
||||
_ cchat.ServerMessageActioner = (*Channel)(nil)
|
||||
_ cchat.ServerMessageTypingIndicator = (*Channel)(nil)
|
||||
_ cchat.ServerMessageUnreadIndicator = (*Channel)(nil)
|
||||
)
|
||||
|
||||
func NewChannel(s *Session, ch discord.Channel) *Channel {
|
||||
|
@ -251,6 +253,11 @@ func (ch *Channel) JoinServer(ctx context.Context, ct cchat.MessagesContainer) (
|
|||
ch.session.AddHandler(func(m *gateway.MessageCreateEvent) {
|
||||
if m.ChannelID == ch.id {
|
||||
ct.CreateMessage(NewMessageCreate(m, ch.session))
|
||||
// Mark as read if the message is not ours. This handler will
|
||||
// stay here as long as the client is seeing the channel.
|
||||
if m.Author.ID != ch.session.userID {
|
||||
ch.session.ReadState.MarkRead(ch.id, m.ID)
|
||||
}
|
||||
}
|
||||
}),
|
||||
ch.session.AddHandler(func(m *gateway.MessageUpdateEvent) {
|
||||
|
@ -471,6 +478,25 @@ func (ch *Channel) TypingSubscribe(ti cchat.TypingIndicator) (func(), error) {
|
|||
}), nil
|
||||
}
|
||||
|
||||
func (ch *Channel) UnreadIndicate(indicator cchat.UnreadIndicator) (func(), error) {
|
||||
if rs := ch.session.ReadState.FindLast(ch.id); rs != nil {
|
||||
c, err := ch.self()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to get self channel")
|
||||
}
|
||||
|
||||
if c.LastMessageID > rs.LastMessageID {
|
||||
indicator.SetUnread(true, rs.MentionCount > 0)
|
||||
}
|
||||
}
|
||||
|
||||
return ch.session.ReadState.OnUpdate(func(ev *read.UpdateEvent) {
|
||||
if ch.id == ev.ChannelID {
|
||||
indicator.SetUnread(ev.Unread, ev.MentionCount > 0)
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
func newCancels() func(...func()) []func() {
|
||||
var cancels []func()
|
||||
return func(appended ...func()) []func() {
|
||||
|
|
6
go.mod
6
go.mod
|
@ -3,9 +3,9 @@ module github.com/diamondburned/cchat-discord
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/diamondburned/arikawa v0.10.5
|
||||
github.com/diamondburned/cchat v0.0.43
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa
|
||||
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/dustin/go-humanize v1.0.0
|
||||
github.com/go-test/deep v1.0.6
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
|
10
go.sum
10
go.sum
|
@ -31,6 +31,8 @@ github.com/diamondburned/arikawa v0.10.2 h1:xTsFWlWwGzFr8HD7tyv2jMRyserOR4yV5dhq
|
|||
github.com/diamondburned/arikawa v0.10.2/go.mod h1:nIhVIatzTQhPUa7NB8w4koG1RF9gYbpAr8Fj8sKq660=
|
||||
github.com/diamondburned/arikawa v0.10.5 h1:o5lBopooA+8cXlKZdct5qF0xztuZZ35phvQrwGS5vYM=
|
||||
github.com/diamondburned/arikawa v0.10.5/go.mod h1:nIhVIatzTQhPUa7NB8w4koG1RF9gYbpAr8Fj8sKq660=
|
||||
github.com/diamondburned/arikawa v0.12.4 h1:lhWJqcGkIIMiOYWdsoEuGlri2UbMkzMeh+VfuJPkXt4=
|
||||
github.com/diamondburned/arikawa v0.12.4/go.mod h1:nIhVIatzTQhPUa7NB8w4koG1RF9gYbpAr8Fj8sKq660=
|
||||
github.com/diamondburned/cchat v0.0.34 h1:BGiVxMRA9dmW3rLilIldBvjVan7eTTpaWCCfX9IKBYU=
|
||||
github.com/diamondburned/cchat v0.0.34/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/diamondburned/cchat v0.0.35 h1:WiMGl8BQJgbP9E4xRxgLGlqUsHpTcJgDKDt8/6a7lBk=
|
||||
|
@ -49,6 +51,10 @@ github.com/diamondburned/cchat v0.0.42 h1:FVMLy9hOTxKju8OWDBIStrekbgTHCaH8+GVnV4
|
|||
github.com/diamondburned/cchat v0.0.42/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/diamondburned/cchat v0.0.43 h1:HetAujSaUSdnQgAUZgprNLARjf/MSWXpCfWdvX2wOCU=
|
||||
github.com/diamondburned/cchat v0.0.43/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/diamondburned/cchat v0.0.44 h1:NmXw4bU3nCPxxKYK6K5LjRjNMp15uXfcKVEt1KTA+SI=
|
||||
github.com/diamondburned/cchat v0.0.44/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/diamondburned/cchat v0.0.45 h1:HMVSKx1h6lh2OenWaBTvMSK531hWaXAW7I0tKZepYug=
|
||||
github.com/diamondburned/cchat v0.0.45/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249 h1:yP7kJ+xCGpDz6XbcfACJcju4SH1XDPwlrvbofz3lP8I=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200621014632-6babb812b249/go.mod h1:xW9hpBZsGi8KpAh10TyP+YQlYBo+Xc+2w4TR6N0951A=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200708085949-b64e350f3b8c h1:3h/kyk6HplYZF3zLi106itjYJWjbuMK/twijeGLEy2M=
|
||||
|
@ -67,6 +73,10 @@ github.com/diamondburned/ningen v0.1.1-0.20200715034121-61de7138eb56 h1:DAk3bEwJ
|
|||
github.com/diamondburned/ningen v0.1.1-0.20200715034121-61de7138eb56/go.mod h1:SKPY3387RHCbMrnefex9D+zlrA2yB+LCtaaQAgatAuc=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa h1:ntHcz6GNzxn3TovtYZVwOBvL3xn7Iq1luaV/KEIEXrk=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa/go.mod h1:SKPY3387RHCbMrnefex9D+zlrA2yB+LCtaaQAgatAuc=
|
||||
github.com/diamondburned/ningen v0.1.1-0.20200716061206-b8f3ae446253 h1:Jpdv9ZnViZct1aSYhE1NZRIkmIodey1OeeqdCSoAu40=
|
||||
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/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=
|
||||
|
|
Loading…
Reference in a new issue