stream-chat-ruby 2.23.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +2 -0
- data/lib/stream-chat/channel.rb +40 -43
- data/lib/stream-chat/client.rb +118 -121
- data/lib/stream-chat/errors.rb +7 -10
- data/lib/stream-chat/stream_rate_limits.rb +4 -7
- data/lib/stream-chat/stream_response.rb +4 -7
- data/lib/stream-chat/types.rb +0 -3
- data/lib/stream-chat/util.rb +1 -4
- data/lib/stream-chat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf7346fa100815ad5e6ded38ee11d3941ce5b8ef33e180ab39f0ce7d5edf1321
|
4
|
+
data.tar.gz: 1d4276d85a538fa0e3aa46b8836383e9a674b5701350ea834acfbed87406d07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebcd5bcf54929c7d7c93194c447f511b0e1a341fbae359ba06d8757e3e3b8097ef468da0d0bc9f0ea401fcd2c95a051c3acdab5797c864b5298387c87d0e7f4a
|
7
|
+
data.tar.gz: 12730b06d2997b07b91bef7f9e19f7c40b3d059b3b5b97e490190f80a1837650189190a121fa891a63145cf783262d9cf7b41d51846f05dae3a7ee0238803a05
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,21 @@
|
|
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.0.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.23.0...v3.0.0) (2022-05-24)
|
6
|
+
|
7
|
+
|
8
|
+
### ⚠ BREAKING CHANGES
|
9
|
+
|
10
|
+
* **sorbet:** enable runtime typecheck (#104)
|
11
|
+
|
12
|
+
> In this release we have enabled runtime level typechecking for Sorbet. This means that if you input parameters
|
13
|
+
are invalid **your code will throw an error during runtime**. Please ensure that your code is properly tested
|
14
|
+
before continuing with v3.0.0 of this library.
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
* **sorbet:** enable runtime typecheck ([#104](https://github.com/GetStream/stream-chat-ruby/issues/104)) ([97d5f29](https://github.com/GetStream/stream-chat-ruby/commit/97d5f299b652e8328af6e76d0d605c59f05a5cc3))
|
19
|
+
|
5
20
|
## [2.23.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.22.2...v2.23.0) (2022-05-19)
|
6
21
|
|
7
22
|
|
data/README.md
CHANGED
@@ -47,6 +47,8 @@ client = StreamChat::Client.new(api_key='STREAM_KEY', api_secret='STREAM_SECRET'
|
|
47
47
|
> 💡 Note: since v2.21.0 we implemented [Sorbet](https://sorbet.org/) type checker. As of v2.x.x we only use it for static type checks and you won't notice any difference, but from v3.0.0 **we will enable runtime checks** 🚨 🚨 🚨.
|
48
48
|
|
49
49
|
> What this means, is that you'll receive an error during runtime if you pass an invalid type to our methods. To prepare for that, just make sure whatever you pass in, matches the method signature (`sig { ... }`).
|
50
|
+
|
51
|
+
> **Update (2022-May-24)**: we have relased [v3.0.0](https://github.com/GetStream/stream-chat-ruby/releases/tag/v3.0.0) with enabled runtime checks.
|
50
52
|
|
51
53
|
---
|
52
54
|
|
data/lib/stream-chat/channel.rb
CHANGED
@@ -9,23 +9,20 @@ require 'stream-chat/types'
|
|
9
9
|
module StreamChat
|
10
10
|
class Channel
|
11
11
|
extend T::Sig
|
12
|
-
# For now we disable runtime type checks.
|
13
|
-
# We will enable it with a major bump in the future,
|
14
|
-
# but for now, let's just run a static type check.
|
15
12
|
|
16
|
-
|
13
|
+
sig { returns(T.nilable(String)) }
|
17
14
|
attr_reader :id
|
18
15
|
|
19
|
-
|
16
|
+
sig { returns(String) }
|
20
17
|
attr_reader :channel_type
|
21
18
|
|
22
|
-
|
19
|
+
sig { returns(StringKeyHash) }
|
23
20
|
attr_reader :custom_data
|
24
21
|
|
25
|
-
|
22
|
+
sig { returns(T::Array[StringKeyHash]) }
|
26
23
|
attr_reader :members
|
27
24
|
|
28
|
-
|
25
|
+
sig { params(client: StreamChat::Client, channel_type: String, channel_id: T.nilable(String), custom_data: T.nilable(StringKeyHash)).void }
|
29
26
|
def initialize(client, channel_type, channel_id = nil, custom_data = nil)
|
30
27
|
@channel_type = channel_type
|
31
28
|
@id = channel_id
|
@@ -35,7 +32,7 @@ module StreamChat
|
|
35
32
|
@members = T.let([], T::Array[StringKeyHash])
|
36
33
|
end
|
37
34
|
|
38
|
-
|
35
|
+
sig { returns(String) }
|
39
36
|
def url
|
40
37
|
raise StreamChannelException, 'channel does not have an id' if @id.nil?
|
41
38
|
|
@@ -43,34 +40,34 @@ module StreamChat
|
|
43
40
|
end
|
44
41
|
|
45
42
|
# Gets multiple messages from the channel.
|
46
|
-
|
43
|
+
sig { params(message_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
47
44
|
def get_messages(message_ids)
|
48
45
|
@client.get("#{url}/messages", params: { 'ids' => message_ids.join(',') })
|
49
46
|
end
|
50
47
|
|
51
48
|
# Sends a message to this channel.
|
52
|
-
|
49
|
+
sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
53
50
|
def send_message(message, user_id)
|
54
51
|
payload = { message: add_user_id(message, user_id) }
|
55
52
|
@client.post("#{url}/message", data: payload)
|
56
53
|
end
|
57
54
|
|
58
55
|
# Sends an event on this channel.
|
59
|
-
|
56
|
+
sig { params(event: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
60
57
|
def send_event(event, user_id)
|
61
58
|
payload = { 'event' => add_user_id(event, user_id) }
|
62
59
|
@client.post("#{url}/event", data: payload)
|
63
60
|
end
|
64
61
|
|
65
62
|
# Sends a new reaction to a given message.
|
66
|
-
|
63
|
+
sig { params(message_id: String, reaction: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
67
64
|
def send_reaction(message_id, reaction, user_id)
|
68
65
|
payload = { reaction: add_user_id(reaction, user_id) }
|
69
66
|
@client.post("messages/#{message_id}/reaction", data: payload)
|
70
67
|
end
|
71
68
|
|
72
69
|
# Delete a reaction from a message.
|
73
|
-
|
70
|
+
sig { params(message_id: String, reaction_type: String, user_id: String).returns(StreamChat::StreamResponse) }
|
74
71
|
def delete_reaction(message_id, reaction_type, user_id)
|
75
72
|
@client.delete(
|
76
73
|
"messages/#{message_id}/reaction/#{reaction_type}",
|
@@ -79,14 +76,14 @@ module StreamChat
|
|
79
76
|
end
|
80
77
|
|
81
78
|
# Creates a channel with the given creator user.
|
82
|
-
|
79
|
+
sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
83
80
|
def create(user_id)
|
84
81
|
@custom_data['created_by'] = { id: user_id }
|
85
82
|
query(watch: false, state: false, presence: false)
|
86
83
|
end
|
87
84
|
|
88
85
|
# Creates or returns a channel.
|
89
|
-
|
86
|
+
sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
|
90
87
|
def query(**options)
|
91
88
|
payload = { state: true, data: @custom_data }.merge(options)
|
92
89
|
url = "channels/#{@channel_type}"
|
@@ -103,7 +100,7 @@ module StreamChat
|
|
103
100
|
# endpoint supports filtering on numerous criteria to efficiently return members information.
|
104
101
|
# This endpoint is useful for channels that have large lists of members and
|
105
102
|
# you want to search members or if you want to display the full list of members for a channel.
|
106
|
-
|
103
|
+
sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
|
107
104
|
def query_members(filter_conditions = {}, sort: nil, **options)
|
108
105
|
params = {}.merge(options).merge({
|
109
106
|
id: @id,
|
@@ -123,14 +120,14 @@ module StreamChat
|
|
123
120
|
end
|
124
121
|
|
125
122
|
# Updates a channel.
|
126
|
-
|
123
|
+
sig { params(channel_data: T.nilable(StringKeyHash), update_message: T.nilable(StringKeyHash), options: T.untyped).returns(StreamChat::StreamResponse) }
|
127
124
|
def update(channel_data, update_message = nil, **options)
|
128
125
|
payload = { data: channel_data, message: update_message }.merge(options)
|
129
126
|
@client.post(url, data: payload)
|
130
127
|
end
|
131
128
|
|
132
129
|
# Updates a channel partially.
|
133
|
-
|
130
|
+
sig { params(set: T.nilable(StringKeyHash), unset: T.nilable(T::Array[String])).returns(StreamChat::StreamResponse) }
|
134
131
|
def update_partial(set = nil, unset = nil)
|
135
132
|
raise StreamChannelException, 'set or unset is needed' if set.nil? && unset.nil?
|
136
133
|
|
@@ -139,13 +136,13 @@ module StreamChat
|
|
139
136
|
end
|
140
137
|
|
141
138
|
# Deletes a channel.
|
142
|
-
|
139
|
+
sig { returns(StreamChat::StreamResponse) }
|
143
140
|
def delete
|
144
141
|
@client.delete(url)
|
145
142
|
end
|
146
143
|
|
147
144
|
# Removes all messages from the channel.
|
148
|
-
|
145
|
+
sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
|
149
146
|
def truncate(**options)
|
150
147
|
@client.post("#{url}/truncate", data: options)
|
151
148
|
end
|
@@ -156,7 +153,7 @@ module StreamChat
|
|
156
153
|
# unread count for the users that muted it. By default, mutes stay in place indefinitely
|
157
154
|
# until the user removes it; however, you can optionally set an expiration time. The list
|
158
155
|
# of muted channels and their expiration time is returned when the user connects.
|
159
|
-
|
156
|
+
sig { params(user_id: String, expiration: T.nilable(Integer)).returns(StreamChat::StreamResponse) }
|
160
157
|
def mute(user_id, expiration = nil)
|
161
158
|
data = { user_id: user_id, channel_cid: @cid }
|
162
159
|
data['expiration'] = expiration if expiration
|
@@ -164,104 +161,104 @@ module StreamChat
|
|
164
161
|
end
|
165
162
|
|
166
163
|
# Unmutes a channel.
|
167
|
-
|
164
|
+
sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
168
165
|
def unmute(user_id)
|
169
166
|
@client.post('moderation/unmute/channel', data: { 'user_id' => user_id, 'channel_cid' => @cid })
|
170
167
|
end
|
171
168
|
|
172
169
|
# Adds members to the channel.
|
173
|
-
|
170
|
+
sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
|
174
171
|
def add_members(user_ids, **options)
|
175
172
|
payload = options.merge({ add_members: user_ids })
|
176
173
|
update(nil, nil, **payload)
|
177
174
|
end
|
178
175
|
|
179
176
|
# Invites users to the channel.
|
180
|
-
|
177
|
+
sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
|
181
178
|
def invite_members(user_ids, **options)
|
182
179
|
payload = options.merge({ invites: user_ids })
|
183
180
|
update(nil, nil, **payload)
|
184
181
|
end
|
185
182
|
|
186
183
|
# Accepts an invitation to the channel.
|
187
|
-
|
184
|
+
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
188
185
|
def accept_invite(user_id, **options)
|
189
186
|
payload = options.merge({ user_id: user_id, accept_invite: true })
|
190
187
|
update(nil, nil, **payload)
|
191
188
|
end
|
192
189
|
|
193
190
|
# Rejects an invitation to the channel.
|
194
|
-
|
191
|
+
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
195
192
|
def reject_invite(user_id, **options)
|
196
193
|
payload = options.merge({ user_id: user_id, reject_invite: true })
|
197
194
|
update(nil, nil, **payload)
|
198
195
|
end
|
199
196
|
|
200
197
|
# Adds moderators to the channel.
|
201
|
-
|
198
|
+
sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
202
199
|
def add_moderators(user_ids)
|
203
200
|
update(nil, nil, add_moderators: user_ids)
|
204
201
|
end
|
205
202
|
|
206
203
|
# Removes members from the channel.
|
207
|
-
|
204
|
+
sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
208
205
|
def remove_members(user_ids)
|
209
206
|
update(nil, nil, remove_members: user_ids)
|
210
207
|
end
|
211
208
|
|
212
209
|
# Assigns roles to members in the channel.
|
213
|
-
|
210
|
+
sig { params(members: T::Array[StringKeyHash], message: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
|
214
211
|
def assign_roles(members, message = nil)
|
215
212
|
update(nil, message, assign_roles: members)
|
216
213
|
end
|
217
214
|
|
218
215
|
# Demotes moderators in the channel.
|
219
|
-
|
216
|
+
sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
220
217
|
def demote_moderators(user_ids)
|
221
218
|
update(nil, nil, demote_moderators: user_ids)
|
222
219
|
end
|
223
220
|
|
224
221
|
# Sends the mark read event for this user, only works if the `read_events` setting is enabled.
|
225
|
-
|
222
|
+
sig { params(user_id: String, options: StringKeyHash).returns(StreamChat::StreamResponse) }
|
226
223
|
def mark_read(user_id, **options)
|
227
224
|
payload = add_user_id(options, user_id)
|
228
225
|
@client.post("#{url}/read", data: payload)
|
229
226
|
end
|
230
227
|
|
231
228
|
# List the message replies for a parent message.
|
232
|
-
|
229
|
+
sig { params(parent_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
233
230
|
def get_replies(parent_id, **options)
|
234
231
|
@client.get("messages/#{parent_id}/replies", params: options)
|
235
232
|
end
|
236
233
|
|
237
234
|
# List the reactions, supports pagination.
|
238
|
-
|
235
|
+
sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
239
236
|
def get_reactions(message_id, **options)
|
240
237
|
@client.get("messages/#{message_id}/reactions", params: options)
|
241
238
|
end
|
242
239
|
|
243
240
|
# Bans a user from this channel.
|
244
|
-
|
241
|
+
sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
245
242
|
def ban_user(user_id, **options)
|
246
243
|
@client.ban_user(user_id, type: @channel_type, id: @id, **options)
|
247
244
|
end
|
248
245
|
|
249
246
|
# Removes the ban for a user on this channel.
|
250
|
-
|
247
|
+
sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
251
248
|
def unban_user(user_id)
|
252
249
|
@client.unban_user(user_id, type: @channel_type, id: @id)
|
253
250
|
end
|
254
251
|
|
255
252
|
# Removes a channel from query channel requests for that user until a new message is added.
|
256
253
|
# Use `show` to cancel this operation.
|
257
|
-
|
254
|
+
sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
258
255
|
def hide(user_id)
|
259
256
|
@client.post("#{url}/hide", data: { user_id: user_id })
|
260
257
|
end
|
261
258
|
|
262
259
|
# Shows a previously hidden channel.
|
263
260
|
# Use `hide` to hide a channel.
|
264
|
-
|
261
|
+
sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
265
262
|
def show(user_id)
|
266
263
|
@client.post("#{url}/show", data: { user_id: user_id })
|
267
264
|
end
|
@@ -270,7 +267,7 @@ module StreamChat
|
|
270
267
|
#
|
271
268
|
# This functionality defaults to using the Stream CDN. If you would like, you can
|
272
269
|
# easily change the logic to upload to your own CDN of choice.
|
273
|
-
|
270
|
+
sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
|
274
271
|
def send_file(url, user, content_type = nil)
|
275
272
|
@client.send_file("#{self.url}/file", url, user, content_type)
|
276
273
|
end
|
@@ -281,26 +278,26 @@ module StreamChat
|
|
281
278
|
# image/heic, image/heic-sequence, image/heif, image/heif-sequence, image/svg+xml.
|
282
279
|
# You can set a more restrictive list for your application if needed.
|
283
280
|
# The maximum file size is 100MB.
|
284
|
-
|
281
|
+
sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
|
285
282
|
def send_image(url, user, content_type = nil)
|
286
283
|
@client.send_file("#{self.url}/image", url, user, content_type)
|
287
284
|
end
|
288
285
|
|
289
286
|
# Deletes a file by file url.
|
290
|
-
|
287
|
+
sig { params(url: String).returns(StreamChat::StreamResponse) }
|
291
288
|
def delete_file(url)
|
292
289
|
@client.delete("#{self.url}/file", params: { url: url })
|
293
290
|
end
|
294
291
|
|
295
292
|
# Deletes an image by image url.
|
296
|
-
|
293
|
+
sig { params(url: String).returns(StreamChat::StreamResponse) }
|
297
294
|
def delete_image(url)
|
298
295
|
@client.delete("#{self.url}/image", params: { url: url })
|
299
296
|
end
|
300
297
|
|
301
298
|
private
|
302
299
|
|
303
|
-
|
300
|
+
sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
|
304
301
|
def add_user_id(payload, user_id)
|
305
302
|
payload.merge({ user: { id: user_id } })
|
306
303
|
end
|