fix cp invite requester room notice

This commit is contained in:
zhx 2026-06-11 19:12:50 +08:00
parent 811178252f
commit eea564ac56
3 changed files with 31 additions and 6 deletions

View File

@ -195,7 +195,7 @@ func validateDelivery(delivery CPDelivery) error {
if isTencentIMC2CChannel(delivery.Channel) && delivery.SenderUserID <= 0 {
return xerr.New(xerr.InvalidArgument, "cp c2c delivery sender_user_id is required")
}
if (delivery.Channel == channelTencentIMRoom || delivery.Channel == channelTencentIMRegion) && strings.TrimSpace(delivery.GroupID) == "" {
if (delivery.Channel == channelTencentIMRoom || delivery.Channel == channelTencentIMRoomSender || delivery.Channel == channelTencentIMRegion) && strings.TrimSpace(delivery.GroupID) == "" {
return xerr.New(xerr.InvalidArgument, "cp group delivery group_id is required")
}
return nil

View File

@ -25,6 +25,7 @@ const (
channelTencentIMC2C = "tencent_im_c2c"
channelTencentIMC2CAcceptor = "tencent_im_c2c_acceptor"
channelTencentIMRoom = "tencent_im_room"
channelTencentIMRoomSender = "tencent_im_room_sender"
channelTencentIMRegion = "tencent_im_region"
noticeTypeApplicationCreated = "cp_application_created"
@ -109,7 +110,7 @@ func (s *Service) publishDelivery(ctx context.Context, delivery CPDelivery, opti
Ext: "cp_relation_notice",
PayloadJSON: delivery.PayloadJSON,
})
case channelTencentIMRoom:
case channelTencentIMRoom, channelTencentIMRoomSender:
err = s.publisher.PublishGroupCustomMessage(publishCtx, tencentim.CustomGroupMessage{
GroupID: delivery.GroupID,
EventID: delivery.EventID,
@ -214,6 +215,8 @@ func deliveriesFromMessage(message usermq.UserOutboxMessage, groupIDPrefix strin
}
roomPayload := cloneJSONMap(basePayload)
roomPayload["recipient_user_id"] = strconv.FormatInt(application.Target.UserID, 10)
requesterRoomPayload := cloneJSONMap(basePayload)
requesterRoomPayload["recipient_user_id"] = strconv.FormatInt(application.Requester.UserID, 10)
return []CPDelivery{
{
AppCode: appCode,
@ -237,6 +240,20 @@ func deliveriesFromMessage(message usermq.UserOutboxMessage, groupIDPrefix strin
PayloadJSON: mustJSON(roomPayload),
CreatedAtMS: message.OccurredAtMS,
},
{
// 创建申请时 target 需要接收态按钮requester 也需要同一房间上下文里的等待态弹窗。
// notice_delivery_events 的主键包含 channel同一 event_id 不能复用 tencent_im_room
// 因此发起人房间通知用独立内部 channel发布边界仍走腾讯 IM 群自定义消息。
AppCode: appCode,
EventID: message.EventID,
EventType: message.EventType,
Channel: channelTencentIMRoomSender,
NoticeType: noticeTypeApplicationCreated,
TargetUserID: application.Requester.UserID,
GroupID: application.RoomID,
PayloadJSON: mustJSON(requesterRoomPayload),
CreatedAtMS: message.OccurredAtMS,
},
}, nil
case eventApplicationAccepted:
application, err := applicationFromObject(root)

View File

@ -11,7 +11,7 @@ import (
"hyapp/pkg/usermq"
)
func TestProcessApplicationCreatedPublishesC2CAndRoomIM(t *testing.T) {
func TestProcessApplicationCreatedPublishesC2CAndBothRoomIMs(t *testing.T) {
repo := &fakeRepository{}
publisher := &fakePublisher{}
service := New(Config{NodeID: "notice-test"}, repo, publisher)
@ -31,10 +31,18 @@ func TestProcessApplicationCreatedPublishesC2CAndRoomIM(t *testing.T) {
if len(publisher.userMessages) != 1 || publisher.userMessages[0].FromAccount != "1001" || publisher.userMessages[0].ToAccount != "1002" {
t.Fatalf("expected target c2c message, got %+v", publisher.userMessages)
}
if len(publisher.groupMessages) != 1 || publisher.groupMessages[0].GroupID != "room-100" {
t.Fatalf("expected room group message, got %+v", publisher.groupMessages)
if len(publisher.groupMessages) != 2 || publisher.groupMessages[0].GroupID != "room-100" || publisher.groupMessages[1].GroupID != "room-100" {
t.Fatalf("expected target and requester room group messages, got %+v", publisher.groupMessages)
}
if len(repo.delivered) != 2 || repo.delivered[0].Channel != channelTencentIMC2C || repo.delivered[1].Channel != channelTencentIMRoom {
targetRoomPayload := mustObject(string(publisher.groupMessages[0].PayloadJSON))
if targetRoomPayload["recipient_user_id"] != "1002" {
t.Fatalf("target room payload mismatch: %+v", targetRoomPayload)
}
requesterRoomPayload := mustObject(string(publisher.groupMessages[1].PayloadJSON))
if requesterRoomPayload["recipient_user_id"] != "1001" {
t.Fatalf("requester room payload mismatch: %+v", requesterRoomPayload)
}
if len(repo.delivered) != 3 || repo.delivered[0].Channel != channelTencentIMC2C || repo.delivered[1].Channel != channelTencentIMRoom || repo.delivered[2].Channel != channelTencentIMRoomSender {
t.Fatalf("delivery channels mismatch: %+v", repo.delivered)
}
}