fix: notify recipients for forwarded messages
This commit is contained in:
@@ -147,3 +147,60 @@ func TestSendPushForStoredGroupMessageIncludesEverySubscription(t *testing.T) {
|
||||
t.Fatal("group system message did not enqueue push")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPushForHTTPForwardMessageIncrementsRecipientUnreadOnly(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
oldTopics := store.Topics
|
||||
oldUsersUpdate := globals.usersUpdate
|
||||
oldCluster := globals.cluster
|
||||
oldSessions := globals.sessionStore
|
||||
topics := mock_store.NewMockTopicsPersistenceInterface(ctrl)
|
||||
store.Topics = topics
|
||||
globals.usersUpdate = make(chan *UserCacheReq, 1)
|
||||
globals.cluster = nil
|
||||
globals.sessionStore = NewSessionStore(time.Minute)
|
||||
t.Cleanup(func() {
|
||||
store.Topics = oldTopics
|
||||
globals.usersUpdate = oldUsersUpdate
|
||||
globals.cluster = oldCluster
|
||||
globals.sessionStore = oldSessions
|
||||
})
|
||||
|
||||
sender := types.Uid(42)
|
||||
receiver := types.Uid(99)
|
||||
topic := sender.P2PName(receiver)
|
||||
topics.EXPECT().GetSubs(types.TenantID(7), topic, nil).Return([]types.Subscription{
|
||||
{User: sender.String(), Topic: topic, ModeWant: types.ModeCFull, ModeGiven: types.ModeCFull},
|
||||
{User: receiver.String(), Topic: topic, ModeWant: types.ModeCFull, ModeGiven: types.ModeCFull},
|
||||
}, nil)
|
||||
msg := &types.Message{
|
||||
ObjHeader: types.ObjHeader{CreatedAt: time.Now().UTC()},
|
||||
TenantID: 7,
|
||||
Topic: topic,
|
||||
SeqId: 12,
|
||||
From: sender.String(),
|
||||
Head: types.KVMap{"x-im-type": "text"},
|
||||
Content: map[string]any{"text": "forwarded"},
|
||||
}
|
||||
|
||||
sendPushForHTTPForwardMessage(7, msg, true, msg.CreatedAt)
|
||||
|
||||
select {
|
||||
case req := <-globals.usersUpdate:
|
||||
if req.PushRcpt == nil || len(req.PushRcpt.To) != 2 {
|
||||
t.Fatalf("push recipients: %#v", req)
|
||||
}
|
||||
if req.PushRcpt.To[sender].ShouldIncrementUnreadCountInCache {
|
||||
t.Fatal("sender should not get unread increment for a sender-read forward")
|
||||
}
|
||||
if !req.PushRcpt.To[receiver].ShouldIncrementUnreadCountInCache {
|
||||
t.Fatal("receiver should get unread increment for forwarded message")
|
||||
}
|
||||
if req.PushRcpt.Payload.Topic != topic || req.PushRcpt.Payload.SeqId != 12 {
|
||||
t.Fatalf("unexpected push payload: %#v", req.PushRcpt.Payload)
|
||||
}
|
||||
default:
|
||||
t.Fatal("http forward message did not enqueue push")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user