Send MARKREAD push notifications

Allows clients to dismiss notifications when another client marks
the conversation as read.
This commit is contained in:
Simon Ser 2022-07-08 16:55:29 +02:00
parent 7e21e79eab
commit 14cbd63412
4 changed files with 38 additions and 17 deletions

View File

@ -2004,6 +2004,8 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
if err := uc.network.deleteChannel(ctx, upstreamName); err != nil { if err := uc.network.deleteChannel(ctx, upstreamName); err != nil {
dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err) dc.logger.Printf("failed to delete channel %q: %v", upstreamName, err)
} }
uc.network.pushTargets.Del(upstreamName)
} }
} }
case "KICK": case "KICK":
@ -2994,6 +2996,16 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
}) })
} }
}) })
if broadcast && network.pushTargets.Has(entity) {
// TODO: only broadcast if draft/read-marker has been negotiated
// TODO: use lower priority
network.pushTargets.Del(entity)
network.broadcastWebPush(ctx, &irc.Message{
Command: "MARKREAD",
Params: []string{entity, timestampStr},
})
}
case "SEARCH": case "SEARCH":
store, ok := dc.user.msgStore.(msgstore.SearchStore) store, ok := dc.user.msgStore.(msgstore.SearchStore)
if !ok { if !ok {

6
irc.go
View File

@ -464,6 +464,12 @@ func (cm *monitorCasemapMap) ForEach(f func(name string, online bool)) {
} }
} }
type casemapSet struct{ casemapMap }
func (cs *casemapSet) Add(name string) {
cs.set(name, nil)
}
func isWordBoundary(r rune) bool { func isWordBoundary(r rune) bool {
switch r { switch r {
case '-', '_', '|': // inspired from weechat.look.highlight_regex case '-', '_', '|': // inspired from weechat.look.highlight_regex

View File

@ -522,21 +522,21 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
self := uc.isOurNick(msg.Prefix.Name) self := uc.isOurNick(msg.Prefix.Name)
ch := uc.network.channels.Get(bufferName) ch := uc.network.channels.Get(bufferName)
highlight := false
if ch != nil && msg.Command != "TAGMSG" && !self { if ch != nil && msg.Command != "TAGMSG" && !self {
if ch.Detached { if ch.Detached {
uc.handleDetachedMessage(ctx, ch, msg) uc.handleDetachedMessage(ctx, ch, msg)
} }
highlight := uc.network.isHighlight(msg) highlight = uc.network.isHighlight(msg)
if ch.DetachOn == database.FilterMessage || ch.DetachOn == database.FilterDefault || (ch.DetachOn == database.FilterHighlight && highlight) { if ch.DetachOn == database.FilterMessage || ch.DetachOn == database.FilterDefault || (ch.DetachOn == database.FilterHighlight && highlight) {
uc.updateChannelAutoDetach(bufferName) uc.updateChannelAutoDetach(bufferName)
} }
if highlight {
uc.network.broadcastWebPush(ctx, msg)
}
} }
if ch == nil && uc.isOurNick(target) {
if highlight || uc.isOurNick(target) {
uc.network.broadcastWebPush(ctx, msg) uc.network.broadcastWebPush(ctx, msg)
uc.network.pushTargets.Add(bufferName)
} }
uc.produce(bufferName, msg, downstreamID) uc.produce(bufferName, msg, downstreamID)

27
user.go
View File

@ -131,11 +131,12 @@ type network struct {
logger Logger logger Logger
stopped chan struct{} stopped chan struct{}
conn *upstreamConn conn *upstreamConn
channels channelCasemapMap channels channelCasemapMap
delivered deliveredStore delivered deliveredStore
lastError error pushTargets casemapSet
casemap casemapping lastError error
casemap casemapping
} }
func newNetwork(user *user, record *database.Network, channels []database.Channel) *network { func newNetwork(user *user, record *database.Network, channels []database.Channel) *network {
@ -148,13 +149,14 @@ func newNetwork(user *user, record *database.Network, channels []database.Channe
} }
return &network{ return &network{
Network: *record, Network: *record,
user: user, user: user,
logger: logger, logger: logger,
stopped: make(chan struct{}), stopped: make(chan struct{}),
channels: m, channels: m,
delivered: newDeliveredStore(), delivered: newDeliveredStore(),
casemap: casemapRFC1459, pushTargets: casemapSet{newCasemapMap()},
casemap: casemapRFC1459,
} }
} }
@ -377,6 +379,7 @@ func (net *network) updateCasemapping(newCasemap casemapping) {
net.casemap = newCasemap net.casemap = newCasemap
net.channels.SetCasemapping(newCasemap) net.channels.SetCasemapping(newCasemap)
net.delivered.m.SetCasemapping(newCasemap) net.delivered.m.SetCasemapping(newCasemap)
net.pushTargets.SetCasemapping(newCasemap)
if uc := net.conn; uc != nil { if uc := net.conn; uc != nil {
uc.channels.SetCasemapping(newCasemap) uc.channels.SetCasemapping(newCasemap)
uc.channels.ForEach(func(uch *upstreamChannel) { uc.channels.ForEach(func(uch *upstreamChannel) {