From ec7db5a02b89d41eb9ffeee9b4f52b7af1fec755 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 10 Mar 2026 14:50:01 -0700 Subject: [PATCH] fix #2349 (#2350) Add msgid to push messages when available, as required by the spec --- irc/handlers.go | 4 +++- irc/webpush/webpush.go | 18 ++++++++++-------- irc/webpush/webpush_test.go | 11 ++++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index 8b527e18..bc0cb957 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -3125,7 +3125,9 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res } } if client.clearClearablePushMessage(cftarget, readTime) { - line, err := webpush.MakePushLine(time.Now().UTC(), "*", server.name, "MARKREAD", unfoldedTarget, readTimestamp) + markreadPushMessage := ircmsg.MakeMessage(nil, server.name, "MARKREAD", unfoldedTarget, readTimestamp) + markreadPushMessage.SetTag("time", time.Now().UTC().Format(utils.IRCv3TimestampFormat)) + line, err := webpush.MakePushLine(markreadPushMessage) if err == nil { client.dispatchPushMessage(pushMessage{ msg: line, diff --git a/irc/webpush/webpush.go b/irc/webpush/webpush.go index a97d7ed4..dc0fb2b0 100644 --- a/irc/webpush/webpush.go +++ b/irc/webpush/webpush.go @@ -11,7 +11,6 @@ import ( "errors" "fmt" "net/http" - "time" "github.com/ergochat/irc-go/ircmsg" webpush "github.com/ergochat/webpush-go/v2" @@ -97,18 +96,21 @@ func MakePushMessage(command, nuh, accountName, target string, msg utils.SplitMe } else { messageForPush = msg.Split[0].Message } - return MakePushLine(msg.Time, accountName, nuh, command, target, messageForPush) -} -// MakePushLine serializes an arbitrary IRC line as a web push message (the args are in -// IRC syntax order) -func MakePushLine(time time.Time, accountName, source, command string, params ...string) ([]byte, error) { - pushMessage := ircmsg.MakeMessage(nil, source, command, params...) - pushMessage.SetTag("time", time.Format(utils.IRCv3TimestampFormat)) + pushMessage := ircmsg.MakeMessage(nil, nuh, command, target, messageForPush) + pushMessage.SetTag("time", msg.Time.Format(utils.IRCv3TimestampFormat)) + pushMessage.SetTag("msgid", msg.Msgid) // "*" is canonical for the unset form of the unfolded account name, but check both: if accountName != "*" && accountName != "" { pushMessage.SetTag("account", accountName) } + + return MakePushLine(pushMessage) +} + +// MakePushLine serializes an arbitrary IRC message as a web push message; +// we assume tags were already filtered. +func MakePushLine(pushMessage ircmsg.Message) ([]byte, error) { if line, err := pushMessage.LineBytesStrict(false, 512); err == nil { // strip final \r\n return line[:len(line)-2], nil diff --git a/irc/webpush/webpush_test.go b/irc/webpush/webpush_test.go index 4e227fd5..dfc51b04 100644 --- a/irc/webpush/webpush_test.go +++ b/irc/webpush/webpush_test.go @@ -11,12 +11,13 @@ import ( ) func TestBuildPushLine(t *testing.T) { - now, err := time.Parse(utils.IRCv3TimestampFormat, "2025-01-12T00:55:44.403Z") - if err != nil { - panic(err) - } + now := "2025-01-12T00:55:44.403Z" + readTimestamp := "timestamp=2025-01-12T00:07:57.972Z" - line, err := MakePushLine(now, "*", "ergo.test", "MARKREAD", "#ergo", "timestamp=2025-01-12T00:07:57.972Z") + markreadPushMessage := ircmsg.MakeMessage(nil, "ergo.test", "MARKREAD", "#ergo", readTimestamp) + markreadPushMessage.SetTag("time", now) + + line, err := MakePushLine(markreadPushMessage) if err != nil { t.Fatal(err) }