stream-chat-ruby 2.21.0 → 2.22.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/lib/stream-chat/channel.rb +93 -41
- data/lib/stream-chat/client.rb +323 -101
- data/lib/stream-chat/errors.rb +7 -8
- data/lib/stream-chat/stream_rate_limits.rb +4 -5
- data/lib/stream-chat/stream_response.rb +4 -5
- data/lib/stream-chat/types.rb +0 -1
- data/lib/stream-chat/util.rb +1 -2
- data/lib/stream-chat/version.rb +1 -1
- data/stream-chat.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d1012ba93c094b6a28185368ae809b0c6ef9bd67d9b88fc7731261c53e25b5
|
4
|
+
data.tar.gz: 04113551dd54cbd418e289f024213bfa3d388168711266a40bd8678d5b59284b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15dca07dcf3d295ac549a2f7d7ddc28663d21c24afa1cd9d4fca89d7a129b00f49594da4713757349903e61b1b2c2b5b32c70e0af1d3827dfd42523ad108c765
|
7
|
+
data.tar.gz: 0d1c5dc9a6ccab2ef2db44fc6eeb221ccf62d16c8779554831784525e2ed375b53f7086f27e02dd22d9a57c77fec1b80e3930cad65a19c898dca2591e3699e6b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,29 @@
|
|
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
|
+
### [2.22.2](https://github.com/GetStream/stream-chat-ruby/compare/v2.22.1...v2.22.2) (2022-04-21)
|
6
|
+
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
* **sorbet:** turn off runtime checks properly ([#98](https://github.com/GetStream/stream-chat-ruby/issues/98)) ([29e9e73](https://github.com/GetStream/stream-chat-ruby/commit/29e9e73ac07d163e8c1ca7b24516cb7ac61e93cd))
|
11
|
+
|
12
|
+
### [2.22.1](https://github.com/GetStream/stream-chat-ruby/compare/v2.22.0...v2.22.1) (2022-04-20)
|
13
|
+
|
14
|
+
### Features
|
15
|
+
|
16
|
+
* added comments to public methods ([#93](https://github.com/GetStream/stream-chat-ruby/issues/93)) ([3843fe4](https://github.com/GetStream/stream-chat-ruby/commit/3843fe41ea7716d2b6a787d695bbe54981b2b35e))
|
17
|
+
|
18
|
+
## [2.22.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.21.0...v2.22.0) (2022-04-01)
|
19
|
+
|
20
|
+
|
21
|
+
### Features
|
22
|
+
|
23
|
+
* add new device field ([#90](https://github.com/GetStream/stream-chat-ruby/issues/90)) ([aa6723c](https://github.com/GetStream/stream-chat-ruby/commit/aa6723cd54e58aab0f1b8c55bc4e54211ab39f3c))
|
24
|
+
* add new moderation apis ([#88](https://github.com/GetStream/stream-chat-ruby/issues/88)) ([573c586](https://github.com/GetStream/stream-chat-ruby/commit/573c58650392eaa5a6d38b4423e170e30b3e98df))
|
25
|
+
* add push provider apis ([#89](https://github.com/GetStream/stream-chat-ruby/issues/89)) ([d592fba](https://github.com/GetStream/stream-chat-ruby/commit/d592fba4c0041102fa18d0fee11961f881414337))
|
26
|
+
* **update_user:** deprecate update in favor of upsert ([#91](https://github.com/GetStream/stream-chat-ruby/issues/91)) ([74d3163](https://github.com/GetStream/stream-chat-ruby/commit/74d316339b277b0f9cf0f94f40f11aae30fd7644))
|
27
|
+
|
5
28
|
## [2.21.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.20.0...v2.21.0) (2022-03-03)
|
6
29
|
|
7
30
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -67,7 +67,7 @@ client.create_token('bob-1')
|
|
67
67
|
### Create/Update users
|
68
68
|
|
69
69
|
```ruby
|
70
|
-
client.
|
70
|
+
client.upsert_user({
|
71
71
|
:id => 'bob-1',
|
72
72
|
:role => 'admin',
|
73
73
|
:name => 'Robert Tables'
|
@@ -76,7 +76,7 @@ client.update_user({
|
|
76
76
|
# Batch update is also supported
|
77
77
|
jane = {:id => 'jane-1'}
|
78
78
|
june = {:id => 'june-1'}
|
79
|
-
client.
|
79
|
+
client.upsert_users([jane, june])
|
80
80
|
```
|
81
81
|
|
82
82
|
### Channel types
|
data/lib/stream-chat/channel.rb
CHANGED
@@ -9,24 +9,23 @@ require 'stream-chat/types'
|
|
9
9
|
module StreamChat
|
10
10
|
class Channel
|
11
11
|
extend T::Sig
|
12
|
-
T::Configuration.default_checked_level = :never
|
13
12
|
# For now we disable runtime type checks.
|
14
13
|
# We will enable it with a major bump in the future,
|
15
14
|
# but for now, let's just run a static type check.
|
16
15
|
|
17
|
-
sig { returns(T.nilable(String)) }
|
16
|
+
T::Sig::WithoutRuntime.sig { returns(T.nilable(String)) }
|
18
17
|
attr_reader :id
|
19
18
|
|
20
|
-
sig { returns(String) }
|
19
|
+
T::Sig::WithoutRuntime.sig { returns(String) }
|
21
20
|
attr_reader :channel_type
|
22
21
|
|
23
|
-
sig { returns(StringKeyHash) }
|
22
|
+
T::Sig::WithoutRuntime.sig { returns(StringKeyHash) }
|
24
23
|
attr_reader :custom_data
|
25
24
|
|
26
|
-
sig { returns(T::Array[StringKeyHash]) }
|
25
|
+
T::Sig::WithoutRuntime.sig { returns(T::Array[StringKeyHash]) }
|
27
26
|
attr_reader :members
|
28
27
|
|
29
|
-
sig { params(client: StreamChat::Client, channel_type: String, channel_id: T.nilable(String), custom_data: T.nilable(StringKeyHash)).void }
|
28
|
+
T::Sig::WithoutRuntime.sig { params(client: StreamChat::Client, channel_type: String, channel_id: T.nilable(String), custom_data: T.nilable(StringKeyHash)).void }
|
30
29
|
def initialize(client, channel_type, channel_id = nil, custom_data = nil)
|
31
30
|
@channel_type = channel_type
|
32
31
|
@id = channel_id
|
@@ -36,37 +35,42 @@ module StreamChat
|
|
36
35
|
@members = T.let([], T::Array[StringKeyHash])
|
37
36
|
end
|
38
37
|
|
39
|
-
sig { returns(String) }
|
38
|
+
T::Sig::WithoutRuntime.sig { returns(String) }
|
40
39
|
def url
|
41
40
|
raise StreamChannelException, 'channel does not have an id' if @id.nil?
|
42
41
|
|
43
42
|
"channels/#{@channel_type}/#{@id}"
|
44
43
|
end
|
45
44
|
|
46
|
-
|
45
|
+
# Gets multiple messages from the channel.
|
46
|
+
T::Sig::WithoutRuntime.sig { params(message_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
47
47
|
def get_messages(message_ids)
|
48
48
|
@client.get("#{url}/messages", params: { 'ids' => message_ids.join(',') })
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
# Sends a message to this channel.
|
52
|
+
T::Sig::WithoutRuntime.sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
52
53
|
def send_message(message, user_id)
|
53
54
|
payload = { message: add_user_id(message, user_id) }
|
54
55
|
@client.post("#{url}/message", data: payload)
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
# Sends an event on this channel.
|
59
|
+
T::Sig::WithoutRuntime.sig { params(event: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
|
58
60
|
def send_event(event, user_id)
|
59
61
|
payload = { 'event' => add_user_id(event, user_id) }
|
60
62
|
@client.post("#{url}/event", data: payload)
|
61
63
|
end
|
62
64
|
|
63
|
-
|
65
|
+
# 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) }
|
64
67
|
def send_reaction(message_id, reaction, user_id)
|
65
68
|
payload = { reaction: add_user_id(reaction, user_id) }
|
66
69
|
@client.post("messages/#{message_id}/reaction", data: payload)
|
67
70
|
end
|
68
71
|
|
69
|
-
|
72
|
+
# 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
74
|
def delete_reaction(message_id, reaction_type, user_id)
|
71
75
|
@client.delete(
|
72
76
|
"messages/#{message_id}/reaction/#{reaction_type}",
|
@@ -74,13 +78,15 @@ module StreamChat
|
|
74
78
|
)
|
75
79
|
end
|
76
80
|
|
77
|
-
|
81
|
+
# Creates a channel with the given creator user.
|
82
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
78
83
|
def create(user_id)
|
79
84
|
@custom_data['created_by'] = { id: user_id }
|
80
85
|
query(watch: false, state: false, presence: false)
|
81
86
|
end
|
82
87
|
|
83
|
-
|
88
|
+
# Creates or returns a channel.
|
89
|
+
T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
|
84
90
|
def query(**options)
|
85
91
|
payload = { state: true, data: @custom_data }.merge(options)
|
86
92
|
url = "channels/#{@channel_type}"
|
@@ -91,7 +97,13 @@ module StreamChat
|
|
91
97
|
state
|
92
98
|
end
|
93
99
|
|
94
|
-
|
100
|
+
# Queries members of a channel.
|
101
|
+
#
|
102
|
+
# The queryMembers endpoint allows you to list and paginate members from a channel. The
|
103
|
+
# endpoint supports filtering on numerous criteria to efficiently return members information.
|
104
|
+
# This endpoint is useful for channels that have large lists of members and
|
105
|
+
# 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) }
|
95
107
|
def query_members(filter_conditions = {}, sort: nil, **options)
|
96
108
|
params = {}.merge(options).merge({
|
97
109
|
id: @id,
|
@@ -110,13 +122,15 @@ module StreamChat
|
|
110
122
|
@client.get('members', params: { payload: params.to_json })
|
111
123
|
end
|
112
124
|
|
113
|
-
|
125
|
+
# 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) }
|
114
127
|
def update(channel_data, update_message = nil, **options)
|
115
128
|
payload = { data: channel_data, message: update_message }.merge(options)
|
116
129
|
@client.post(url, data: payload)
|
117
130
|
end
|
118
131
|
|
119
|
-
|
132
|
+
# Updates a channel partially.
|
133
|
+
T::Sig::WithoutRuntime.sig { params(set: T.nilable(StringKeyHash), unset: T.nilable(T::Array[String])).returns(StreamChat::StreamResponse) }
|
120
134
|
def update_partial(set = nil, unset = nil)
|
121
135
|
raise StreamChannelException, 'set or unset is needed' if set.nil? && unset.nil?
|
122
136
|
|
@@ -124,131 +138,169 @@ module StreamChat
|
|
124
138
|
@client.patch(url, data: payload)
|
125
139
|
end
|
126
140
|
|
127
|
-
|
141
|
+
# Deletes a channel.
|
142
|
+
T::Sig::WithoutRuntime.sig { returns(StreamChat::StreamResponse) }
|
128
143
|
def delete
|
129
144
|
@client.delete(url)
|
130
145
|
end
|
131
146
|
|
132
|
-
|
147
|
+
# Removes all messages from the channel.
|
148
|
+
T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
|
133
149
|
def truncate(**options)
|
134
150
|
@client.post("#{url}/truncate", data: options)
|
135
151
|
end
|
136
152
|
|
137
|
-
|
153
|
+
# Mutes a channel.
|
154
|
+
#
|
155
|
+
# Messages added to a muted channel will not trigger push notifications, nor change the
|
156
|
+
# unread count for the users that muted it. By default, mutes stay in place indefinitely
|
157
|
+
# until the user removes it; however, you can optionally set an expiration time. The list
|
158
|
+
# 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) }
|
138
160
|
def mute(user_id, expiration = nil)
|
139
161
|
data = { user_id: user_id, channel_cid: @cid }
|
140
162
|
data['expiration'] = expiration if expiration
|
141
163
|
@client.post('moderation/mute/channel', data: data)
|
142
164
|
end
|
143
165
|
|
144
|
-
|
166
|
+
# Unmutes a channel.
|
167
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
145
168
|
def unmute(user_id)
|
146
169
|
@client.post('moderation/unmute/channel', data: { 'user_id' => user_id, 'channel_cid' => @cid })
|
147
170
|
end
|
148
171
|
|
149
|
-
|
172
|
+
# Adds members to the channel.
|
173
|
+
T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
|
150
174
|
def add_members(user_ids, **options)
|
151
175
|
payload = options.merge({ add_members: user_ids })
|
152
176
|
update(nil, nil, **payload)
|
153
177
|
end
|
154
178
|
|
155
|
-
|
179
|
+
# Invites users to the channel.
|
180
|
+
T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
|
156
181
|
def invite_members(user_ids, **options)
|
157
182
|
payload = options.merge({ invites: user_ids })
|
158
183
|
update(nil, nil, **payload)
|
159
184
|
end
|
160
185
|
|
161
|
-
|
186
|
+
# Accepts an invitation to the channel.
|
187
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
162
188
|
def accept_invite(user_id, **options)
|
163
189
|
payload = options.merge({ user_id: user_id, accept_invite: true })
|
164
190
|
update(nil, nil, **payload)
|
165
191
|
end
|
166
192
|
|
167
|
-
|
193
|
+
# Rejects an invitation to the channel.
|
194
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
168
195
|
def reject_invite(user_id, **options)
|
169
196
|
payload = options.merge({ user_id: user_id, reject_invite: true })
|
170
197
|
update(nil, nil, **payload)
|
171
198
|
end
|
172
199
|
|
173
|
-
|
200
|
+
# Adds moderators to the channel.
|
201
|
+
T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
174
202
|
def add_moderators(user_ids)
|
175
203
|
update(nil, nil, add_moderators: user_ids)
|
176
204
|
end
|
177
205
|
|
178
|
-
|
206
|
+
# Removes members from the channel.
|
207
|
+
T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
179
208
|
def remove_members(user_ids)
|
180
209
|
update(nil, nil, remove_members: user_ids)
|
181
210
|
end
|
182
211
|
|
183
|
-
|
212
|
+
# Assigns roles to members in the channel.
|
213
|
+
T::Sig::WithoutRuntime.sig { params(members: T::Array[StringKeyHash], message: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
|
184
214
|
def assign_roles(members, message = nil)
|
185
215
|
update(nil, message, assign_roles: members)
|
186
216
|
end
|
187
217
|
|
188
|
-
|
218
|
+
# Demotes moderators in the channel.
|
219
|
+
T::Sig::WithoutRuntime.sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
|
189
220
|
def demote_moderators(user_ids)
|
190
221
|
update(nil, nil, demote_moderators: user_ids)
|
191
222
|
end
|
192
223
|
|
193
|
-
|
224
|
+
# 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) }
|
194
226
|
def mark_read(user_id, **options)
|
195
227
|
payload = add_user_id(options, user_id)
|
196
228
|
@client.post("#{url}/read", data: payload)
|
197
229
|
end
|
198
230
|
|
199
|
-
|
231
|
+
# List the message replies for a parent message.
|
232
|
+
T::Sig::WithoutRuntime.sig { params(parent_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
200
233
|
def get_replies(parent_id, **options)
|
201
234
|
@client.get("messages/#{parent_id}/replies", params: options)
|
202
235
|
end
|
203
236
|
|
204
|
-
|
237
|
+
# List the reactions, supports pagination.
|
238
|
+
T::Sig::WithoutRuntime.sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
205
239
|
def get_reactions(message_id, **options)
|
206
240
|
@client.get("messages/#{message_id}/reactions", params: options)
|
207
241
|
end
|
208
242
|
|
209
|
-
|
243
|
+
# Bans a user from this channel.
|
244
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
|
210
245
|
def ban_user(user_id, **options)
|
211
246
|
@client.ban_user(user_id, type: @channel_type, id: @id, **options)
|
212
247
|
end
|
213
248
|
|
214
|
-
|
249
|
+
# Removes the ban for a user on this channel.
|
250
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
215
251
|
def unban_user(user_id)
|
216
252
|
@client.unban_user(user_id, type: @channel_type, id: @id)
|
217
253
|
end
|
218
254
|
|
219
|
-
|
255
|
+
# Removes a channel from query channel requests for that user until a new message is added.
|
256
|
+
# Use `show` to cancel this operation.
|
257
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
220
258
|
def hide(user_id)
|
221
259
|
@client.post("#{url}/hide", data: { user_id: user_id })
|
222
260
|
end
|
223
261
|
|
224
|
-
|
262
|
+
# Shows a previously hidden channel.
|
263
|
+
# Use `hide` to hide a channel.
|
264
|
+
T::Sig::WithoutRuntime.sig { params(user_id: String).returns(StreamChat::StreamResponse) }
|
225
265
|
def show(user_id)
|
226
266
|
@client.post("#{url}/show", data: { user_id: user_id })
|
227
267
|
end
|
228
268
|
|
229
|
-
|
269
|
+
# Uploads a file.
|
270
|
+
#
|
271
|
+
# This functionality defaults to using the Stream CDN. If you would like, you can
|
272
|
+
# 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) }
|
230
274
|
def send_file(url, user, content_type = nil)
|
231
275
|
@client.send_file("#{self.url}/file", url, user, content_type)
|
232
276
|
end
|
233
277
|
|
234
|
-
|
278
|
+
# Uploads an image.
|
279
|
+
#
|
280
|
+
# Stream supported image types are: image/bmp, image/gif, image/jpeg, image/png, image/webp,
|
281
|
+
# image/heic, image/heic-sequence, image/heif, image/heif-sequence, image/svg+xml.
|
282
|
+
# You can set a more restrictive list for your application if needed.
|
283
|
+
# The maximum file size is 100MB.
|
284
|
+
T::Sig::WithoutRuntime.sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
|
235
285
|
def send_image(url, user, content_type = nil)
|
236
286
|
@client.send_file("#{self.url}/image", url, user, content_type)
|
237
287
|
end
|
238
288
|
|
239
|
-
|
289
|
+
# Deletes a file by file url.
|
290
|
+
T::Sig::WithoutRuntime.sig { params(url: String).returns(StreamChat::StreamResponse) }
|
240
291
|
def delete_file(url)
|
241
292
|
@client.delete("#{self.url}/file", params: { url: url })
|
242
293
|
end
|
243
294
|
|
244
|
-
|
295
|
+
# Deletes an image by image url.
|
296
|
+
T::Sig::WithoutRuntime.sig { params(url: String).returns(StreamChat::StreamResponse) }
|
245
297
|
def delete_image(url)
|
246
298
|
@client.delete("#{self.url}/image", params: { url: url })
|
247
299
|
end
|
248
300
|
|
249
301
|
private
|
250
302
|
|
251
|
-
sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
|
303
|
+
T::Sig::WithoutRuntime.sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
|
252
304
|
def add_user_id(payload, user_id)
|
253
305
|
payload.merge({ user: { id: user_id } })
|
254
306
|
end
|