stream-chat-ruby 3.11.0 → 3.13.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/CHANGELOG.md +13 -0
- data/lib/stream-chat/channel.rb +35 -0
- data/lib/stream-chat/client.rb +29 -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: 3f242a964e26ae0d7150830f886e9e1b96b8a3f0a203421c0f8b8b439a455146
|
4
|
+
data.tar.gz: 5ade6ec19923342d9508b1b2b139c68e107ae0458e38edd41773e9c8e41d088b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1f4a36a5c7d9bc92cbd0ca7503fda1c18c67fac83e6cbbab46885703de71dd8aeac9b3312aba7c68b71ac4dcbba25ecb7b9eb7800ed3cdb7e6767a93c22ae93
|
7
|
+
data.tar.gz: d71f1a32e0e30f78a23bbd4bcd048215b15432f65645bd68d985d1d6650705f735d9ef3e8c36313903206e03366c5f71144c9faa6af042299e737bfc9367d112
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
## [3.13.0](https://github.com/GetStream/stream-chat-ruby/compare/v3.12.0...v3.13.0) (2025-04-04)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* deactivate users ([#162](https://github.com/GetStream/stream-chat-ruby/issues/162)) ([12bf4d1](https://github.com/GetStream/stream-chat-ruby/commit/12bf4d19846b5100f1886929b74c7ad05d753be4))
|
11
|
+
* draft messages ([#161](https://github.com/GetStream/stream-chat-ruby/pull/161)) ([1719104](https://github.com/GetStream/stream-chat-ruby/commit/c7bccb3ad30721a20f32fd60eb13ab6d97a08208))
|
12
|
+
|
13
|
+
### Other
|
14
|
+
|
15
|
+
* added nijeesh to code owners ([#156](https://github.com/GetStream/stream-chat-ruby/issues/156)) ([7cd4e54](https://github.com/GetStream/stream-chat-ruby/commit/7cd4e5443a8f283596b8eadc873030d737cd621c))
|
16
|
+
* **release:** v3.12.0 ([#157](https://github.com/GetStream/stream-chat-ruby/issues/157)) ([993b7a3](https://github.com/GetStream/stream-chat-ruby/commit/993b7a30bd2222ee328ca7a862384c7baf7d53e1))
|
17
|
+
|
5
18
|
## [3.11.0](https://github.com/GetStream/stream-chat-ruby/compare/v3.9.0...v3.11.0) (2025-03-21)
|
6
19
|
|
7
20
|
|
data/lib/stream-chat/channel.rb
CHANGED
@@ -360,6 +360,41 @@ module StreamChat
|
|
360
360
|
@client.delete("#{self.url}/image", params: { url: url })
|
361
361
|
end
|
362
362
|
|
363
|
+
# Creates or updates a draft message for this channel.
|
364
|
+
#
|
365
|
+
# @param [StringKeyHash] message The draft message content
|
366
|
+
# @param [String] user_id The ID of the user creating/updating the draft
|
367
|
+
# @return [StreamChat::StreamResponse]
|
368
|
+
sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
369
|
+
def create_draft(message, user_id)
|
370
|
+
payload = { message: add_user_id(message, user_id) }
|
371
|
+
@client.post("#{url}/draft", data: payload)
|
372
|
+
end
|
373
|
+
|
374
|
+
# Deletes a draft message for this channel.
|
375
|
+
#
|
376
|
+
# @param [String] user_id The ID of the user deleting the draft
|
377
|
+
# @param [String] parent_id Optional parent message ID for thread drafts
|
378
|
+
# @return [StreamChat::StreamResponse]
|
379
|
+
sig { params(user_id: String, parent_id: T.nilable(String)).returns(StreamChat::StreamResponse) }
|
380
|
+
def delete_draft(user_id, parent_id: nil)
|
381
|
+
params = { user_id: user_id }
|
382
|
+
params[:parent_id] = parent_id if parent_id
|
383
|
+
@client.delete("#{url}/draft", params: params)
|
384
|
+
end
|
385
|
+
|
386
|
+
# Gets a draft message for this channel.
|
387
|
+
#
|
388
|
+
# @param [String] user_id The ID of the user getting the draft
|
389
|
+
# @param [String] parent_id Optional parent message ID for thread drafts
|
390
|
+
# @return [StreamChat::StreamResponse]
|
391
|
+
sig { params(user_id: String, parent_id: T.nilable(String)).returns(StreamChat::StreamResponse) }
|
392
|
+
def get_draft(user_id, parent_id: nil)
|
393
|
+
params = { user_id: user_id }
|
394
|
+
params[:parent_id] = parent_id if parent_id
|
395
|
+
@client.get("#{url}/draft", params: params)
|
396
|
+
end
|
397
|
+
|
363
398
|
private
|
364
399
|
|
365
400
|
sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
|
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
|
@@ -275,6 +280,14 @@ module StreamChat
|
|
275
280
|
post("users/#{user_id}/deactivate", params: options)
|
276
281
|
end
|
277
282
|
|
283
|
+
# Deactivates a users
|
284
|
+
sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
|
285
|
+
def deactivate_users(user_ids, **options)
|
286
|
+
raise ArgumentError, 'user_ids should not be empty' if user_ids.empty?
|
287
|
+
|
288
|
+
post('users/deactivate', data: { user_ids: user_ids, **options })
|
289
|
+
end
|
290
|
+
|
278
291
|
# Reactivates a deactivated user. Use deactivate_user to deactivate a user.
|
279
292
|
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
280
293
|
def reactivate_user(user_id, **options)
|
@@ -778,6 +791,22 @@ module StreamChat
|
|
778
791
|
post('commands', data: command)
|
779
792
|
end
|
780
793
|
|
794
|
+
# Queries draft messages for the current user.
|
795
|
+
#
|
796
|
+
# @param [String] user_id The ID of the user to query drafts for
|
797
|
+
# @param [StringKeyHash] filter Optional filter conditions for the query
|
798
|
+
# @param [Array] sort Optional sort parameters
|
799
|
+
# @param [Hash] options Additional query options
|
800
|
+
# @return [StreamChat::StreamResponse]
|
801
|
+
sig { params(user_id: String, filter: T.nilable(StringKeyHash), sort: T.nilable(T::Array[StringKeyHash]), options: T.untyped).returns(StreamChat::StreamResponse) }
|
802
|
+
def query_drafts(user_id, filter: nil, sort: nil, **options)
|
803
|
+
data = { user_id: user_id }
|
804
|
+
data['filter'] = filter if filter
|
805
|
+
data['sort'] = sort if sort
|
806
|
+
data.merge!(options) if options
|
807
|
+
post('drafts/query', data: data)
|
808
|
+
end
|
809
|
+
|
781
810
|
# Gets a comamnd.
|
782
811
|
sig { params(name: String).returns(StreamChat::StreamResponse) }
|
783
812
|
def get_command(name)
|
@@ -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.13.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-
|
11
|
+
date: 2025-04-04 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
|