feat: expose account fields in user profiles
This commit is contained in:
+43
-2
@@ -3191,7 +3191,12 @@ func serveIMMeProfile(wrt http.ResponseWriter, req *http.Request) {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, userProfilePayload10(profile))
|
||||
payload, err := currentUserProfilePayload(principal.TenantID, principal.Uid, profile)
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, payload)
|
||||
case http.MethodPatch:
|
||||
var body struct {
|
||||
AvatarFileID *string `json:"avatar_file_id"`
|
||||
@@ -3240,7 +3245,12 @@ func serveIMMeProfile(wrt http.ResponseWriter, req *http.Request) {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, userProfilePayload10(profile))
|
||||
payload, err := currentUserProfilePayload(principal.TenantID, principal.Uid, profile)
|
||||
if err != nil {
|
||||
writeIMRelationError(wrt, req, err)
|
||||
return
|
||||
}
|
||||
writeIMSuccess(wrt, req, payload)
|
||||
default:
|
||||
writeIMError(wrt, req, http.StatusMethodNotAllowed, 30002, imReasonMethodNotAllowed, "method not allowed", nil)
|
||||
}
|
||||
@@ -9799,6 +9809,21 @@ func userProfilePayload10(profile *types.UserProfile) map[string]any {
|
||||
return data
|
||||
}
|
||||
|
||||
func currentUserProfilePayload(tenantID types.TenantID, uid types.Uid, profile *types.UserProfile) (map[string]any, error) {
|
||||
user, err := store.Users.Get(tenantID, uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data := userProfilePayload10(profile)
|
||||
data["phone_mask"] = ""
|
||||
data["username"] = ""
|
||||
if user != nil {
|
||||
data["phone_mask"] = maskIMProfilePhone(user.Phone)
|
||||
data["username"] = user.Username
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func validIMSecurityChallengeScene(scene string) bool {
|
||||
switch strings.TrimSpace(scene) {
|
||||
case "set_independent_password", "enable_youth_mode", "close_youth_mode", "reset_independent_password",
|
||||
@@ -10280,6 +10305,7 @@ func blockListItemPayload(item types.BlockListItem) map[string]any {
|
||||
|
||||
func userProfilePayload(user *types.User, ctx *types.RelationshipContext) map[string]any {
|
||||
data := userSummaryPayload(user, ctx.Remark)
|
||||
data["username"] = user.Username
|
||||
data["relationship"] = ctx.Relationship
|
||||
data["topic"] = ctx.Topic
|
||||
data["capabilities"] = map[string]any{
|
||||
@@ -10303,6 +10329,7 @@ func userProfilePayload(user *types.User, ctx *types.RelationshipContext) map[st
|
||||
|
||||
func blockedUserProfilePayload(user *types.User, ctx *types.RelationshipContext) map[string]any {
|
||||
data := userSummaryPayload(user, ctx.Remark)
|
||||
data["username"] = user.Username
|
||||
data["relationship"] = ctx.Relationship
|
||||
data["topic"] = ctx.Topic
|
||||
data["capabilities"] = map[string]any{
|
||||
@@ -11365,6 +11392,20 @@ func maskIMPhone(phone string) string {
|
||||
return phone[:4] + "****" + phone[len(phone)-3:]
|
||||
}
|
||||
|
||||
func maskIMProfilePhone(phone string) string {
|
||||
phone = strings.TrimSpace(phone)
|
||||
if strings.HasPrefix(phone, "+86") {
|
||||
phone = strings.TrimPrefix(phone, "+86")
|
||||
}
|
||||
if phone == "" {
|
||||
return ""
|
||||
}
|
||||
if len(phone) <= 7 {
|
||||
return phone
|
||||
}
|
||||
return phone[:3] + "****" + phone[len(phone)-4:]
|
||||
}
|
||||
|
||||
func randomIMNumericCode(length int) (string, error) {
|
||||
max := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(length)), nil)
|
||||
n, err := rand.Int(rand.Reader, max)
|
||||
|
||||
Reference in New Issue
Block a user