Customize forward bundle titles
This commit is contained in:
+73
-5
@@ -9439,7 +9439,7 @@ func buildForwardBundle(principal *imPrincipal, sources []struct {
|
||||
if len(failures) > 0 {
|
||||
return nil, failures
|
||||
}
|
||||
userSummaries := forwardMessageUserSummaries(principal.TenantID, sourceMessages)
|
||||
userSummaries := forwardMessageUserSummaries(principal.TenantID, sourceMessages, forwardBundleTitleUIDs(sourceTopics)...)
|
||||
items := make([]map[string]any, 0, len(sourceMessages))
|
||||
preview := make([]map[string]any, 0, min(len(sourceMessages), 3))
|
||||
sourceRefs := make([]map[string]any, 0, len(sourceMessages))
|
||||
@@ -9467,7 +9467,7 @@ func buildForwardBundle(principal *imPrincipal, sources []struct {
|
||||
bundleID := "fbundle_" + store.Store.GetUidString()
|
||||
return map[string]any{
|
||||
"bundle_id": bundleID,
|
||||
"title": "聊天记录",
|
||||
"title": forwardBundleTitle(principal.TenantID, sourceTopics, userSummaries),
|
||||
"item_count": len(items),
|
||||
"preview": preview,
|
||||
"items": items,
|
||||
@@ -9477,12 +9477,80 @@ func buildForwardBundle(principal *imPrincipal, sources []struct {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func forwardMessageUserSummaries(tenantID types.TenantID, messages []*types.Message) map[types.Uid]map[string]any {
|
||||
if store.Users == nil || len(messages) == 0 {
|
||||
func forwardBundleTitleUIDs(sourceTopics []string) []types.Uid {
|
||||
seen := make(map[types.Uid]bool)
|
||||
uids := make([]types.Uid, 0, 2)
|
||||
for _, topic := range sourceTopics {
|
||||
if types.GetTopicCat(topic) != types.TopicCatP2P {
|
||||
continue
|
||||
}
|
||||
uid1, uid2, err := types.ParseP2P(topic)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, uid := range []types.Uid{uid1, uid2} {
|
||||
if uid.IsZero() || seen[uid] {
|
||||
continue
|
||||
}
|
||||
seen[uid] = true
|
||||
uids = append(uids, uid)
|
||||
}
|
||||
}
|
||||
return uids
|
||||
}
|
||||
|
||||
func forwardBundleTitle(tenantID types.TenantID, sourceTopics []string, userSummaries map[types.Uid]map[string]any) string {
|
||||
if len(sourceTopics) == 0 {
|
||||
return "聊天记录"
|
||||
}
|
||||
topic := sourceTopics[0]
|
||||
switch types.GetTopicCat(topic) {
|
||||
case types.TopicCatP2P:
|
||||
uid1, uid2, err := types.ParseP2P(topic)
|
||||
if err != nil {
|
||||
return "聊天记录"
|
||||
}
|
||||
return forwardBundleDisplayName(uid1, userSummaries) + "和" + forwardBundleDisplayName(uid2, userSummaries) + "的聊天记录"
|
||||
case types.TopicCatGrp:
|
||||
groupName := topic
|
||||
if store.Topics != nil {
|
||||
if group, err := store.Topics.Get(tenantID, topic); err == nil && group != nil {
|
||||
groupName = imDisplayNameFromPublic(group.Public, topic)
|
||||
} else if err != nil {
|
||||
logs.Warn.Printf("im message forward: failed to load group title topic=%s: %v", topic, err)
|
||||
}
|
||||
}
|
||||
if strings.HasSuffix(groupName, "群") {
|
||||
return groupName + "的聊天记录"
|
||||
}
|
||||
return groupName + "群的聊天记录"
|
||||
default:
|
||||
return "聊天记录"
|
||||
}
|
||||
}
|
||||
|
||||
func forwardBundleDisplayName(uid types.Uid, summaries map[types.Uid]map[string]any) string {
|
||||
if summary := forwardMessageUserSummary(uid.String(), summaries); summary != nil {
|
||||
if name := strings.TrimSpace(fmt.Sprint(summary["display_name"])); name != "" {
|
||||
return name
|
||||
}
|
||||
}
|
||||
return uid.UserId()
|
||||
}
|
||||
|
||||
func forwardMessageUserSummaries(tenantID types.TenantID, messages []*types.Message, extraUIDs ...types.Uid) map[types.Uid]map[string]any {
|
||||
if store.Users == nil {
|
||||
return nil
|
||||
}
|
||||
seen := make(map[types.Uid]bool)
|
||||
uids := make([]types.Uid, 0, len(messages))
|
||||
uids := make([]types.Uid, 0, len(messages)+len(extraUIDs))
|
||||
for _, uid := range extraUIDs {
|
||||
if uid.IsZero() || seen[uid] {
|
||||
continue
|
||||
}
|
||||
seen[uid] = true
|
||||
uids = append(uids, uid)
|
||||
}
|
||||
for _, msg := range messages {
|
||||
if msg == nil {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user