refactor: retire legacy tinode database routing
This commit is contained in:
+38
-1
@@ -3816,7 +3816,7 @@ func serveIMFriendRequestCreate(wrt http.ResponseWriter, req *http.Request) {
|
||||
source := strings.TrimSpace(body.Source)
|
||||
sourceTopic := strings.TrimSpace(body.SourceTopic)
|
||||
switch source {
|
||||
case "search", "qr":
|
||||
case "search", "qr", "profile_card":
|
||||
if sourceTopic != "" {
|
||||
writeIMError(wrt, req, http.StatusBadRequest, 30000, imReasonMalformedRequest, "source_topic is only valid for group source", nil)
|
||||
return
|
||||
@@ -6037,6 +6037,10 @@ func serveIMUserProfile(wrt http.ResponseWriter, req *http.Request, identifier s
|
||||
writeIMSuccess(wrt, req, blockedUserProfilePayload(user, ctx))
|
||||
return
|
||||
}
|
||||
if ctx.Relationship == types.RelationshipNone {
|
||||
writeIMSuccess(wrt, req, limitedUserProfilePayload(user, ctx, privacy))
|
||||
return
|
||||
}
|
||||
writeIMError(wrt, req, http.StatusForbidden, 30005, imReasonPermissionDenied, "profile is private", nil)
|
||||
return
|
||||
}
|
||||
@@ -9030,6 +9034,39 @@ func blockedUserProfilePayload(user *types.User, ctx *types.RelationshipContext)
|
||||
return data
|
||||
}
|
||||
|
||||
func limitedUserProfilePayload(user *types.User, ctx *types.RelationshipContext, privacy *types.UserPrivacySettings) map[string]any {
|
||||
data := userSummaryPayload(user, "")
|
||||
data["username"] = user.Username
|
||||
if original := userOriginalDisplayName(user); original != "" {
|
||||
data["profile_display_name"] = original
|
||||
data["original_display_name"] = original
|
||||
}
|
||||
data["relationship"] = ctx.Relationship
|
||||
data["topic"] = ctx.Topic
|
||||
data["capabilities"] = map[string]any{
|
||||
"can_send": false,
|
||||
"can_call": false,
|
||||
"can_add_friend": ctx.Relationship == types.RelationshipNone && imPrivacyAllowsAdd(privacy, "profile_card"),
|
||||
}
|
||||
if ctx.RequestID != "" {
|
||||
data["request_id"] = ctx.RequestID
|
||||
}
|
||||
if public, ok := user.Public.(map[string]any); ok {
|
||||
copyLimitedProfileFields(data, public)
|
||||
} else if public, ok := user.Public.(types.KVMap); ok {
|
||||
copyLimitedProfileFields(data, map[string]any(public))
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func copyLimitedProfileFields(data map[string]any, public map[string]any) {
|
||||
for _, key := range []string{"nickname", "public_account"} {
|
||||
if value, ok := public[key]; ok {
|
||||
data[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func copyOptionalProfileFields(data map[string]any, public map[string]any) {
|
||||
for _, key := range []string{"nickname", "gender", "region", "public_account", "signature"} {
|
||||
if value, ok := public[key]; ok {
|
||||
|
||||
Reference in New Issue
Block a user