fix: include username in me endpoint
This commit is contained in:
+18
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user