stream-chat-ruby 2.20.0 → 2.21.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: 36870782d8439c010ce69c4593b2a9007b25ea0c18f748ea8bc809507378b2cd
4
- data.tar.gz: f5eeb52979560fa3be08059c71517dd5637ef317f78f9cf6ff27f2fabe8e3d61
3
+ metadata.gz: 800770eb3b23adf3a433b13784d19cd0d35c6bcc24d46e05687926d3e646fcad
4
+ data.tar.gz: 77c2fa8401f2d16e5aaaff3ba5e00b83f35388abc7875ba1bbd301fdf8e0f910
5
5
  SHA512:
6
- metadata.gz: cdffeaa2e783243ca32b098034b27c5175993d480dd34d78b7e6b2538e2c788fef8bbcf4c32357a2ab48e14edfcee056c4b3018a0f2cc4fb1e2a09a4b5c22fb3
7
- data.tar.gz: b2be01f9571c5ff952660fd046b35dd3fabe8920e3d3d58e50087253c74a57351ccee9b7fe5e0ccaa8fd154b64a20cd1046e6e4fd1662d1abbd1dc03ea1c5578
6
+ metadata.gz: e76da1cf10fb1f0a8d25f56eb77a0ad29898691a7cd9402efab643f483015adae91ba9344a21ff0d4e7ea233fda16ae2a73596afe8e52e9c342d86c9e62e4515
7
+ data.tar.gz: 7a898a5e6916344cecc340b175dbfb7e9e1884d3963465b593250320aad5b994213521932cb93e2e79f033f302d0f8748e2062ef494cb503c4979d0182db72a3
data/.rubocop.yml CHANGED
@@ -2,6 +2,9 @@ AllCops:
2
2
  DisabledByDefault: false
3
3
  NewCops: enable
4
4
  TargetRubyVersion: 2.5
5
+ Exclude:
6
+ - sorbet/**/*.rbi
7
+ - vendor/bundle/**/*
5
8
 
6
9
  Layout/LineLength:
