Class: StreamChat::Moderation

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/stream-chat/moderation.rb

Overview

Moderation class provides all the endpoints related to moderation v2

Constant Summary collapse

MODERATION_ENTITY_TYPES =
T.let(
  {
    user: 'stream:user',
    message: 'stream:chat:v1:message',
    userprofile: 'stream:v1:user_profile'
  }.freeze,
  T::Hash[Symbol, String]
)

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Moderation



24
25
26
# File 'lib/stream-chat/moderation.rb', line 24

def initialize(client)
  @client = client
end

Instance Method Details

#add_custom_flags(entity_type, entity_id, moderation_payload, flags, entity_creator_id: '') ⇒ Object



270
271
272
273
274
275
276
277
278
# File 'lib/stream-chat/moderation.rb', line 270

def add_custom_flags(entity_type, entity_id, moderation_payload, flags, entity_creator_id: '')
  @client.post('api/v2/moderation/custom_check', data: {
                 entity_type: entity_type,
                 entity_id: entity_id,
                 entity_creator_id: entity_creator_id,
                 moderation_payload: moderation_payload,
                 flags: flags
               })
end

#add_custom_message_flags(message_id, flags) ⇒ Object



285
286
287
# File 'lib/stream-chat/moderation.rb', line 285

def add_custom_message_flags(message_id, flags)
  add_custom_flags(T.must(MODERATION_ENTITY_TYPES[:message]), message_id, {}, flags)
end

#check(entity_type, entity_id, moderation_payload, config_key, entity_creator_id: '', options: {}) ⇒ Object



251
252
253
254
255
256
257
258
259
260
# File 'lib/stream-chat/moderation.rb', line 251

def check(entity_type, entity_id, moderation_payload, config_key, entity_creator_id: '', options: {})
  @client.post('api/v2/moderation/check', data: {
                 entity_type: entity_type,
                 entity_id: entity_id,
                 entity_creator_id: entity_creator_id,
                 moderation_payload: moderation_payload,
                 config_key: config_key,
                 options: options
               })
end

#check_user_profile(user_id, profile) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/stream-chat/moderation.rb', line 50

def (user_id, profile)
  raise ArgumentError, 'Either username or image must be provided' if profile[:username].nil? && profile[:image].nil?

  moderation_payload = {}
  moderation_payload[:texts] = [profile[:username]] if profile[:username]
  moderation_payload[:images] = [profile[:image]] if profile[:image]

  check(
    T.must(MODERATION_ENTITY_TYPES[:userprofile]),
    user_id,
    moderation_payload,
    'user_profile:default',
    entity_creator_id: user_id,
    options: {
      force_sync: true,
      test_mode: true
    }
  )
end

#delete_config(key, data = {}) ⇒ Object



195
196
197
# File 'lib/stream-chat/moderation.rb', line 195

def delete_config(key, data = {})
  @client.delete("api/v2/moderation/config/#{key}", params: data)
end

#flag(entity_type, entity_id, reason, entity_creator_id: '', **options) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/stream-chat/moderation.rb', line 105

def flag(entity_type, entity_id, reason, entity_creator_id: '', **options)
  @client.post('api/v2/moderation/flag', data: {
                 entity_type: entity_type,
                 entity_id: entity_id,
                 entity_creator_id: entity_creator_id,
                 reason: reason,
                 **options
               })
end

#flag_message(message_id, reason, **options) ⇒ Object



90
91
92
# File 'lib/stream-chat/moderation.rb', line 90

def flag_message(message_id, reason, **options)
  flag(T.must(MODERATION_ENTITY_TYPES[:message]), message_id, reason, **options)
end

#flag_user(flagged_user_id, reason, **options) ⇒ Object



78
79
80
# File 'lib/stream-chat/moderation.rb', line 78

def flag_user(flagged_user_id, reason, **options)
  flag(T.must(MODERATION_ENTITY_TYPES[:user]), flagged_user_id, reason, **options)
end

#get_config(key, data = {}) ⇒ Object



185
186
187
# File 'lib/stream-chat/moderation.rb', line 185

def get_config(key, data = {})
  @client.get("api/v2/moderation/config/#{key}", params: data)
end

#get_user_moderation_report(user_id, **options) ⇒ Object



150
151
152
153
154
155
# File 'lib/stream-chat/moderation.rb', line 150

def get_user_moderation_report(user_id, **options)
  @client.get('api/v2/moderation/user_report', params: {
                user_id: user_id,
                **options
              })
end

#mute_user(target_id, **options) ⇒ Object



122
123
124
125
126
127
# File 'lib/stream-chat/moderation.rb', line 122

def mute_user(target_id, **options)
  @client.post('api/v2/moderation/mute', data: {
                 target_ids: [target_id],
                 **options
               })
end

#query_configs(filter_conditions, sort, **options) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/stream-chat/moderation.rb', line 205

def query_configs(filter_conditions, sort, **options)
  @client.post('api/v2/moderation/configs', data: {
                 filter: filter_conditions,
                 sort: sort,
                 **options
               })
end

#query_review_queue(filter_conditions = {}, sort = [], **options) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/stream-chat/moderation.rb', line 163

def query_review_queue(filter_conditions = {}, sort = [], **options)
  @client.post('api/v2/moderation/review_queue', data: {
                 filter: filter_conditions,
                 sort: StreamChat.get_sort_fields(sort),
                 **options
               })
end

#submit_action(action_type, item_id, **options) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/stream-chat/moderation.rb', line 219

def submit_action(action_type, item_id, **options)
  @client.post('api/v2/moderation/submit_action', data: {
                 action_type: action_type,
                 item_id: item_id,
                 **options
               })
end

#unmute_user(target_id, **options) ⇒ Object



135
136
137
138
139
140
# File 'lib/stream-chat/moderation.rb', line 135

def unmute_user(target_id, **options)
  @client.post('api/v2/moderation/unmute', data: {
                 target_ids: [target_id],
                 **options
               })
end

#upsert_config(config) ⇒ Object



175
176
177
# File 'lib/stream-chat/moderation.rb', line 175

def upsert_config(config)
  @client.post('api/v2/moderation/config', data: config)
end