fix: 统一用户资料投影并放开头像访问

This commit is contained in:
richjohnrambo
2026-09-08 15:26:05 +08:00
parent 62e989487b
commit 06945a4050
8 changed files with 250 additions and 57 deletions
+79 -6
View File
@@ -2834,7 +2834,66 @@ func (profileMapper) Update(tenantID types.TenantID, uid types.Uid, patch types.
if err != nil {
return nil, err
}
return tenantAdp.TenantUserProfileUpdate(tenantID, uid, patch)
profile, err := tenantAdp.TenantUserProfileUpdate(tenantID, uid, patch)
if err != nil {
return nil, err
}
refreshUserProfileProjections(tenantID, uid, profile)
return profile, nil
}
func refreshUserProfileProjections(tenantID types.TenantID, uid types.Uid, profile *types.UserProfile) {
_ = DeleteCachedObject(tenantID, cacheNamespaceUser, uid.String())
if profile == nil {
return
}
public := userProfilePublicProjection(profile)
cursor := ""
for {
items, nextCursor, err := Relations.ListFriends(tenantID, uid, "", "", cursor, 100)
if err != nil {
logs.Warn.Printf("profile %s: refresh friend subscription projections failed: %v", uid, err)
return
}
for _, item := range items {
if item.Friendship.Topic == "" || item.Friendship.PeerID.IsZero() {
continue
}
if err := Subs.Update(tenantID, item.Friendship.Topic, item.Friendship.PeerID, map[string]any{"Public": public}); err != nil {
logs.Warn.Printf("profile %s: refresh subscription %s/%s public failed: %v", uid, item.Friendship.Topic, item.Friendship.PeerID, err)
}
}
if nextCursor == "" {
return
}
cursor = nextCursor
}
}
func userProfilePublicProjection(profile *types.UserProfile) map[string]any {
public := make(map[string]any)
nickname := strings.TrimSpace(profile.Nickname)
if nickname != "" {
for _, key := range []string{"display_name", "nickname", "fn", "name"} {
public[key] = nickname
}
}
if value := strings.TrimSpace(profile.AvatarFileID); value != "" {
public["avatar_file_id"] = value
}
if value := strings.TrimSpace(profile.Signature); value != "" {
public["signature"] = value
}
if value := strings.TrimSpace(profile.Gender); value != "" {
public["gender"] = value
}
if value := strings.TrimSpace(profile.Region); value != "" {
public["region"] = value
}
if value := strings.TrimSpace(profile.PublicAccount); value != "" {
public["public_account"] = value
}
return public
}
func (profileMapper) GetPrivacy(tenantID types.TenantID, uid types.Uid) (*types.UserPrivacySettings, error) {
@@ -4155,19 +4214,33 @@ func (fileMapper) DeleteUnused(tenantID types.TenantID, olderThan time.Time, lim
// LinkAttachments connects earlier uploaded attachments to a message or topic to prevent it
// from being garbage collected.
func (fileMapper) LinkAttachments(tenantID types.TenantID, topic string, msgId types.Uid, attachments []string) error {
tenantAdp, err := tenantBusinessAdapter(tenantID)
if err != nil {
return err
}
// Convert attachment URLs to file IDs.
var fids []string
for _, url := range attachments {
if fid := mediaHandler.GetIdFromUrl(url); !fid.IsZero() {
raw := strings.TrimSpace(url)
if raw == "" {
continue
}
if mediaHandler != nil {
if fid := mediaHandler.GetIdFromUrl(raw); !fid.IsZero() {
fids = append(fids, fid.String())
continue
}
}
if fid := media.GetIdFromUrl(raw, ""); !fid.IsZero() {
fids = append(fids, fid.String())
continue
}
if fid := types.ParseUid(raw); !fid.IsZero() {
fids = append(fids, fid.String())
}
}
if len(fids) > 0 {
tenantAdp, err := tenantBusinessAdapter(tenantID)
if err != nil {
return err
}
userId := types.ZeroUid
if topic != "" && types.GetTopicCat(topic) == types.TopicCatMe {
userId = types.ParseUserId(topic)