Customize forward bundle titles
This commit is contained in:
@@ -5439,16 +5439,20 @@ func TestServeIMMessageForwardBundleSavesForwardBundle(t *testing.T) {
|
||||
oldSubs := store.Subs
|
||||
oldMessages := store.Messages
|
||||
oldUsers := store.Users
|
||||
oldTopics := store.Topics
|
||||
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
||||
messages := mock_store.NewMockMessagesPersistenceInterface(ctrl)
|
||||
users := mock_store.NewMockUsersPersistenceInterface(ctrl)
|
||||
topics := mock_store.NewMockTopicsPersistenceInterface(ctrl)
|
||||
store.Subs = subs
|
||||
store.Messages = messages
|
||||
store.Users = users
|
||||
store.Topics = topics
|
||||
t.Cleanup(func() {
|
||||
store.Subs = oldSubs
|
||||
store.Messages = oldMessages
|
||||
store.Users = oldUsers
|
||||
store.Topics = oldTopics
|
||||
})
|
||||
|
||||
subs.EXPECT().Get(types.TenantID(7), "grpTarget", types.Uid(42), false).Return(&types.Subscription{
|
||||
@@ -5481,6 +5485,7 @@ func TestServeIMMessageForwardBundleSavesForwardBundle(t *testing.T) {
|
||||
TenantID: 7,
|
||||
Public: types.KVMap{"display_name": "后端-potter", "avatar_file_id": "avatar-99"},
|
||||
}}, nil)
|
||||
topics.EXPECT().Get(types.TenantID(7), "grpSource").Return(&types.Topic{Public: map[string]any{"fn": "研发群"}}, nil)
|
||||
messages.EXPECT().Save(types.TenantID(7), gomock.Any(), gomock.Nil(), true).DoAndReturn(
|
||||
func(_ types.TenantID, msg *types.Message, _ []string, _ bool) (*types.MessageSaveResult, error) {
|
||||
if msg.Topic != "grpTarget" || msg.Head["x-im-type"] != "forward_bundle" {
|
||||
@@ -5490,6 +5495,9 @@ func TestServeIMMessageForwardBundleSavesForwardBundle(t *testing.T) {
|
||||
if content["bundle_id"] != "fbundle_bundle-1" || content["item_count"] != 1 {
|
||||
t.Fatalf("unexpected bundle content: %#v", content)
|
||||
}
|
||||
if content["title"] != "研发群的聊天记录" {
|
||||
t.Fatalf("unexpected bundle title: %#v", content)
|
||||
}
|
||||
bundleItems := content["items"].([]map[string]any)
|
||||
itemUser := bundleItems[0]["from_user"].(map[string]any)
|
||||
if itemUser["user_id"] != types.Uid(99).UserId() || itemUser["display_name"] != "后端-potter" || itemUser["avatar_file_id"] != "avatar-99" {
|
||||
@@ -5521,6 +5529,33 @@ func TestServeIMMessageForwardBundleSavesForwardBundle(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardBundleTitleUsesP2PUsers(t *testing.T) {
|
||||
uid1 := types.Uid(42)
|
||||
uid2 := types.Uid(99)
|
||||
title := forwardBundleTitle(types.TenantID(7), []string{uid1.P2PName(uid2)}, map[types.Uid]map[string]any{
|
||||
uid1: {"display_name": "Alice"},
|
||||
uid2: {"display_name": "Bob"},
|
||||
})
|
||||
if title != "Alice和Bob的聊天记录" {
|
||||
t.Fatalf("unexpected p2p title: %s", title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardBundleTitleUsesGroupName(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
oldTopics := store.Topics
|
||||
topics := mock_store.NewMockTopicsPersistenceInterface(ctrl)
|
||||
store.Topics = topics
|
||||
t.Cleanup(func() { store.Topics = oldTopics })
|
||||
|
||||
topics.EXPECT().Get(types.TenantID(7), "grpSource").Return(&types.Topic{Public: map[string]any{"fn": "项目群"}}, nil)
|
||||
title := forwardBundleTitle(types.TenantID(7), []string{"grpSource"}, nil)
|
||||
if title != "项目群的聊天记录" {
|
||||
t.Fatalf("unexpected group title: %s", title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMSecurityURLCheck(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
Reference in New Issue
Block a user