Fix clearing webpush targets after any MARKREAD
Previously, we would clear webpush targets after any MARKREAD. Consider the following scenario (ignore any typos, this is crafted by hand): <<< @time=2020-01-01T00:00:00Z PRIVMSG #foo :hi mark! <<< @time=2020-01-02T00:00:00Z PRIVMSG #foo :hi again mark! >>> MARKREAD #foo timestamp=2020-01-01T00:00:00Z >>> MARKREAD #foo timestamp=2020-01-02T00:00:00Z The push target was previously cleared on the first MARKREAD, which means that the second MARKREAD was never broadcast to Firebase, and all devices would keep the "hi again mark!" notification indefinitely. This changes the webpush target map so that we store a timestamp of the last highlight we sent. We only clear the push target when sending a MARKREAD that is at or after the last message.
This commit is contained in:
parent
897c21dbb4
commit
ac578823dc
@ -2818,7 +2818,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
|
|
||||||
if broadcast && network.pushTargets.Has(target) {
|
if broadcast && network.pushTargets.Has(target) {
|
||||||
// TODO: only broadcast if draft/read-marker has been negotiated
|
// TODO: only broadcast if draft/read-marker has been negotiated
|
||||||
network.pushTargets.Del(target)
|
if !r.Timestamp.Before(network.pushTargets.Get(target)) {
|
||||||
|
network.pushTargets.Del(target)
|
||||||
|
}
|
||||||
go network.broadcastWebPush(&irc.Message{
|
go network.broadcastWebPush(&irc.Message{
|
||||||
Command: "MARKREAD",
|
Command: "MARKREAD",
|
||||||
Params: []string{target, timestampStr},
|
Params: []string{target, timestampStr},
|
||||||
|
14
irc.go
14
irc.go
@ -459,10 +459,18 @@ func (cm *monitorCasemapMap) ForEach(f func(name string, online bool)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type casemapSet struct{ casemapMap }
|
type pushTargetCasemapMap struct{ casemapMap }
|
||||||
|
|
||||||
func (cs *casemapSet) Add(name string) {
|
func (cm *pushTargetCasemapMap) Get(name string) (last time.Time) {
|
||||||
cs.set(name, nil)
|
if v := cm.get(name); v == nil {
|
||||||
|
return time.Time{}
|
||||||
|
} else {
|
||||||
|
return v.(time.Time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cm *pushTargetCasemapMap) Set(name string, last time.Time) {
|
||||||
|
cm.set(name, last)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWordBoundary(r rune) bool {
|
func isWordBoundary(r rune) bool {
|
||||||
|
@ -556,7 +556,9 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
|
|
||||||
if highlight || uc.isOurNick(target) {
|
if highlight || uc.isOurNick(target) {
|
||||||
go uc.network.broadcastWebPush(msg)
|
go uc.network.broadcastWebPush(msg)
|
||||||
uc.network.pushTargets.Add(bufferName)
|
if timestamp, err := time.Parse(xirc.ServerTimeLayout, string(msg.Tags["time"])); err == nil {
|
||||||
|
uc.network.pushTargets.Set(bufferName, timestamp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uc.produce(bufferName, msg, downstreamID)
|
uc.produce(bufferName, msg, downstreamID)
|
||||||
|
4
user.go
4
user.go
@ -141,7 +141,7 @@ type network struct {
|
|||||||
conn *upstreamConn
|
conn *upstreamConn
|
||||||
channels channelCasemapMap
|
channels channelCasemapMap
|
||||||
delivered deliveredStore
|
delivered deliveredStore
|
||||||
pushTargets casemapSet
|
pushTargets pushTargetCasemapMap
|
||||||
lastError error
|
lastError error
|
||||||
casemap casemapping
|
casemap casemapping
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ func newNetwork(user *user, record *database.Network, channels []database.Channe
|
|||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
channels: m,
|
channels: m,
|
||||||
delivered: newDeliveredStore(),
|
delivered: newDeliveredStore(),
|
||||||
pushTargets: casemapSet{newCasemapMap()},
|
pushTargets: pushTargetCasemapMap{newCasemapMap()},
|
||||||
casemap: casemapRFC1459,
|
casemap: casemapRFC1459,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user