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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06e555a899a1f327f6ab64ae55a383c84bf76991df3530d67b8c29a84a27e0b4
4
- data.tar.gz: 93df6034f3d3f76d735f3a023ef0e160b1c74930509b52c80df3e9436b28780d
3
+ metadata.gz: cf7346fa100815ad5e6ded38ee11d3941ce5b8ef33e180ab39f0ce7d5edf1321
4
+ data.tar.gz: 1d4276d85a538fa0e3aa46b8836383e9a674b5701350ea834acfbed87406d07c
5
5
  SHA512:
6
- metadata.gz: 668c718c2dc5b9c75db14601a3c8d2ebf6eaf3f7a53d14b654c05236304b8bc46fd8c76f6790cde9c16453911bc07bc6f4efb6c7be5547a036b2f98d33c58b35
7
- data.tar.gz: e5b37cf05fedfe43a6d5b512dd36a0443010c7261070d40aa3455448c98a47842cbe2dbdd4b03cd83c315851aa810e66fda1e7cba4c358da1d015bde6f484484
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
 
@@ -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
- T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
13
+ sig { returns(T.nilable(String)) }
17
14
  attr_reader :id
18
15
 
19
- T::Sig::WithoutRuntime.sig { returns(String) }
16
+ sig { returns(String) }
20
17
  attr_reader :channel_type
21
18
 
22
- T::Sig::WithoutRuntime.sig { returns(StringKeyHash) }
19
+ sig { returns(StringKeyHash) }
23
20
  attr_reader :custom_data
24
21
 
25
- T::Sig::WithoutRuntime.sig { returns(T::Array[StringKeyHash]) }
22
+ sig { returns(T::Array[StringKeyHash]) }
26
23
  attr_reader :members
27
24
 
28
- T::Sig::WithoutRuntime.sig { params(client: StreamChat::Client, channel_type: String, channel_id: T.nilable(String), custom_data: T.nilable(StringKeyHash)).void }
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
- T::Sig::WithoutRuntime.sig { returns(String) }
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
- T::Sig::WithoutRuntime.sig { params(message_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(event: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(message_id: String, reaction: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(message_id: String, reaction_type: String, user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(channel_data: T.nilable(StringKeyHash), update_message: T.nilable(StringKeyHash), options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(set: T.nilable(StringKeyHash), unset: T.nilable(T::Array[String])).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String, expiration: T.nilable(Integer)).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(members: T::Array[StringKeyHash], message: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String, options: StringKeyHash).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(parent_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(url: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(url: String).returns(StreamChat::StreamResponse) }
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
- T::Sig::WithoutRuntime.sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
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