stream-chat-ruby 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/stream-chat/client.rb +5 -0
- data/lib/stream-chat/moderation.rb +246 -0
- data/lib/stream-chat/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a82d5e57e78d2f495ea24218a4f5320e1d3e07d135ff6581ee3f6e0457b82f9
|
4
|
+
data.tar.gz: 328487e5aa840033e84f189d8e02d101b71db31a775d6af6732b10991f8f8339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b90f95c75dc4945afc521e05859181146a5d697026574363e0973a74dbe2409067ee51efac819c61c2922c81b8d19fc1b942cecde6ad7b68380f798e016c0763
|
7
|
+
data.tar.gz: e93e5222e8746762c77a2d55d6b8544d9ae1e0be7441c083f334a0e26cc7a75f51fdd16a4e99d37067c256dd9f43de101c25c03b5323c7d5f8452621526b210f
|
data/lib/stream-chat/client.rb
CHANGED
@@ -14,6 +14,7 @@ require 'stream-chat/stream_response'
|
|
14
14
|
require 'stream-chat/version'
|
15
15
|
require 'stream-chat/util'
|
16
16
|
require 'stream-chat/types'
|
17
|
+
require 'stream-chat/moderation'
|
17
18
|
|
18
19
|
module StreamChat
|
19
20
|
DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
|
@@ -35,6 +36,9 @@ module StreamChat
|
|
35
36
|
sig { returns(Faraday::Connection) }
|
36
37
|
attr_reader :conn
|
37
38
|
|
39
|
+
sig { returns(Moderation) }
|
40
|
+
attr_reader :moderation
|
41
|
+
|
38
42
|
# initializes a Stream Chat API Client
|
39
43
|
#
|
40
44
|
# @param [string] api_key your application api_key
|
@@ -64,6 +68,7 @@ module StreamChat
|
|
64
68
|
end
|
65
69
|
end
|
66
70
|
@conn = T.let(conn, Faraday::Connection)
|
71
|
+
@moderation = T.let(Moderation.new(self), Moderation)
|
67
72
|
end
|
68
73
|
|
69
74
|
# initializes a Stream Chat API Client from STREAM_KEY and STREAM_SECRET
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'stream-chat/client'
|
5
|
+
require 'stream-chat/errors'
|
6
|
+
require 'stream-chat/util'
|
7
|
+
require 'stream-chat/types'
|
8
|
+
|
9
|
+
module StreamChat
|
10
|
+
# Moderation class provides all the endpoints related to moderation v2
|
11
|
+
class Moderation
|
12
|
+
extend T::Sig
|
13
|
+
|
14
|
+
MODERATION_ENTITY_TYPES = T.let(
|
15
|
+
{
|
16
|
+
user: 'stream:user',
|
17
|
+
message: 'stream:chat:v1:message'
|
18
|
+
}.freeze,
|
19
|
+
T::Hash[Symbol, String]
|
20
|
+
)
|
21
|
+
|
22
|
+
sig { params(client: Client).void }
|
23
|
+
def initialize(client)
|
24
|
+
@client = client
|
25
|
+
end
|
26
|
+
|
27
|
+
# Flags a user with a reason
|
28
|
+
#
|
29
|
+
# @param [string] flagged_user_id User ID to be flagged
|
30
|
+
# @param [string] reason Reason for flagging the user
|
31
|
+
# @param [Hash] options Additional options for flagging the user
|
32
|
+
# @option options [String] :user_id User ID of the user who is flagging the target user
|
33
|
+
# @option options [Hash] :custom Additional data to be stored with the flag
|
34
|
+
sig { params(flagged_user_id: String, reason: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
35
|
+
def flag_user(flagged_user_id, reason, **options)
|
36
|
+
flag(T.must(MODERATION_ENTITY_TYPES[:user]), flagged_user_id, reason, **options)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Flags a message with a reason
|
40
|
+
#
|
41
|
+
# @param [string] message_id Message ID to be flagged
|
42
|
+
# @param [string] reason Reason for flagging the message
|
43
|
+
# @param [Hash] options Additional options for flagging the message
|
44
|
+
# @option options [String] :user_id User ID of the user who is flagging the target message
|
45
|
+
# @option options [Hash] :custom Additional data to be stored with the flag
|
46
|
+
sig { params(message_id: String, reason: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
47
|
+
def flag_message(message_id, reason, **options)
|
48
|
+
flag(T.must(MODERATION_ENTITY_TYPES[:message]), message_id, reason, **options)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Flags an entity with a reason
|
52
|
+
#
|
53
|
+
# @param [string] entity_type Entity type to be flagged
|
54
|
+
# @param [string] entity_id Entity ID to be flagged
|
55
|
+
# @param [string] reason Reason for flagging the entity
|
56
|
+
# @param [string] entity_creator_id User ID of the entity creator (optional)
|
57
|
+
# @param [Hash] options Additional options for flagging the entity
|
58
|
+
# @option options [String] :user_id User ID of the user who is flagging the target entity
|
59
|
+
# @option options [Hash] :moderation_payload Content to be flagged
|
60
|
+
# @option options [Hash] :custom Additional data to be stored with the flag
|
61
|
+
sig { params(entity_type: String, entity_id: String, reason: String, entity_creator_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
62
|
+
def flag(entity_type, entity_id, reason, entity_creator_id: '', **options)
|
63
|
+
@client.post('api/v2/moderation/flag', data: {
|
64
|
+
entity_type: entity_type,
|
65
|
+
entity_id: entity_id,
|
66
|
+
entity_creator_id: entity_creator_id,
|
67
|
+
reason: reason,
|
68
|
+
**options
|
69
|
+
})
|
70
|
+
end
|
71
|
+
|
72
|
+
# Mutes a user
|
73
|
+
#
|
74
|
+
# @param [string] target_id User ID to be muted
|
75
|
+
# @param [Hash] options Additional options for muting the user
|
76
|
+
# @option options [String] :user_id User ID of the user who is muting the target user
|
77
|
+
# @option options [Integer] :timeout Timeout for the mute in minutes
|
78
|
+
sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
79
|
+
def mute_user(target_id, **options)
|
80
|
+
@client.post('api/v2/moderation/mute', data: {
|
81
|
+
target_ids: [target_id],
|
82
|
+
**options
|
83
|
+
})
|
84
|
+
end
|
85
|
+
|
86
|
+
# Unmutes a user
|
87
|
+
#
|
88
|
+
# @param [string] target_id User ID to be unmuted
|
89
|
+
# @param [Hash] options Additional options for unmuting the user
|
90
|
+
# @option options [String] :user_id User ID of the user who is unmuting the target user
|
91
|
+
sig { params(target_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
92
|
+
def unmute_user(target_id, **options)
|
93
|
+
@client.post('api/v2/moderation/unmute', data: {
|
94
|
+
target_ids: [target_id],
|
95
|
+
**options
|
96
|
+
})
|
97
|
+
end
|
98
|
+
|
99
|
+
# Gets moderation report for a user
|
100
|
+
#
|
101
|
+
# @param [string] user_id User ID for which moderation report is to be fetched
|
102
|
+
# @param [Hash] options Additional options for fetching the moderation report
|
103
|
+
# @option options [Boolean] :create_user_if_not_exists Create user if not exists
|
104
|
+
# @option options [Boolean] :include_user_blocks Include user blocks
|
105
|
+
# @option options [Boolean] :include_user_mutes Include user mutes
|
106
|
+
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
107
|
+
def get_user_moderation_report(user_id, **options)
|
108
|
+
@client.get('api/v2/moderation/user_report', params: {
|
109
|
+
user_id: user_id,
|
110
|
+
**options
|
111
|
+
})
|
112
|
+
end
|
113
|
+
|
114
|
+
# Queries review queue
|
115
|
+
#
|
116
|
+
# @param [Hash] filter_conditions Filter conditions for querying review queue
|
117
|
+
# @param [Array] sort Sort conditions for querying review queue
|
118
|
+
# @param [Hash] options Pagination options for querying review queue
|
119
|
+
sig { params(filter_conditions: T.untyped, sort: T.untyped, options: T.untyped).returns(StreamChat::StreamResponse) }
|
120
|
+
def query_review_queue(filter_conditions = {}, sort = [], **options)
|
121
|
+
@client.post('api/v2/moderation/review_queue', data: {
|
122
|
+
filter: filter_conditions,
|
123
|
+
sort: StreamChat.get_sort_fields(sort),
|
124
|
+
**options
|
125
|
+
})
|
126
|
+
end
|
127
|
+
|
128
|
+
# Upserts moderation config
|
129
|
+
#
|
130
|
+
# @param [Hash] config Moderation config to be upserted
|
131
|
+
sig { params(config: T.untyped).returns(StreamChat::StreamResponse) }
|
132
|
+
def upsert_config(config)
|
133
|
+
@client.post('api/v2/moderation/config', data: config)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Gets moderation config
|
137
|
+
#
|
138
|
+
# @param [string] key Key for which moderation config is to be fetched
|
139
|
+
# @param [Hash] data Additional data
|
140
|
+
# @option data [String] :team Team name
|
141
|
+
sig { params(key: String, data: T.untyped).returns(StreamChat::StreamResponse) }
|
142
|
+
def get_config(key, data = {})
|
143
|
+
@client.get("api/v2/moderation/config/#{key}", params: data)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Deletes moderation config
|
147
|
+
#
|
148
|
+
# @param [string] key Key for which moderation config is to be deleted
|
149
|
+
# @param [Hash] data Additional data
|
150
|
+
# @option data [String] :team Team name
|
151
|
+
sig { params(key: String, data: T.untyped).returns(StreamChat::StreamResponse) }
|
152
|
+
def delete_config(key, data = {})
|
153
|
+
@client.delete("api/v2/moderation/config/#{key}", params: data)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Queries moderation configs
|
157
|
+
#
|
158
|
+
# @param [Hash] filter_conditions Filter conditions for querying moderation configs
|
159
|
+
# @param [Array] sort Sort conditions for querying moderation configs
|
160
|
+
# @param [Hash] options Additional options for querying moderation configs
|
161
|
+
sig { params(filter_conditions: T.untyped, sort: T.untyped, options: T.untyped).returns(StreamChat::StreamResponse) }
|
162
|
+
def query_configs(filter_conditions, sort, **options)
|
163
|
+
@client.post('api/v2/moderation/configs', data: {
|
164
|
+
filter: filter_conditions,
|
165
|
+
sort: sort,
|
166
|
+
**options
|
167
|
+
})
|
168
|
+
end
|
169
|
+
|
170
|
+
# Submits a moderation action
|
171
|
+
#
|
172
|
+
# @param [string] action_type Type of action to submit
|
173
|
+
# @param [string] item_id ID of the item to submit action for
|
174
|
+
# @param [Hash] options Additional options for submitting the action
|
175
|
+
sig { params(action_type: String, item_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
176
|
+
def submit_action(action_type, item_id, **options)
|
177
|
+
@client.post('api/v2/moderation/submit_action', data: {
|
178
|
+
action_type: action_type,
|
179
|
+
item_id: item_id,
|
180
|
+
**options
|
181
|
+
})
|
182
|
+
end
|
183
|
+
|
184
|
+
# rubocop:disable Metrics/ParameterLists
|
185
|
+
# Checks content for moderation
|
186
|
+
#
|
187
|
+
# @param [string] entity_type Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
|
188
|
+
# @param [string] entity_id ID of the entity to be checked. This is mainly for tracking purposes
|
189
|
+
# @param [string] entity_creator_id ID of the entity creator
|
190
|
+
# @param [Hash] moderation_payload Content to be checked for moderation
|
191
|
+
# @option moderation_payload [Array<String>] :texts Array of texts to be checked for moderation
|
192
|
+
# @option moderation_payload [Array<String>] :images Array of images to be checked for moderation
|
193
|
+
# @option moderation_payload [Array<String>] :videos Array of videos to be checked for moderation
|
194
|
+
# @option moderation_payload [Hash] :custom Additional custom data
|
195
|
+
# @param [string] config_key Key of the moderation config to use
|
196
|
+
# @param [Hash] options Additional options
|
197
|
+
# @option options [Boolean] :force_sync Force synchronous check
|
198
|
+
sig do
|
199
|
+
params(
|
200
|
+
entity_type: String,
|
201
|
+
entity_id: String,
|
202
|
+
moderation_payload: T::Hash[Symbol, T.any(T::Array[String], T::Hash[String, T.untyped])],
|
203
|
+
config_key: String,
|
204
|
+
entity_creator_id: String,
|
205
|
+
options: T::Hash[Symbol, T::Boolean]
|
206
|
+
).returns(StreamChat::StreamResponse)
|
207
|
+
end
|
208
|
+
def check(entity_type, entity_id, moderation_payload, config_key, entity_creator_id: '', options: {})
|
209
|
+
@client.post('api/v2/moderation/check', data: {
|
210
|
+
entity_type: entity_type,
|
211
|
+
entity_id: entity_id,
|
212
|
+
entity_creator_id: entity_creator_id,
|
213
|
+
moderation_payload: moderation_payload,
|
214
|
+
config_key: config_key,
|
215
|
+
options: options
|
216
|
+
})
|
217
|
+
end
|
218
|
+
# rubocop:enable Metrics/ParameterLists
|
219
|
+
# Adds custom flags to an entity
|
220
|
+
#
|
221
|
+
# @param [string] entity_type Type of entity to be checked
|
222
|
+
# @param [string] entity_id ID of the entity to be checked
|
223
|
+
# @param [string] entity_creator_id ID of the entity creator
|
224
|
+
# @param [Hash] moderation_payload Content to be checked for moderation
|
225
|
+
# @param [Array] flags Array of custom flags to add
|
226
|
+
sig { params(entity_type: String, entity_id: String, moderation_payload: T.untyped, flags: T::Array[T.untyped], entity_creator_id: String).returns(StreamChat::StreamResponse) }
|
227
|
+
def add_custom_flags(entity_type, entity_id, moderation_payload, flags, entity_creator_id: '')
|
228
|
+
@client.post('api/v2/moderation/custom_check', data: {
|
229
|
+
entity_type: entity_type,
|
230
|
+
entity_id: entity_id,
|
231
|
+
entity_creator_id: entity_creator_id,
|
232
|
+
moderation_payload: moderation_payload,
|
233
|
+
flags: flags
|
234
|
+
})
|
235
|
+
end
|
236
|
+
|
237
|
+
# Adds custom flags to a message
|
238
|
+
#
|
239
|
+
# @param [string] message_id Message ID to be flagged
|
240
|
+
# @param [Array] flags Array of custom flags to add
|
241
|
+
sig { params(message_id: String, flags: T::Array[T.untyped]).returns(StreamChat::StreamResponse) }
|
242
|
+
def add_custom_message_flags(message_id, flags)
|
243
|
+
add_custom_flags(T.must(MODERATION_ENTITY_TYPES[:message]), message_id, {}, flags)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
data/lib/stream-chat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream-chat-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- getstream.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/stream-chat/channel.rb
|
116
116
|
- lib/stream-chat/client.rb
|
117
117
|
- lib/stream-chat/errors.rb
|
118
|
+
- lib/stream-chat/moderation.rb
|
118
119
|
- lib/stream-chat/stream_rate_limits.rb
|
119
120
|
- lib/stream-chat/stream_response.rb
|
120
121
|
- lib/stream-chat/types.rb
|