fix: expire stale call pushes

This commit is contained in:
richjohnrambo
2026-09-14 12:11:43 +08:00
parent 4854e090ef
commit 789e662bdb
8 changed files with 164 additions and 14 deletions
+55
View File
@@ -0,0 +1,55 @@
package fcm
import (
"testing"
"time"
"github.com/tinode/chat/server/push"
"github.com/tinode/chat/server/store/types"
)
func TestPayloadToDataIncludesCallExpiresAt(t *testing.T) {
expiresAt := time.Date(2026, 9, 4, 10, 0, 30, 0, time.UTC)
data, err := payloadToData(&push.Payload{
What: push.ActMsg,
Topic: "p2pTopic",
From: "usrCaller",
SeqId: 30,
Webrtc: "started",
ExpiresAt: &expiresAt,
Content: map[string]any{
"txt": "call",
},
Timestamp: time.Date(2026, 9, 4, 10, 0, 0, 0, time.UTC),
})
if err != nil {
t.Fatalf("payload data: %v", err)
}
if data["expires_at"] != expiresAt.Format(time.RFC3339Nano) {
t.Fatalf("unexpected expires_at: %#v", data)
}
}
func TestPrepareV1NotificationsDropsExpiredCallInvite(t *testing.T) {
expiresAt := time.Now().Add(-time.Second)
messages, uids := PrepareV1Notifications(&push.Receipt{
TenantID: 7,
To: map[types.Uid]push.Recipient{
42: {},
},
Payload: push.Payload{
What: push.ActMsg,
Topic: "p2pTopic",
SeqId: 30,
Webrtc: "started",
ExpiresAt: &expiresAt,
Content: map[string]any{
"txt": "call",
},
Timestamp: time.Now().Add(-time.Minute),
},
}, &configType{})
if len(messages) != 0 || len(uids) != 0 {
t.Fatalf("expired call invite should be dropped: messages=%d uids=%#v", len(messages), uids)
}
}