fix: include username in me endpoint

This commit is contained in:
richjohnrambo
2026-09-17 15:23:47 +08:00
parent ed976c76ff
commit c8d9146604
2 changed files with 45 additions and 3 deletions
+18 -3
View File
@@ -3247,8 +3247,14 @@ func serveIMMe(wrt http.ResponseWriter, req *http.Request) {
writeIMRelationError(wrt, req, err)
return
}
account, err := currentUserAccountPayload(principal.TenantID, principal.Uid)
if err != nil {
writeIMRelationError(wrt, req, err)
return
}
writeIMSuccess(wrt, req, map[string]any{
"user_id": principal.Uid.UserId(),
"username": account["username"],
"profile": userProfilePayload10(profile),
"profile_version": profile.Version,
"realname": map[string]any{"status": "unknown"},
@@ -10093,13 +10099,22 @@ func userProfilePayload10(profile *types.UserProfile) map[string]any {
}
func currentUserProfilePayload(tenantID types.TenantID, uid types.Uid, profile *types.UserProfile) (map[string]any, error) {
user, err := store.Users.Get(tenantID, uid)
account, err := currentUserAccountPayload(tenantID, uid)
if err != nil {
return nil, err
}
data := userProfilePayload10(profile)
data["phone_mask"] = ""
data["username"] = ""
data["phone_mask"] = account["phone_mask"]
data["username"] = account["username"]
return data, nil
}
func currentUserAccountPayload(tenantID types.TenantID, uid types.Uid) (map[string]any, error) {
user, err := store.Users.Get(tenantID, uid)
if err != nil {
return nil, err
}
data := map[string]any{"phone_mask": "", "username": ""}
if user != nil {
data["phone_mask"] = maskIMProfilePhone(user.Phone)
data["username"] = user.Username