stream-chat-ruby 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77a57822787deb58ec33e8b6a717e26edba13b3edbcb818abd55bc6bf86ac516
4
- data.tar.gz: 917861d1fafe2b42e7d849643f9a32941ac31039ff7a3de554229d77ca60aae4
3
+ metadata.gz: ea550365bc302aeb9097c2f2819a0dd6c5ead1fd1064a7c12842de4670e871d4
4
+ data.tar.gz: b01a528a334338edfd9f05e8f3aa40e682cabd3de40e6356b162f9f0cc791e64
5
5
  SHA512:
6
- metadata.gz: 03655565e49824a54aa9c27b9621a075ede33b0b063e46aa8bb493a490a776ec8dff273992502668862df8afb0dd23c5574742f83942ad873c2f9832ba7e6d2e
7
- data.tar.gz: 798df127e33162706774f4eb7a6e1e6d4d294b472db0a81c7a657049c2d4505cf089a9208c977aa2b17e9533be05c08764d378db895d05cfb10b5dd663e21af6
6
+ metadata.gz: 3f12aa7bec1853b9a91e3b9a63a6f296aca373bb8f24a719a0728959e68cbe10e4b440bc7056d730bfa36f3e2a0c5c1b4db1b566cc51159a09bad3eac4694747
7
+ data.tar.gz: 9982645b54641b15fd7d8deae0049d90aca66defcaba509e19be7f0c27dfd42fec8bba5221b0ca961251fc8c084c61a1793fcc689df853ae09a570b0358ac605
@@ -1,3 +1,8 @@
1
+ ## January 20th, 2021 - 2.4.0
2
+ - Add query_members to channel
3
+ - Use post endpoint for query channels instead of get
4
+ - Extract common code for sorting into a helper for query calls
5
+
1
6
  ## January 5th, 2021 - 2.3.0
2
7
  - Add check SQS helper
3
8
 
data/README.md CHANGED
@@ -28,9 +28,8 @@ gem install stream-chat-ruby
28
28
 
29
29
  ### Supported features
30
30
 
31
- - Chat channels
31
+ - Chat channel type, channels and members
32
32
  - Messages
33
- - Chat channel types
34
33
  - User management
35
34
  - Moderation API
36
35
  - Push configuration
@@ -131,6 +130,9 @@ chan.unban_user('bob-1')
131
130
 
132
131
  # Query channel state
133
132
  chan.query({'messages' => { 'limit' => 10, 'id_lte' => m1['id']}})
133
+
134
+ # Query channel members
135
+ chan.query_members({name: {'$autocomplete': 'test'}}, {last_created_at: -1}, offset: 5, limit: 5)
134
136
  ```
135
137
 
136
138
  ### Messages
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'stream-chat/errors'
4
+ require 'stream-chat/util'
4
5
 
5
6
  module StreamChat
6
7
  class Channel # rubocop:todo Metrics/ClassLength # rubocop:todo Style/Documentation
7
8
  attr_reader :id
8
9
  attr_reader :channel_type
9
10
  attr_reader :custom_data
11
+ attr_reader :members
10
12
 
11
13
  def initialize(client, channel_type, channel_id = nil, custom_data = nil)
12
14
  @channel_type = channel_type
@@ -59,6 +61,24 @@ module StreamChat
59
61
  state
60
62
  end
61
63
 
64
+ def query_members(filter_conditions: {}, sort: nil, **options)
65
+ params = {}.merge(options).merge({
66
+ id: @id,
67
+ type: @channel_type,
68
+ filter_conditions: filter_conditions,
69
+ sort: get_sort_fields(sort)
70
+ })
71
+
72
+ if @id == '' && @members.length.positive?
73
+ params['members'] = []
74
+ @members&.each do |m|
75
+ params['members'] << m['user'].nil? ? m['user_id'] : m['user']['id']
76
+ end
77
+ end
78
+
79
+ @client.get('members', params: { payload: params.to_json })
80
+ end
81
+
62
82
  def update(channel_data, update_message = nil)
63
83
  payload = { "data": channel_data, "message": update_message }
64
84
  @client.post(url, data: payload)
@@ -7,6 +7,7 @@ require 'jwt'
7
7
  require 'stream-chat/channel'
8
8
  require 'stream-chat/errors'
9
9
  require 'stream-chat/version'
10
+ require 'stream-chat/util'
10
11
 
11
12
  module StreamChat
12
13
  DEFAULT_BLOCKLIST = 'profanity_en_2020_v1'
@@ -166,28 +167,20 @@ module StreamChat
166
167
  end
167
168
 
168
169
  def query_users(filter_conditions, sort: nil, **options)
169
- sort_fields = []
170
- sort&.each do |k, v|
171
- sort_fields << { "field": k, "direction": v }
172
- end
173
170
  params = options.merge({
174
171
  "filter_conditions": filter_conditions,
175
- "sort": sort_fields
172
+ "sort": get_sort_fields(sort)
176
173
  })
177
174
  get('users', params: { "payload": params.to_json })
178
175
  end
179
176
 
180
177
  def query_channels(filter_conditions, sort: nil, **options)
181
- params = { "state": true, "watch": false, "presence": false }
182
- sort_fields = []
183
- sort&.each do |k, v|
184
- sort_fields << { "field": k, "direction": v }
185
- end
186
- params = params.merge(options).merge({
187
- "filter_conditions": filter_conditions,
188
- "sort": sort_fields
189
- })
190
- get('channels', params: { "payload": params.to_json })
178
+ data = { "state": true, "watch": false, "presence": false }
179
+ data = data.merge(options).merge({
180
+ filter_conditions: filter_conditions,
181
+ sort: get_sort_fields(sort)
182
+ })
183
+ post('channels', data: data)
191
184
  end
192
185
 
193
186
  def create_channel_type(data)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/util.rb
4
+
5
+ def get_sort_fields(sort)
6
+ sort_fields = []
7
+ sort&.each do |k, v|
8
+ sort_fields << { field: k, direction: v }
9
+ end
10
+ sort_fields
11
+ end
@@ -3,5 +3,5 @@
3
3
  # lib/version.rb
4
4
 
5
5
  module StreamChat
6
- VERSION = '2.3.0'
6
+ VERSION = '2.4.0'
7
7
  end
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: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mircea Cosbuc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -99,6 +99,7 @@ files:
99
99
  - lib/stream-chat/channel.rb
100
100
  - lib/stream-chat/client.rb
101
101
  - lib/stream-chat/errors.rb
102
+ - lib/stream-chat/util.rb
102
103
  - lib/stream-chat/version.rb
103
104
  - stream-chat.gemspec
104
105
  homepage: http://github.com/GetStream/stream-chat-ruby