fix group invitation notifications
This commit is contained in:
+21
-7
@@ -5381,13 +5381,7 @@ func serveIMGroupInvitations(wrt http.ResponseWriter, req *http.Request, topic s
|
||||
if inv.JoinRequestID != "" {
|
||||
item["join_request_id"] = inv.JoinRequestID
|
||||
}
|
||||
if imReliableHTTPEventsEnabled(req) {
|
||||
publishIMConversationSystemNotice(principal.TenantID, principal.Uid.P2PName(uid),
|
||||
"system_action", "group_invitation_created", "邀请你加入群聊。",
|
||||
[]imSystemMessageActor{{UserID: principal.Uid.UserId(), Click: map[string]any{"type": "user_profile", "target_id": principal.Uid.UserId()}}},
|
||||
[]imSystemMessageAction{{Type: "group_invitation_accept", Label: "立即加入", TargetID: inv.InvitationID}},
|
||||
map[string]any{"invitation_id": inv.InvitationID, "topic": topic, "message": inv.Message})
|
||||
}
|
||||
publishIMGroupInvitationNotification(principal.TenantID, inv)
|
||||
results = append(results, item)
|
||||
}
|
||||
dispatchIMGroupEvents(principal.TenantID)
|
||||
@@ -11032,6 +11026,26 @@ func broadcastIMConversationSystemMessage(tenantID types.TenantID, msg *types.Me
|
||||
broadcastHTTPForwardPresence(tenantID, msg, timestamp)
|
||||
}
|
||||
|
||||
func publishIMGroupInvitationNotification(tenantID types.TenantID, inv *types.GroupInvitation) {
|
||||
if tenantID == types.ZeroTenantID || inv == nil || inv.TargetUserID.IsZero() || store.Security == nil {
|
||||
return
|
||||
}
|
||||
eventID := stableIMEventID("group-invitation", inv.InvitationID, inv.TargetUserID.UserId(), "created")
|
||||
action := types.KVMap{
|
||||
"type": "group_invitation_accept",
|
||||
"invitation_id": inv.InvitationID,
|
||||
"topic": inv.Topic,
|
||||
"inviter_id": inv.InviterUserID.UserId(),
|
||||
}
|
||||
if inv.Message != "" {
|
||||
action["message"] = inv.Message
|
||||
}
|
||||
if err := createIMSystemNotification(tenantID, inv.TargetUserID, eventID, "group.invitation.created",
|
||||
"群聊邀请", "邀请你加入群聊。", action); err != nil {
|
||||
logs.Warn.Printf("group invitation: create notification invitation=%s target=%s: %v", inv.InvitationID, inv.TargetUserID.UserId(), err)
|
||||
}
|
||||
}
|
||||
|
||||
func deliverIMConversationSystemMessageToP2PSessions(tenantID types.TenantID, msg *types.Message, out *ServerComMessage) {
|
||||
if globals.sessionStore == nil || msg == nil || out == nil || out.Data == nil {
|
||||
return
|
||||
|
||||
+19
-1
@@ -312,6 +312,7 @@ type testMailboxStore struct {
|
||||
|
||||
type testUserSecurityStore struct {
|
||||
unreadByPrefix map[string]int
|
||||
notifications []types.SystemNotification
|
||||
}
|
||||
|
||||
type testProfilesStore struct {
|
||||
@@ -1003,7 +1004,10 @@ func (s *testUserSecurityStore) SetYouthMode(_ types.TenantID, uid types.Uid, en
|
||||
return &types.YouthModeSettings{UserID: uid, Enabled: enabled, PolicyVersion: policyVersion, UpdatedAt: now}, nil
|
||||
}
|
||||
|
||||
func (s *testUserSecurityStore) CreateSystemNotification(_ types.TenantID, _ *types.SystemNotification) error {
|
||||
func (s *testUserSecurityStore) CreateSystemNotification(_ types.TenantID, notification *types.SystemNotification) error {
|
||||
if notification != nil {
|
||||
s.notifications = append(s.notifications, *notification)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4704,13 +4708,17 @@ func TestServeIMGroupInvitationAddsNonMember(t *testing.T) {
|
||||
mockStore.EXPECT().GetUidString().Return("test")
|
||||
oldSubs := store.Subs
|
||||
oldGroupBusiness := store.GroupBusiness
|
||||
oldSecurity := store.Security
|
||||
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
||||
groupStore := &testGroupBusinessStore{}
|
||||
securityStore := &testUserSecurityStore{}
|
||||
store.Subs = subs
|
||||
store.GroupBusiness = groupStore
|
||||
store.Security = securityStore
|
||||
defer func() {
|
||||
store.Subs = oldSubs
|
||||
store.GroupBusiness = oldGroupBusiness
|
||||
store.Security = oldSecurity
|
||||
}()
|
||||
owner := types.Uid(42)
|
||||
target := types.Uid(43)
|
||||
@@ -4737,6 +4745,16 @@ func TestServeIMGroupInvitationAddsNonMember(t *testing.T) {
|
||||
if len(groupStore.invitations) != 1 || groupStore.invitations[0].TargetUserID != target || groupStore.invitations[0].InvitationID != "ginv_test" {
|
||||
t.Fatalf("invitation was not persisted: %#v", groupStore.invitations)
|
||||
}
|
||||
if len(securityStore.notifications) != 1 {
|
||||
t.Fatalf("expected one target notification, got %#v", securityStore.notifications)
|
||||
}
|
||||
notification := securityStore.notifications[0]
|
||||
if notification.UserID != target || notification.EventType != "group.invitation.created" {
|
||||
t.Fatalf("unexpected notification target/type: %#v", notification)
|
||||
}
|
||||
if notification.Action["type"] != "group_invitation_accept" || notification.Action["invitation_id"] != "ginv_test" || notification.Action["topic"] != "grpAlpha" {
|
||||
t.Fatalf("unexpected notification action: %#v", notification.Action)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMGroupInvitationCreatesApprovalRequest(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user