@@ -14,7 +14,8 @@ class Moderation
1414 MODERATION_ENTITY_TYPES = T . let (
1515 {
1616 user : 'stream:user' ,
17- message : 'stream:chat:v1:message'
17+ message : 'stream:chat:v1:message' ,
18+ userprofile : 'stream:v1:user_profile'
1819 } . freeze ,
1920 T ::Hash [ Symbol , String ]
2021 )
@@ -24,6 +25,48 @@ def initialize(client)
2425 @client = client
2526 end
2627
28+ # Experimental: Check user profile
29+ #
30+ # Warning: This is an experimental feature and the API is subject to change.
31+ #
32+ # This function is used to check a user profile for moderation.
33+ # This will not create any review queue items for the user profile.
34+ # You can just use this to check whether to allow a certain user profile to be created or not.
35+ #
36+ # @param [string] user_id User ID to be checked
37+ # @param [Hash] profile Profile data to be checked
38+ # @option profile [String] :username Username to be checked
39+ # @option profile [String] :image Image URL to be checked
40+ # @return [StreamChat::StreamResponse]
41+ #
42+ # example:
43+ # client.moderation.check_user_profile('user-id', {username: 'bad_username', image: 'https://example.com/profile.jpg'})
44+ sig do
45+ params (
46+ user_id : String ,
47+ profile : T ::Hash [ Symbol , T . nilable ( String ) ]
48+ ) . returns ( StreamChat ::StreamResponse )
49+ end
50+ def check_user_profile ( user_id , profile )
51+ raise ArgumentError , 'Either username or image must be provided' if profile [ :username ] . nil? && profile [ :image ] . nil?
52+
53+ moderation_payload = { }
54+ moderation_payload [ :texts ] = [ profile [ :username ] ] if profile [ :username ]
55+ moderation_payload [ :images ] = [ profile [ :image ] ] if profile [ :image ]
56+
57+ check (
58+ T . must ( MODERATION_ENTITY_TYPES [ :userprofile ] ) ,
59+ user_id ,
60+ moderation_payload ,
61+ 'user_profile:default' ,
62+ entity_creator_id : user_id ,
63+ options : {
64+ force_sync : true ,
65+ test_mode : true
66+ }
67+ )
68+ end
69+
2770 # Flags a user with a reason
2871 #
2972 # @param [string] flagged_user_id User ID to be flagged
0 commit comments