3
0
mirror of https://github.com/ergochat/ergo.git synced 2026-03-12 10:18:06 +01:00
Add msgid to push messages when available, as required by the spec
This commit is contained in:
Shivaram Lingamneni 2026-03-10 14:50:01 -07:00 committed by GitHub
parent 3c41a81921
commit ec7db5a02b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 14 deletions

View File

@ -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,

View File

@ -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

View File

@ -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)
}