7
10
  Enabled: false
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
+ ## [2.21.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.20.0...v2.21.0) (2022-03-03)
6
+
7
+
8
+ ### Features
9
+
10
+ * add options to delete message ([#80](https://github.com/GetStream/stream-chat-ruby/issues/80)) ([6a343e9](https://github.com/GetStream/stream-chat-ruby/commit/6a343e9fa9409150c27afc4246765f07bb12e571))
11
+ * add sorbet type checker ([#83](https://github.com/GetStream/stream-chat-ruby/issues/83)) ([f2fcee5](https://github.com/GetStream/stream-chat-ruby/commit/f2fcee58ecc0c3b4016721e997c42c44753bba9a))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * update app settings ([#86](https://github.com/GetStream/stream-chat-ruby/issues/86)) ([3f88185](https://github.com/GetStream/stream-chat-ruby/commit/3f88185117c5710e0b3e66f7f402f2c8969dec2f))
17
+
5
18
  ## [2.20.0](https://github.com/GetStream/stream-chat-ruby/compare/v2.19.0...v2.20.0) (2022-02-04)
6
19
 
7
20
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,64 @@
1
+
2
+ # :recycle: Contributing
3
+
4
+ We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
5
+
6
+ ## Getting started
7
+
8
+ ### Install dependencies
9
+
10
+ ```shell
11
+ $ bundle install --path vendor/bundle
12
+ ```
13
+
14
+ ### Run tests
15
+
16
+ ```shell
17
+ $ STREAM_KEY=my_api_key STREAM_SECRET=my_api_secret bundle exec rake spec
18
+ ```
19
+
20
+ ### Linters and type check
21
+
22
+ We use [Rubocop](https://github.com/rubocop/rubocop) for linting and [Sorbet](https://sorbet.org/) for type checking.
23
+
24
+ To run them:
25
+ ```shell
26
+ $ bundle exec rake rubocop
27
+ $ bundle exec srb tc
28
+ ```
29
+
30
+ These linters can be easily integrated into IDEs such as RubyMine or VS Code.
31
+
32
+ For VS Code, just install the basic Ruby extension which handles Rubocop ([`rebornix.ruby`](https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby)) and the official Sorbet one ([`sorbet.sorbet-vscode-extension`](https://marketplace.visualstudio.com/items?itemName=sorbet.sorbet-vscode-extension)).
33
+
34
+ Recommended settings:
35
+ ```json
36
+ {
37
+ "editor.formatOnSave": true,
38
+ "ruby.useBundler": true,
39
+ "ruby.lint": {
40
+ "rubocop": {
41
+ "useBundler": true, // enable rubocop via bundler
42
+ }
43
+ },
44
+ "ruby.format": "rubocop",
45
+ "ruby.useLanguageServer": true,
46
+ "sorbet.enabled": true
47
+ }
48
+ ```
49
+
50
+ ### Commit message convention
51
+
52
+ This repository follows a commit message convention in order to automatically generate the [CHANGELOG](./CHANGELOG.md). Make sure you follow the rules of [conventional commits](https://www.conventionalcommits.org/) when opening a pull request.
53
+
54
+ ### Releasing a new version (for Stream developers)
55
+
56
+ In order to release new version you need to be a maintainer of the library.
57
+
58
+ - Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-ruby/actions/workflows/initiate_release.yml)).
59
+
60
+ The job creates a pull request with the changelog. Check if it looks good.
61
+
62
+ - Merge the pull request.
63
+
64
+ Once the PR is merged, it automatically kicks off another job which will upload the Gem to RubyGems.org and creates a GitHub release.
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :dev do
9
9
  gem 'pry'
10
10
  gem 'pry-doc'
11
11
  gem 'rubocop', require: false
12
+ gem 'sorbet'
12
13
  end
13
14
 
14
15
  group :test do
data/README.md CHANGED
@@ -1,57 +1,64 @@
1
- # stream-chat-ruby
1
+ # Official Ruby SDK for [Stream Chat](https://getstream.io/chat/)
2
2
 
3
3
  [![build](https://github.com/GetStream/stream-chat-ruby/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-ruby/actions) [![Gem Version](https://badge.fury.io/rb/stream-chat-ruby.svg)](http://badge.fury.io/rb/stream-chat-ruby)
4
4
 
5
- stream-chat-ruby is the official Ruby client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
5
+ <p align="center">
6
+ <img src="./assets/logo.svg" width="50%" height="50%">
7
+ </p>
8
+ <p align="center">
9
+ Official Ruby API client for Stream Chat, a service for building chat applications.
10
+ <br />
11
+ <a href="https://getstream.io/chat/docs/"><strong>Explore the docs »</strong></a>
12
+ <br />
13
+ <br />
14
+ <a href="https://github.com/GetStream/rails-chat-example">Code Samples</a>
15
+ ·
16
+ <a href="https://github.com/GetStream/stream-chat-ruby/issues">Report Bug</a>
17
+ ·
18
+ <a href="https://github.com/GetStream/stream-chat-ruby/issues">Request Feature</a>
19
+ </p>
6
20
 
7
- You can sign up for a Stream account at https://getstream.io/chat/get_started/.
21
+ ## 📝 About Stream
8
22
 
9
- You can use this library to access chat API endpoints server-side. For the
10
- client-side integrations (web and mobile) have a look at the JavaScript, iOS and
11
- Android SDK libraries (https://getstream.io/chat/).
23
+ You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
12
24
 
13
- ### Installation
25
+ You can use this library to access chat API endpoints server-side.
14
26
 
15
- stream-chat-ruby supports:
27
+ For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/chat/)).
16
28
 
17
- - Ruby (2.5, 2.6, 2.7, 3.0, 3.1)
29
+ ## ⚙️ Installation
30
+
31
+ [`stream-chat-ruby`](https://rubygems.org/gems/stream-chat-ruby) supports:
18
32
 
19
- #### Install
33
+ - Ruby (2.5, 2.6, 2.7, 3.0, 3.1)
20
34
 
21
35
  ```bash
22
- gem install stream-chat-ruby
36
+ $ gem install stream-chat-ruby
23
37
  ```
24
38
 
25
- ### Documentation
26
-
27
- [Official API docs](https://getstream.io/chat/docs/)
28
-
29
- ### Supported features
30
-
31
- - Chat channel type, channels and members
32
- - Messages
33
- - User management
34
- - Moderation API
35
- - Push configuration
36
- - User devices
37
- - User search
38
- - Channel search
39
- - Blocklists
40
- - Export channels
41
-
42
- ### Import
39
+ ## ✨ Getting started
43
40
 
44
41
  ```ruby
45
42
  require 'stream-chat'
46
- ```
47
43
 
48
- ### Initialize client
49
-
50
- ```ruby
51
44
  client = StreamChat::Client.new(api_key='STREAM_KEY', api_secret='STREAM_SECRET')
52
45
  ```
53
46
 
54
- ### Generate a token for client side use
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
+
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
+ ---
52
+
53
+ > Additionally, in a future major version, we would like to enforce symbol hash keys during runtime to conform to Ruby best practises. It's a good idea to prepare your application for that.
54
+ > ```ruby
55
+ > # Wrong:
56
+ > user = { "user" => { "id" => "bob-1"}}
57
+ > # Correct:
58
+ > user = { :user => { :id => "bob-1" }}
59
+ > ```
60
+
61
+ ### Generate a token for client-side usage:
55
62
 
56
63
  ```ruby
57
64
  client.create_token('bob-1')
@@ -66,87 +73,58 @@ client.update_user({
66
73
  :name => 'Robert Tables'
67
74
  })
68
75
 
69
- # batch update is also supported
70
- jane = ...
71
- june = ...
76
+ # Batch update is also supported
77
+ jane = {:id => 'jane-1'}
78
+ june = {:id => 'june-1'}
72
79
  client.update_users([jane, june])
73
80
  ```
74
81
 
75
- ### Channel types CRUD
82
+ ### Channel types
76
83
 
77
84
  ```ruby
78
- # Create
79
85
  client.create_channel_type({
80
- 'name' => 'livechat',
81
- 'automod' => 'disabled',
82
- 'commands' => ['ban'],
83
- 'mutes' => true
86
+ :name => 'livechat',
87
+ :automod => 'disabled',
88
+ :commands => ['ban'],
89
+ :mutes => true
84
90
  })
85
91
 
86
- # Update
87
- client.update_channel_type('livechat', 'automod' => 'enabled'})
88
-
89
- # Get
90
- client.get_channel_type('livechat')
91
-
92
- # List
93
- client.list_channel_types
94
-
95
- # Delete
96
- client.delete_channel_type('livechat')
92
+ channel_types = client.list_channel_types()
97
93
  ```
98
94
 
99
95
  ### Channels
100
96
 
101
97
  ```ruby
102
98
  # Create a channel with members from the start
103
- chan = client.channel("messaging", channel_id: "bob-and-jane", data: {'members'=> ['bob-1', 'jane-77']})
99
+ chan = client.channel("messaging", channel_id: "bob-and-jane", data: {:members => ['bob-1', 'jane-77']})
104
100
  chan.create('bob-1')
105
101
 
106
102
  # Create a channel and then add members
107
103
  chan = client.channel("messaging", channel_id: "bob-and-jane")
108
104
  chan.create('bob-1')
109
105
  chan.add_members(['bob-1', 'jane-77'])
106
+ ```
110
107
 
111
- # Send messages
112
- m1 = chan.send_message({'text' => 'Hi Jane!'}, 'bob-1')
113
- m2 = chan.send_message({'text' => 'Hi Bob'}, 'jane-77')
114
-
115
- # Send replies
116
- r1 = chan.send_message({'text' => 'And a good day!', 'parent_id' => m1['id']}, 'bob-1')
117
-
118
- # Send reactions
119
- chan.send_reaction(m1['id'], {'type' => 'like'}, 'bob-1')
108
+ ### Reactions
109
+ ```ruby
110
+ chan.send_reaction(m1['id'], {:type => 'like'}, 'bob-1')
111
+ ```
120
112
 
121
- # Add/remove moderators
113
+ ### Moderation
114
+ ```ruby
122
115
  chan.add_moderators(['jane-77'])
123
116
  chan.demote_moderators(['bob-1'])
124
117
 
125
- # Add a ban with a timeout
126
118
  chan.ban_user('bob-1', timeout: 30)
127
119
 
128
- # Remove a ban
129
120
  chan.unban_user('bob-1')
130
-
131
- # Query channel state
132
- chan.query({'messages' => { 'limit' => 10, 'id_lte' => m1['id']}})
133
-
134
- # Update metadata (overwrite)
135
- chan.update({'motd' => 'one apple a day....'})
136
-
137
- # Update partial
138
- # 1. key-value pairs to set
139
- # 2. keys to unset (remove)
140
- chan.update_partial({color: 'blue', age: 30}, ['motd'])
141
-
142
- # Query channel members
143
- chan.query_members({name: {'$autocomplete': 'test'}}, sort: {last_created_at: -1}, offset: 5, limit: 5)
144
121
  ```
145
122
 
146
123
  ### Messages
147
124
 
148
125
  ```ruby
149
- # Delete a message from any channel by ID
126
+ m1 = chan.send_message({:text => 'Hi Jane!'}, 'bob-1')
127
+
150
128
  deleted_message = client.delete_message(r1['id'])
151
129
 
152
130
  ```
@@ -154,29 +132,23 @@ deleted_message = client.delete_message(r1['id'])
154
132
  ### Devices
155
133
 
156
134
  ```ruby
157
- # Add device
158
- jane_phone = client.add_device({'id' => 'iOS Device Token', 'push_provider' => push_provider.apn, 'user_id' => 'jane-77'})
135
+ jane_phone = client.add_device({:id => 'iOS Device Token', :push_provider => push_provider.apn, :user_id => 'jane-77'})
159
136
 
160
- # List devices
161
137
  client.get_devices('jane-77')
162
138
 
163
- # Remove device
164
139
  client.remove_device(jane_phone['id'], jane_phone['user_id'])
165
140
  ```
166
141
 
167
142
  ### Blocklists
168
143
 
169
144
  ```ruby
170
- # Create a blocklist
171
145
  client.create_blocklist('my_blocker', %w[fudge cream sugar])
172
146
 
173
- # Enable it on messaging channel type
147
+ # Enable it on 'messaging' channel type
174
148
  client.update_channel_type('messaging', blocklist: 'my_blocker', blocklist_behavior: 'block')
175
149
 
176
- # Get the details of the blocklist
177
150
  client.get_blocklist('my_blocker')
178
151
 
179
- # Delete the blocklist
180
152
  client.delete_blocklist('my_blocker')
181
153
  ```
182
154
 
@@ -184,7 +156,7 @@ client.delete_blocklist('my_blocker')
184
156
 
185
157
  ```ruby
186
158
  # Register an export
187
- response = client.export_channels({type: 'messaging', id: 'jane'})
159
+ response = client.export_channels({:type => 'messaging', :id => 'jane'})
188
160
 
189
161
  # Check completion
190
162
  status_response = client.get_export_channel_status(response['task_id'])
@@ -204,33 +176,13 @@ limits = client.get_rate_limits(server_side: true)
204
176
  limits = client.get_rate_limits(android: true, ios: true, endpoints: ['QueryChannels', 'SendMessage'])
205
177
  ```
206
178
 
207
- ### Example Rails application
208
-
209
- See [an example rails application using the Ruby SDK](https://github.com/GetStream/rails-chat-example).
210
-
211
- ### Contributing
212
-
213
- First, make sure you can run the test suite. Tests are run via rspec
214
-
215
- ```bash
216
- STREAM_KEY=my_api_key STREAM_SECRET=my_api_secret bundle exec rake spec
217
- ```
218
-
219
- This repository follows a commit message convention in order to automatically generate the [CHANGELOG](./CHANGELOG.md). Make sure you follow the rules of [conventional commits](https://www.conventionalcommits.org/) when opening a pull request.
220
-
221
- ### Releasing a new version
222
-
223
- In order to release new version you need to be a maintainer of the library.
224
-
225
- - Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-ruby/actions/workflows/initiate_release.yml)).
226
-
227
- The job creates a pull request with the changelog. Check if it looks good.
179
+ ## ✍️ Contributing
228
180
 
229
- - Merge the pull request.
181
+ We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.
230
182
 
231
- Once the PR is merged, it automatically kicks off another job which will upload the Gem to RubyGems.org and creates a GitHub release.
183
+ Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.
232
184
 
233
- ## We are hiring!
185
+ ## 🧑‍💻 We are hiring!
234
186
 
235
187
  We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.
236
188
  Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
@@ -1,49 +1,72 @@
1
+ # typed: strict
1
2
  # frozen_string_literal: true
2
3
 
4
+ require 'stream-chat/client'
3
5
  require 'stream-chat/errors'
4
6
  require 'stream-chat/util'
7
+ require 'stream-chat/types'
5
8
 
6
9
  module StreamChat
7
- class Channel # rubocop:todo Metrics/ClassLength # rubocop:todo Style/Documentation
10
+ class Channel
11
+ extend T::Sig
12
+ T::Configuration.default_checked_level = :never
13
+ # For now we disable runtime type checks.
14
+ # We will enable it with a major bump in the future,
15
+ # but for now, let's just run a static type check.
16
+
17
+ sig { returns(T.nilable(String)) }
8
18
  attr_reader :id
19
+
20
+ sig { returns(String) }
9
21
  attr_reader :channel_type
22
+
23
+ sig { returns(StringKeyHash) }
10
24
  attr_reader :custom_data
25
+
26
+ sig { returns(T::Array[StringKeyHash]) }
11
27
  attr_reader :members
12
28
 
29
+ sig { params(client: StreamChat::Client, channel_type: String, channel_id: T.nilable(String), custom_data: T.nilable(StringKeyHash)).void }
13
30
  def initialize(client, channel_type, channel_id = nil, custom_data = nil)
14
31
  @channel_type = channel_type
15
32
  @id = channel_id
16
- @cid = "#{@channel_type}:#{@id}"
33
+ @cid = T.let("#{@channel_type}:#{@id}", String)
17
34
  @client = client
18
- @custom_data = custom_data
19
- @custom_data = {} if @custom_data.nil?
35
+ @custom_data = T.let(custom_data || {}, StringKeyHash)
36
+ @members = T.let([], T::Array[StringKeyHash])
20
37
  end
21
38
 
39
+ sig { returns(String) }
22
40
  def url
23
41
  raise StreamChannelException, 'channel does not have an id' if @id.nil?
24
42
 
25
43
  "channels/#{@channel_type}/#{@id}"
26
44
  end
27
45
 
46
+ sig { params(message_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
28
47
  def get_messages(message_ids)
29
48
  @client.get("#{url}/messages", params: { 'ids' => message_ids.join(',') })
30
49
  end
31
50
 
51
+ sig { params(message: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
32
52
  def send_message(message, user_id)
33
53
  payload = { message: add_user_id(message, user_id) }
34
54
  @client.post("#{url}/message", data: payload)
35
55
  end
36
56
 
57
+ sig { params(event: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
37
58
  def send_event(event, user_id)
38
59
  payload = { 'event' => add_user_id(event, user_id) }
39
60
  @client.post("#{url}/event", data: payload)
40
61
  end
41
62
 
63
+ sig { params(message_id: String, reaction: StringKeyHash, user_id: String).returns(StreamChat::StreamResponse) }
42
64
  def send_reaction(message_id, reaction, user_id)
43
65
  payload = { reaction: add_user_id(reaction, user_id) }
44
66
  @client.post("messages/#{message_id}/reaction", data: payload)
45
67
  end
46
68
 
69
+ sig { params(message_id: String, reaction_type: String, user_id: String).returns(StreamChat::StreamResponse) }
47
70
  def delete_reaction(message_id, reaction_type, user_id)
48
71
  @client.delete(
49
72
  "messages/#{message_id}/reaction/#{reaction_type}",
@@ -51,11 +74,13 @@ module StreamChat
51
74
  )
52
75
  end
53
76
 
77
+ sig { params(user_id: String).returns(StreamChat::StreamResponse) }
54
78
  def create(user_id)
55
79
  @custom_data['created_by'] = { id: user_id }
56
80
  query(watch: false, state: false, presence: false)
57
81
  end
58
82
 
83
+ sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
59
84
  def query(**options)
60
85
  payload = { state: true, data: @custom_data }.merge(options)
61
86
  url = "channels/#{@channel_type}"
@@ -66,17 +91,18 @@ module StreamChat
66
91
  state
67
92
  end
68
93
 
94
+ sig { params(filter_conditions: StringKeyHash, sort: T.nilable(T::Hash[String, Integer]), options: T.untyped).returns(StreamChat::StreamResponse) }
69
95
  def query_members(filter_conditions = {}, sort: nil, **options)
70
96
  params = {}.merge(options).merge({
71
97
  id: @id,
72
98
  type: @channel_type,
73
99
  filter_conditions: filter_conditions,
74
- sort: get_sort_fields(sort)
100
+ sort: StreamChat.get_sort_fields(sort)
75
101
  })
76
102
 
77
103
  if @id == '' && @members.length.positive?
78
104
  params['members'] = []
79
- @members&.each do |m|
105
+ @members.each do |m|
80
106
  params['members'] << m['user'].nil? ? m['user_id'] : m['user']['id']
81
107
  end
82
108
  end
@@ -84,11 +110,13 @@ module StreamChat
84
110
  @client.get('members', params: { payload: params.to_json })
85
111
  end
86
112
 
113
+ sig { params(channel_data: T.nilable(StringKeyHash), update_message: T.nilable(StringKeyHash), options: T.untyped).returns(StreamChat::StreamResponse) }
87
114
  def update(channel_data, update_message = nil, **options)
88
115
  payload = { data: channel_data, message: update_message }.merge(options)
89
116
  @client.post(url, data: payload)
90
117
  end
91
118
 
119
+ sig { params(set: T.nilable(StringKeyHash), unset: T.nilable(T::Array[String])).returns(StreamChat::StreamResponse) }
92
120
  def update_partial(set = nil, unset = nil)
93
121
  raise StreamChannelException, 'set or unset is needed' if set.nil? && unset.nil?
94
122
 
@@ -96,107 +124,131 @@ module StreamChat
96
124
  @client.patch(url, data: payload)
97
125
  end
98
126
 
127
+ sig { returns(StreamChat::StreamResponse) }
99
128
  def delete
100
129
  @client.delete(url)
101
130
  end
102
131
 
132
+ sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
103
133
  def truncate(**options)
104
134
  @client.post("#{url}/truncate", data: options)
105
135
  end
106
136
 
137
+ sig { params(user_id: String, expiration: T.nilable(Integer)).returns(StreamChat::StreamResponse) }
107
138
  def mute(user_id, expiration = nil)
108
139
  data = { user_id: user_id, channel_cid: @cid }
109
140
  data['expiration'] = expiration if expiration
110
141
  @client.post('moderation/mute/channel', data: data)
111
142
  end
112
143
 
144
+ sig { params(user_id: String).returns(StreamChat::StreamResponse) }
113
145
  def unmute(user_id)
114
146
  @client.post('moderation/unmute/channel', data: { 'user_id' => user_id, 'channel_cid' => @cid })
115
147
  end
116
148
 
149
+ sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
117
150
  def add_members(user_ids, **options)
118
151
  payload = options.merge({ add_members: user_ids })
119
152
  update(nil, nil, **payload)
120
153
  end
121
154
 
155
+ sig { params(user_ids: T::Array[String], options: T.untyped).returns(StreamChat::StreamResponse) }
122
156
  def invite_members(user_ids, **options)
123
157
  payload = options.merge({ invites: user_ids })
124
158
  update(nil, nil, **payload)
125
159
  end
126
160
 
161
+ sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
127
162
  def accept_invite(user_id, **options)
128
163
  payload = options.merge({ user_id: user_id, accept_invite: true })
129
164
  update(nil, nil, **payload)
130
165
  end
131
166
 
167
+ sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
132
168
  def reject_invite(user_id, **options)
133
169
  payload = options.merge({ user_id: user_id, reject_invite: true })
134
170
  update(nil, nil, **payload)
135
171
  end
136
172
 
173
+ sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
137
174
  def add_moderators(user_ids)
138
175
  update(nil, nil, add_moderators: user_ids)
139
176
  end
140
177
 
178
+ sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
141
179
  def remove_members(user_ids)
142
180
  update(nil, nil, remove_members: user_ids)
143
181
  end
144
182
 
183
+ sig { params(members: T::Array[StringKeyHash], message: T.nilable(StringKeyHash)).returns(StreamChat::StreamResponse) }
145
184
  def assign_roles(members, message = nil)
146
185
  update(nil, message, assign_roles: members)
147
186
  end
148
187
 
188
+ sig { params(user_ids: T::Array[String]).returns(StreamChat::StreamResponse) }
149
189
  def demote_moderators(user_ids)
150
190
  update(nil, nil, demote_moderators: user_ids)
151
191
  end
152
192
 
193
+ sig { params(user_id: String, options: StringKeyHash).returns(StreamChat::StreamResponse) }
153
194
  def mark_read(user_id, **options)
154
195
  payload = add_user_id(options, user_id)
155
196
  @client.post("#{url}/read", data: payload)
156
197
  end
157
198
 
199
+ sig { params(parent_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
158
200
  def get_replies(parent_id, **options)
159
201
  @client.get("messages/#{parent_id}/replies", params: options)
160
202
  end
161
203
 
204
+ sig { params(message_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
162
205
  def get_reactions(message_id, **options)
163
206
  @client.get("messages/#{message_id}/reactions", params: options)
164
207
  end
165
208
 
209
+ sig { params(user_id: String, options: T.untyped).returns(StreamChat::StreamResponse) }
166
210
  def ban_user(user_id, **options)
167
211
  @client.ban_user(user_id, type: @channel_type, id: @id, **options)
168
212
  end
169
213
 
214
+ sig { params(user_id: String).returns(StreamChat::StreamResponse) }
170
215
  def unban_user(user_id)
171
216
  @client.unban_user(user_id, type: @channel_type, id: @id)
172
217
  end
173
218
 
219
+ sig { params(user_id: String).returns(StreamChat::StreamResponse) }
174
220
  def hide(user_id)
175
221
  @client.post("#{url}/hide", data: { user_id: user_id })
176
222
  end
177
223
 
224
+ sig { params(user_id: String).returns(StreamChat::StreamResponse) }
178
225
  def show(user_id)
179
226
  @client.post("#{url}/show", data: { user_id: user_id })
180
227
  end
181
228
 
229
+ sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
182
230
  def send_file(url, user, content_type = nil)
183
231
  @client.send_file("#{self.url}/file", url, user, content_type)
184
232
  end
185
233
 
234
+ sig { params(url: String, user: StringKeyHash, content_type: T.nilable(String)).returns(StreamChat::StreamResponse) }
186
235
  def send_image(url, user, content_type = nil)
187
236
  @client.send_file("#{self.url}/image", url, user, content_type)
188
237
  end
189
238
 
239
+ sig { params(url: String).returns(StreamChat::StreamResponse) }
190
240
  def delete_file(url)
191
241
  @client.delete("#{self.url}/file", params: { url: url })
192
242
  end
193
243
 
244
+ sig { params(url: String).returns(StreamChat::StreamResponse) }
194
245
  def delete_image(url)
195
246
  @client.delete("#{self.url}/image", params: { url: url })
196
247
  end
197
248
 
198
249
  private
199
250
 
251
+ sig { params(payload: StringKeyHash, user_id: String).returns(StringKeyHash) }
200
252
  def add_user_id(payload, user_id)
201
253
  payload.merge({ user: { id: user_id } })
202
254
  end