matrix_sdk 2.4.0 → 2.5.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: b8fabc9c9f840753916f52925807e2b6282a9fd17fbeedd63f284bd60a1aab86
4
- data.tar.gz: d0c2330e13f85036bbc0cecf1cde73fc2b960906c497b0cb7fdfe89b49499fd8
3
+ metadata.gz: 24a67aeb6af66f75480104c5c0dc44987e2fe54163ed96047da58bf091476752
4
+ data.tar.gz: e5935a94b430a1b195b55d748415cc0ad95ea649e32f5e97045cc82726dd2bd3
5
5
  SHA512:
6
- metadata.gz: 709c402251e87cd3cb650a7081d121eda551fec86f46dde8c92f2799491810ddb16bd8e44280ced09c0a5daa343385958d8ab19640348cffc2f97eafcb14bcaf
7
- data.tar.gz: 979fc101ef76e21023b9a6ce41649c0d144a2376429ff3ff6572b0384298d598a30f05ac64e0b2e98013180e7e4b0356a26da214df28ada4c5808e8ae02af331
6
+ metadata.gz: 1ea88ea4c76b573dad7b03aeba49e91b8f7c01040118c38032b49ca00cfbe687bd931c4e17387545e27df529f6ae06fc835ee964b5e79489fb0c5cf84186b35b
7
+ data.tar.gz: e2a6a5cd78e7629ffb2cc4af5ec9c9154f2f63db570479ebb2c6fa9aff13b7b231bea877d56694ae799019698af8d4a87394f88fa162dcb172dbbd1ede09fc8f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.5.0 - 2022-01-14
2
+
3
+ - Adds preliminary support for the Matrix v1.1 `client/v3` API
4
+ - Adds some support for knocking rooms
5
+ - Adds mutex synchronization on API requests to avoid some threading issues
6
+ - Fixes error on attempting to skip cache for certain requests (#19)
7
+ - Fixes inconsistency in MXID typing for the Client abstraction (#18 #20)
8
+ - Fixes missed autoloader entries for errors (#22)
9
+ - Fixes some potential issues arising from broken user-provided state data
10
+
1
11
  ## 2.4.0 - 2021-07-19
2
12
 
3
13
  - Adds support for matrix: URI's according to MSC2312
@@ -57,13 +57,14 @@ module MatrixSdk
57
57
  @validate_certificate = params.fetch(:validate_certificate, false)
58
58
  @transaction_id = params.fetch(:transaction_id, 0)
59
59
  @backoff_time = params.fetch(:backoff_time, 5000)
60
- @open_timeout = params.fetch(:open_timeout, 60)
61
- @read_timeout = params.fetch(:read_timeout, 240)
60
+ @open_timeout = params.fetch(:open_timeout, nil)
61
+ @read_timeout = params.fetch(:read_timeout, nil)
62
62
  @well_known = params.fetch(:well_known, {})
63
63
  @global_headers = DEFAULT_HEADERS.dup
64
64
  @global_headers.merge!(params.fetch(:global_headers)) if params.key? :global_headers
65
65
  @synapse = params.fetch(:synapse, true)
66
66
  @http = nil
67
+ @http_lock = Mutex.new
67
68
 
68
69
  ([params.fetch(:protocols, [:CS])].flatten - protocols).each do |proto|
69
70
  self.class.include MatrixSdk::Protocols.const_get(proto)
@@ -281,7 +282,9 @@ module MatrixSdk
281
282
 
282
283
  req_obj = construct_request(url: url, method: method, **options)
283
284
  print_http(req_obj, id: req_id)
284
- begin
285
+ response = duration = nil
286
+
287
+ @http_lock.synchronize do
285
288
  dur_start = Time.now
286
289
  response = http.request req_obj
287
290
  dur_end = Time.now
@@ -398,8 +401,8 @@ module MatrixSdk
398
401
  Net::HTTP.new(host, port)
399
402
  end
400
403
 
401
- @http.open_timeout = open_timeout
402
- @http.read_timeout = read_timeout
404
+ @http.open_timeout = open_timeout if open_timeout
405
+ @http.read_timeout = read_timeout if read_timeout
403
406
  @http.use_ssl = homeserver.scheme == 'https'
404
407
  @http.verify_mode = validate_certificate ? ::OpenSSL::SSL::VERIFY_PEER : ::OpenSSL::SSL::VERIFY_NONE
405
408
  @http.start
@@ -552,11 +552,14 @@ module MatrixSdk
552
552
  raise ArgumentError, 'Must be a room ID' unless room_id.room_id?
553
553
 
554
554
  room_id = room_id.to_s
555
- @rooms.fetch(room_id) do
555
+ ret = @rooms.fetch(room_id) do
556
556
  room = Room.new(self, room_id)
557
557
  @rooms[room_id] = room unless cache == :none
558
558
  room
559
559
  end
560
+ # Need to figure out a way to handle multiple types
561
+ ret = @rooms[room_id] = ret.to_space if ret.instance_variable_get :@room_type
562
+ ret
560
563
  end
561
564
 
562
565
  def listen_forever(timeout: 30, bad_sync_timeout: 5, sync_interval: 0, **params)
@@ -585,7 +588,7 @@ module MatrixSdk
585
588
  private
586
589
 
587
590
  def post_authentication(data)
588
- @mxid = data[:user_id]
591
+ @mxid = MXID.new data[:user_id]
589
592
  @api.access_token = data[:access_token]
590
593
  @api.device_id = data[:device_id]
591
594
  @api.homeserver = data[:home_server]
@@ -13,8 +13,10 @@ module MatrixSdk::Protocols::CS
13
13
  def client_api_versions
14
14
  (@client_api_versions ||= request(:get, :client, '/versions')).versions.tap do |vers|
15
15
  vers.instance_eval <<-'CODE', __FILE__, __LINE__ + 1
16
- def latest
17
- last
16
+ if !respond_to? :latest
17
+ def latest
18
+ last
19
+ end
18
20
  end
19
21
  CODE
20
22
  end
@@ -39,10 +41,20 @@ module MatrixSdk::Protocols::CS
39
41
  end
40
42
  end
41
43
 
44
+ # Gets the latest version of the client API
45
+ # @return [Symbol] :client_r0 / :client_v3 / etc
46
+ def client_api_latest
47
+ @client_api_latest ||= :client_v3 if client_api_versions.any? { |v| v.start_with? 'v1.1' }
48
+ @client_api_latest ||= :client_r0
49
+ rescue StandardError => e
50
+ logger.warn "Failed to look up supported client API, defaulting to r0. The error was #{e.class}: #{e}"
51
+ @client_api_latest ||= :client_r0
52
+ end
53
+
42
54
  # Gets the list of available methods for logging in
43
55
  # @return [Response]
44
56
  def allowed_login_methods
45
- request(:get, :client_r0, '/login')
57
+ request(:get, client_api_latest, '/login')
46
58
  end
47
59
 
48
60
  # Runs the client API /sync method
@@ -64,7 +76,7 @@ module MatrixSdk::Protocols::CS
64
76
  query[:timeout] = params.delete(:timeout_ms).to_i if params.key? :timeout_ms
65
77
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
66
78
 
67
- request(:get, :client_r0, '/sync', query: query)
79
+ request(:get, client_api_latest, '/sync', query: query)
68
80
  end
69
81
 
70
82
  # Registers a user using the client API /register endpoint
@@ -90,7 +102,7 @@ module MatrixSdk::Protocols::CS
90
102
  store_token = params.delete(:store_token) { !protocol?(:AS) }
91
103
  store_device_id = params.delete(:store_device_id) { store_token }
92
104
 
93
- request(:post, :client_r0, '/register', body: params, query: query).tap do |resp|
105
+ request(:post, client_api_latest, '/register', body: params, query: query).tap do |resp|
94
106
  @access_token = resp.token if resp.key?(:token) && store_token
95
107
  @device_id = resp.device_id if resp.key?(:device_id) && store_device_id
96
108
  end
@@ -113,7 +125,7 @@ module MatrixSdk::Protocols::CS
113
125
  next_link: next_link
114
126
  }.compact
115
127
 
116
- request(:post, :client_r0, '/register/email/requestToken', body: body)
128
+ request(:post, client_api_latest, '/register/email/requestToken', body: body)
117
129
  end
118
130
 
119
131
  # Requests to register a phone number to the current account
@@ -135,7 +147,7 @@ module MatrixSdk::Protocols::CS
135
147
  next_link: next_link
136
148
  }.compact
137
149
 
138
- request(:post, :client_r0, '/register/msisdn/requestToken', body: body)
150
+ request(:post, client_api_latest, '/register/msisdn/requestToken', body: body)
139
151
  end
140
152
 
141
153
  # Checks if a given username is available and valid for registering
@@ -148,7 +160,7 @@ module MatrixSdk::Protocols::CS
148
160
  # @return [Response]
149
161
  # @see https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-register-available
150
162
  def username_available?(username)
151
- request(:get, :client_r0, '/register/available', query: { username: username })
163
+ request(:get, client_api_latest, '/register/available', query: { username: username })
152
164
  end
153
165
 
154
166
  # Logs in using the client API /login endpoint, and optionally stores the resulting access for API usage
@@ -190,7 +202,7 @@ module MatrixSdk::Protocols::CS
190
202
  }.merge params
191
203
  data[:device_id] = device_id if device_id
192
204
 
193
- request(:post, :client_r0, '/login', body: data, query: query).tap do |resp|
205
+ request(:post, client_api_latest, '/login', body: data, query: query).tap do |resp|
194
206
  @access_token = resp.token if resp.key?(:token) && options[:store_token]
195
207
  @device_id = resp.device_id if resp.key?(:device_id) && options[:store_device_id]
196
208
  end
@@ -204,7 +216,7 @@ module MatrixSdk::Protocols::CS
204
216
  query = {}
205
217
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
206
218
 
207
- request(:post, :client_r0, '/logout', query: query)
219
+ request(:post, client_api_latest, '/logout', query: query)
208
220
  end
209
221
 
210
222
  # Logs out the currently logged in user
@@ -215,7 +227,7 @@ module MatrixSdk::Protocols::CS
215
227
  query = {}
216
228
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
217
229
 
218
- request(:post, :client_r0, '/logout/all', query: query)
230
+ request(:post, client_api_latest, '/logout/all', query: query)
219
231
  end
220
232
 
221
233
  # Changes the users password
@@ -235,7 +247,7 @@ module MatrixSdk::Protocols::CS
235
247
  auth: auth
236
248
  }
237
249
 
238
- request(:post, :client_r0, '/account/password', body: body, query: query)
250
+ request(:post, client_api_latest, '/account/password', body: body, query: query)
239
251
  end
240
252
 
241
253
  # Requests an authentication token based on an email address
@@ -255,7 +267,7 @@ module MatrixSdk::Protocols::CS
255
267
  next_link: next_link
256
268
  }.compact
257
269
 
258
- request(:post, :client_r0, '/account/password/email/requestToken', body: body)
270
+ request(:post, client_api_latest, '/account/password/email/requestToken', body: body)
259
271
  end
260
272
 
261
273
  # Requests an authentication token based on a phone number
@@ -277,7 +289,7 @@ module MatrixSdk::Protocols::CS
277
289
  next_link: next_link
278
290
  }.compact
279
291
 
280
- request(:post, :client_r0, '/account/password/msisdn/requestToken', body: body)
292
+ request(:post, client_api_latest, '/account/password/msisdn/requestToken', body: body)
281
293
  end
282
294
 
283
295
  # Deactivates the current account, logging out all connected devices and preventing future logins
@@ -293,14 +305,14 @@ module MatrixSdk::Protocols::CS
293
305
  id_server: id_server
294
306
  }.compact
295
307
 
296
- request(:post, :client_r0, '/account/deactivate', body: body)
308
+ request(:post, client_api_latest, '/account/deactivate', body: body)
297
309
  end
298
310
 
299
311
  def get_3pids(**params)
300
312
  query = {}
301
313
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
302
314
 
303
- request(:get, :client_r0, '/account/3pid', query: query)
315
+ request(:get, client_api_latest, '/account/3pid', query: query)
304
316
  end
305
317
 
306
318
  # Finishes a 3PID addition to the current user
@@ -318,7 +330,7 @@ module MatrixSdk::Protocols::CS
318
330
  auth: auth_data
319
331
  }.compact
320
332
 
321
- request(:post, :client_r0, '/account/3pid/add', body: body)
333
+ request(:post, client_api_latest, '/account/3pid/add', body: body)
322
334
  end
323
335
 
324
336
  # Finishes binding a 3PID to the current user
@@ -338,7 +350,7 @@ module MatrixSdk::Protocols::CS
338
350
  sid: session
339
351
  }
340
352
 
341
- request(:post, :client_r0, '/account/3pid/bind', body: body)
353
+ request(:post, client_api_latest, '/account/3pid/bind', body: body)
342
354
  end
343
355
 
344
356
  # Deletes a 3PID from the current user, this method might not unbind it from the identity server
@@ -356,7 +368,7 @@ module MatrixSdk::Protocols::CS
356
368
  medium: medium
357
369
  }
358
370
 
359
- request(:post, :client_r0, '/account/3pid/delete', body: body)
371
+ request(:post, client_api_latest, '/account/3pid/delete', body: body)
360
372
  end
361
373
 
362
374
  # Unbinds a 3PID from the current user
@@ -374,7 +386,7 @@ module MatrixSdk::Protocols::CS
374
386
  medium: medium
375
387
  }
376
388
 
377
- request(:post, :client_r0, '/account/3pid/unbind', body: body)
389
+ request(:post, client_api_latest, '/account/3pid/unbind', body: body)
378
390
  end
379
391
 
380
392
  # Gets the list of rooms joined by the current user
@@ -385,7 +397,7 @@ module MatrixSdk::Protocols::CS
385
397
  query = {}
386
398
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
387
399
 
388
- request(:get, :client_r0, '/joined_rooms', query: query)
400
+ request(:get, client_api_latest, '/joined_rooms', query: query)
389
401
  end
390
402
 
391
403
  # Gets the list of public rooms on a Matrix server
@@ -418,7 +430,7 @@ module MatrixSdk::Protocols::CS
418
430
  query = query.merge(params).compact
419
431
  end
420
432
 
421
- request(method, :client_r0, '/publicRooms', query: query, body: body)
433
+ request(method, client_api_latest, '/publicRooms', query: query, body: body)
422
434
  end
423
435
 
424
436
  # Creates a new room
@@ -440,7 +452,29 @@ module MatrixSdk::Protocols::CS
440
452
  content[:invite] = [params.delete(:invite)].flatten if params[:invite]
441
453
  content.merge! params
442
454
 
443
- request(:post, :client_r0, '/createRoom', body: content, query: query)
455
+ request(:post, client_api_latest, '/createRoom', body: content, query: query)
456
+ end
457
+
458
+ # Knock on a room
459
+ #
460
+ # @param id_or_alias [MXID,String] The room ID or Alias to knock
461
+ # @param reason [String] A reason for the knock, will be attached to the membership data
462
+ # @param server_name [String[]] A list of servers to perform the join through
463
+ # @param params [Hash] Extra room knock options
464
+ # @return [Response] A response hash with at least the parameter :room_id
465
+ # @see https://spec.matrix.org/v1.1/client-server-api/#knocking-on-rooms
466
+ # The Matrix Spec, for more information about the call and response
467
+ def knock_room(id_or_alias, reason: nil, server_name: nil, **params)
468
+ query = {}
469
+ query[:server_name] = server_name if server_name
470
+ query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
471
+
472
+ content = {}
473
+ content[:reason] = reason if reason
474
+
475
+ id_or_alias = ERB::Util.url_encode id_or_alias.to_s
476
+
477
+ request(:post, client_api_latest, "/knock/#{id_or_alias}", body: content, query: query)
444
478
  end
445
479
 
446
480
  # Joins a room
@@ -451,17 +485,17 @@ module MatrixSdk::Protocols::CS
451
485
  # @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-join-roomidoralias
452
486
  # The Matrix Spec, for more information about the call and response
453
487
  # @todo Add support for 3rd-party signed objects
454
- def join_room(id_or_alias, **params)
488
+ def join_room(id_or_alias, reason: nil, **params)
455
489
  query = {}
456
490
  query[:server_name] = params[:server_name] if params[:server_name]
457
491
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
458
492
 
459
- # id_or_alias = MXID.new id_or_alias.to_s unless id_or_alias.is_a? MXID
460
- # raise ArgumentError, 'Not a room ID or alias' unless id_or_alias.room?
493
+ content = {}
494
+ content[:reason] = reason if reason
461
495
 
462
496
  id_or_alias = ERB::Util.url_encode id_or_alias.to_s
463
497
 
464
- request(:post, :client_r0, "/join/#{id_or_alias}", query: query)
498
+ request(:post, client_api_latest, "/join/#{id_or_alias}", body: content, query: query)
465
499
  end
466
500
 
467
501
  # Sends a state event to a room
@@ -482,7 +516,7 @@ module MatrixSdk::Protocols::CS
482
516
  event_type = ERB::Util.url_encode event_type.to_s
483
517
  state_key = ERB::Util.url_encode params[:state_key].to_s if params.key? :state_key
484
518
 
485
- request(:put, :client_r0, "/rooms/#{room_id}/state/#{event_type}#{"/#{state_key}" unless state_key.nil?}", body: content, query: query)
519
+ request(:put, client_api_latest, "/rooms/#{room_id}/state/#{event_type}#{"/#{state_key}" unless state_key.nil?}", body: content, query: query)
486
520
  end
487
521
 
488
522
  # Sends a message event to a room
@@ -505,7 +539,7 @@ module MatrixSdk::Protocols::CS
505
539
  event_type = ERB::Util.url_encode event_type.to_s
506
540
  txn_id = ERB::Util.url_encode txn_id.to_s
507
541
 
508
- request(:put, :client_r0, "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body: content, query: query)
542
+ request(:put, client_api_latest, "/rooms/#{room_id}/send/#{event_type}/#{txn_id}", body: content, query: query)
509
543
  end
510
544
 
511
545
  # Redact an event in a room
@@ -531,7 +565,7 @@ module MatrixSdk::Protocols::CS
531
565
  event_id = ERB::Util.url_encode event_id.to_s
532
566
  txn_id = ERB::Util.url_encode txn_id.to_s
533
567
 
534
- request(:put, :client_r0, "/rooms/#{room_id}/redact/#{event_id}/#{txn_id}", body: content, query: query)
568
+ request(:put, client_api_latest, "/rooms/#{room_id}/redact/#{event_id}/#{txn_id}", body: content, query: query)
535
569
  end
536
570
 
537
571
  # Send a content message to a room
@@ -687,7 +721,7 @@ module MatrixSdk::Protocols::CS
687
721
  room_id = ERB::Util.url_encode room_id.to_s
688
722
  event_id = ERB::Util.url_encode event_id.to_s
689
723
 
690
- request(:post, :client_r0, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query)
724
+ request(:post, client_api_latest, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query)
691
725
  end
692
726
 
693
727
  # Retrieve additional messages in a room
@@ -714,7 +748,7 @@ module MatrixSdk::Protocols::CS
714
748
 
715
749
  room_id = ERB::Util.url_encode room_id.to_s
716
750
 
717
- request(:get, :client_r0, "/rooms/#{room_id}/messages", query: query)
751
+ request(:get, client_api_latest, "/rooms/#{room_id}/messages", query: query)
718
752
  end
719
753
 
720
754
  # Gets a specific event from a room
@@ -731,7 +765,7 @@ module MatrixSdk::Protocols::CS
731
765
  room_id = ERB::Util.url_encode room_id.to_s
732
766
  event_id = ERB::Util.url_encode event_id.to_s
733
767
 
734
- request(:get, :client_r0, "/rooms/#{room_id}/event/#{event_id}", query: query)
768
+ request(:get, client_api_latest, "/rooms/#{room_id}/event/#{event_id}", query: query)
735
769
  end
736
770
 
737
771
  # Reads the latest instance of a room state event
@@ -749,7 +783,7 @@ module MatrixSdk::Protocols::CS
749
783
  state_type = ERB::Util.url_encode state_type.to_s
750
784
  key = ERB::Util.url_encode key.to_s
751
785
 
752
- request(:get, :client_r0, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query)
786
+ request(:get, client_api_latest, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query)
753
787
  end
754
788
 
755
789
  # Retrieves all current state objects from a room
@@ -764,7 +798,7 @@ module MatrixSdk::Protocols::CS
764
798
 
765
799
  room_id = ERB::Util.url_encode room_id.to_s
766
800
 
767
- request(:get, :client_r0, "/rooms/#{room_id}/state", query: query)
801
+ request(:get, client_api_latest, "/rooms/#{room_id}/state", query: query)
768
802
  end
769
803
 
770
804
  # Retrieves number of events that happened just before and after the specified event
@@ -788,7 +822,7 @@ module MatrixSdk::Protocols::CS
788
822
  room_id = ERB::Util.url_encode room_id.to_s
789
823
  event_id = ERB::Util.url_encode event_id.to_s
790
824
 
791
- request(:get, :client_r0, "/rooms/#{room_id}/context/#{event_id}", query: query)
825
+ request(:get, client_api_latest, "/rooms/#{room_id}/context/#{event_id}", query: query)
792
826
  end
793
827
 
794
828
  ## Specialized getters for specced state
@@ -1125,7 +1159,7 @@ module MatrixSdk::Protocols::CS
1125
1159
 
1126
1160
  room_id = ERB::Util.url_encode room_id.to_s
1127
1161
 
1128
- request(:post, :client_r0, "/rooms/#{room_id}/leave", query: query)
1162
+ request(:post, client_api_latest, "/rooms/#{room_id}/leave", query: query)
1129
1163
  end
1130
1164
 
1131
1165
  def forget_room(room_id, **params)
@@ -1134,7 +1168,7 @@ module MatrixSdk::Protocols::CS
1134
1168
 
1135
1169
  room_id = ERB::Util.url_encode room_id.to_s
1136
1170
 
1137
- request(:post, :client_r0, "/rooms/#{room_id}/forget", query: query)
1171
+ request(:post, client_api_latest, "/rooms/#{room_id}/forget", query: query)
1138
1172
  end
1139
1173
 
1140
1174
  # Directly joins a room by ID
@@ -1154,7 +1188,7 @@ module MatrixSdk::Protocols::CS
1154
1188
 
1155
1189
  room_id = ERB::Util.url_encode room_id.to_s
1156
1190
 
1157
- request(:post, :client_r0, "/rooms/#{room_id}/join", body: body, query: query)
1191
+ request(:post, client_api_latest, "/rooms/#{room_id}/join", body: body, query: query)
1158
1192
  end
1159
1193
 
1160
1194
  def invite_user(room_id, user_id, **params)
@@ -1167,7 +1201,7 @@ module MatrixSdk::Protocols::CS
1167
1201
 
1168
1202
  room_id = ERB::Util.url_encode room_id.to_s
1169
1203
 
1170
- request(:post, :client_r0, "/rooms/#{room_id}/invite", body: content, query: query)
1204
+ request(:post, client_api_latest, "/rooms/#{room_id}/invite", body: content, query: query)
1171
1205
  end
1172
1206
 
1173
1207
  def kick_user(room_id, user_id, reason: '', **params)
@@ -1180,7 +1214,7 @@ module MatrixSdk::Protocols::CS
1180
1214
  }
1181
1215
  room_id = ERB::Util.url_encode room_id.to_s
1182
1216
 
1183
- request(:post, :client_r0, "/rooms/#{room_id}/kick", body: content, query: query)
1217
+ request(:post, client_api_latest, "/rooms/#{room_id}/kick", body: content, query: query)
1184
1218
  end
1185
1219
 
1186
1220
  def get_membership(room_id, user_id, **params)
@@ -1190,7 +1224,7 @@ module MatrixSdk::Protocols::CS
1190
1224
  room_id = ERB::Util.url_encode room_id.to_s
1191
1225
  user_id = ERB::Util.url_encode user_id.to_s
1192
1226
 
1193
- request(:get, :client_r0, "/rooms/#{room_id}/state/m.room.member/#{user_id}", query: query)
1227
+ request(:get, client_api_latest, "/rooms/#{room_id}/state/m.room.member/#{user_id}", query: query)
1194
1228
  end
1195
1229
 
1196
1230
  def set_membership(room_id, user_id, membership, reason: '', **params)
@@ -1214,7 +1248,7 @@ module MatrixSdk::Protocols::CS
1214
1248
  }
1215
1249
  room_id = ERB::Util.url_encode room_id.to_s
1216
1250
 
1217
- request(:post, :client_r0, "/rooms/#{room_id}/ban", body: content, query: query)
1251
+ request(:post, client_api_latest, "/rooms/#{room_id}/ban", body: content, query: query)
1218
1252
  end
1219
1253
 
1220
1254
  def unban_user(room_id, user_id, **params)
@@ -1226,7 +1260,7 @@ module MatrixSdk::Protocols::CS
1226
1260
  }
1227
1261
  room_id = ERB::Util.url_encode room_id.to_s
1228
1262
 
1229
- request(:post, :client_r0, "/rooms/#{room_id}/unban", body: content, query: query)
1263
+ request(:post, client_api_latest, "/rooms/#{room_id}/unban", body: content, query: query)
1230
1264
  end
1231
1265
 
1232
1266
  # Gets the room directory visibility status for a room
@@ -1241,7 +1275,7 @@ module MatrixSdk::Protocols::CS
1241
1275
 
1242
1276
  room_id = ERB::Util.url_encode room_id.to_s
1243
1277
 
1244
- request(:get, :client_r0, "/directory/list/room/#{room_id}", query: query)
1278
+ request(:get, client_api_latest, "/directory/list/room/#{room_id}", query: query)
1245
1279
  end
1246
1280
 
1247
1281
  # Sets the room directory visibility status for a room
@@ -1261,7 +1295,7 @@ module MatrixSdk::Protocols::CS
1261
1295
 
1262
1296
  room_id = ERB::Util.url_encode room_id.to_s
1263
1297
 
1264
- request(:put, :client_r0, "/directory/list/room/#{room_id}", body: body, query: query)
1298
+ request(:put, client_api_latest, "/directory/list/room/#{room_id}", body: body, query: query)
1265
1299
  end
1266
1300
 
1267
1301
  def get_user_tags(user_id, room_id, **params)
@@ -1271,7 +1305,7 @@ module MatrixSdk::Protocols::CS
1271
1305
  room_id = ERB::Util.url_encode room_id.to_s
1272
1306
  user_id = ERB::Util.url_encode user_id.to_s
1273
1307
 
1274
- request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags", query: query)
1308
+ request(:get, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags", query: query)
1275
1309
  end
1276
1310
 
1277
1311
  def remove_user_tag(user_id, room_id, tag, **params)
@@ -1282,7 +1316,7 @@ module MatrixSdk::Protocols::CS
1282
1316
  user_id = ERB::Util.url_encode user_id.to_s
1283
1317
  tag = ERB::Util.url_encode tag.to_s
1284
1318
 
1285
- request(:delete, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", query: query)
1319
+ request(:delete, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", query: query)
1286
1320
  end
1287
1321
 
1288
1322
  def add_user_tag(user_id, room_id, tag, **params)
@@ -1300,7 +1334,7 @@ module MatrixSdk::Protocols::CS
1300
1334
  user_id = ERB::Util.url_encode user_id.to_s
1301
1335
  tag = ERB::Util.url_encode tag.to_s
1302
1336
 
1303
- request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", body: content, query: query)
1337
+ request(:put, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/tags/#{tag}", body: content, query: query)
1304
1338
  end
1305
1339
 
1306
1340
  def get_account_data(user_id, type_key, **params)
@@ -1310,7 +1344,7 @@ module MatrixSdk::Protocols::CS
1310
1344
  user_id = ERB::Util.url_encode user_id.to_s
1311
1345
  type_key = ERB::Util.url_encode type_key.to_s
1312
1346
 
1313
- request(:get, :client_r0, "/user/#{user_id}/account_data/#{type_key}", query: query)
1347
+ request(:get, client_api_latest, "/user/#{user_id}/account_data/#{type_key}", query: query)
1314
1348
  end
1315
1349
 
1316
1350
  def set_account_data(user_id, type_key, account_data, **params)
@@ -1320,7 +1354,7 @@ module MatrixSdk::Protocols::CS
1320
1354
  user_id = ERB::Util.url_encode user_id.to_s
1321
1355
  type_key = ERB::Util.url_encode type_key.to_s
1322
1356
 
1323
- request(:put, :client_r0, "/user/#{user_id}/account_data/#{type_key}", body: account_data, query: query)
1357
+ request(:put, client_api_latest, "/user/#{user_id}/account_data/#{type_key}", body: account_data, query: query)
1324
1358
  end
1325
1359
 
1326
1360
  def get_room_account_data(user_id, room_id, type_key, **params)
@@ -1331,7 +1365,7 @@ module MatrixSdk::Protocols::CS
1331
1365
  room_id = ERB::Util.url_encode room_id.to_s
1332
1366
  type_key = ERB::Util.url_encode type_key.to_s
1333
1367
 
1334
- request(:get, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", query: query)
1368
+ request(:get, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", query: query)
1335
1369
  end
1336
1370
 
1337
1371
  def set_room_account_data(user_id, room_id, type_key, account_data, **params)
@@ -1342,7 +1376,7 @@ module MatrixSdk::Protocols::CS
1342
1376
  room_id = ERB::Util.url_encode room_id.to_s
1343
1377
  type_key = ERB::Util.url_encode type_key.to_s
1344
1378
 
1345
- request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query)
1379
+ request(:put, client_api_latest, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query)
1346
1380
  end
1347
1381
 
1348
1382
  # Retrieve user information
@@ -1354,7 +1388,7 @@ module MatrixSdk::Protocols::CS
1354
1388
  def whois(user_id)
1355
1389
  user_id = ERB::Util.url_encode user_id.to_s
1356
1390
 
1357
- request(:get, :client_r0, "/admin/whois/#{user_id}")
1391
+ request(:get, client_api_latest, "/admin/whois/#{user_id}")
1358
1392
  end
1359
1393
 
1360
1394
  def get_filter(user_id, filter_id, **params)
@@ -1364,7 +1398,7 @@ module MatrixSdk::Protocols::CS
1364
1398
  user_id = ERB::Util.url_encode user_id.to_s
1365
1399
  filter_id = ERB::Util.url_encode filter_id.to_s
1366
1400
 
1367
- request(:get, :client_r0, "/user/#{user_id}/filter/#{filter_id}", query: query)
1401
+ request(:get, client_api_latest, "/user/#{user_id}/filter/#{filter_id}", query: query)
1368
1402
  end
1369
1403
 
1370
1404
  # Creates a filter for future use
@@ -1377,7 +1411,7 @@ module MatrixSdk::Protocols::CS
1377
1411
 
1378
1412
  user_id = ERB::Util.url_encode user_id.to_s
1379
1413
 
1380
- request(:post, :client_r0, "/user/#{user_id}/filter", body: filter_params, query: query)
1414
+ request(:post, client_api_latest, "/user/#{user_id}/filter", body: filter_params, query: query)
1381
1415
  end
1382
1416
 
1383
1417
  def media_upload(content, content_type, **params)
@@ -1393,7 +1427,7 @@ module MatrixSdk::Protocols::CS
1393
1427
 
1394
1428
  user_id = ERB::Util.url_encode user_id.to_s
1395
1429
 
1396
- request(:get, :client_r0, "/profile/#{user_id}/displayname", query: query)
1430
+ request(:get, client_api_latest, "/profile/#{user_id}/displayname", query: query)
1397
1431
  end
1398
1432
 
1399
1433
  def set_display_name(user_id, display_name, **params)
@@ -1406,7 +1440,7 @@ module MatrixSdk::Protocols::CS
1406
1440
 
1407
1441
  user_id = ERB::Util.url_encode user_id.to_s
1408
1442
 
1409
- request(:put, :client_r0, "/profile/#{user_id}/displayname", body: content, query: query)
1443
+ request(:put, client_api_latest, "/profile/#{user_id}/displayname", body: content, query: query)
1410
1444
  end
1411
1445
 
1412
1446
  def get_avatar_url(user_id, **params)
@@ -1415,7 +1449,7 @@ module MatrixSdk::Protocols::CS
1415
1449
 
1416
1450
  user_id = ERB::Util.url_encode user_id.to_s
1417
1451
 
1418
- request(:get, :client_r0, "/profile/#{user_id}/avatar_url", query: query)
1452
+ request(:get, client_api_latest, "/profile/#{user_id}/avatar_url", query: query)
1419
1453
  end
1420
1454
 
1421
1455
  # Sets the avatar URL for a user
@@ -1449,7 +1483,7 @@ module MatrixSdk::Protocols::CS
1449
1483
 
1450
1484
  user_id = ERB::Util.url_encode user_id.to_s
1451
1485
 
1452
- request(:put, :client_r0, "/profile/#{user_id}/avatar_url", body: content, query: query)
1486
+ request(:put, client_api_latest, "/profile/#{user_id}/avatar_url", body: content, query: query)
1453
1487
  end
1454
1488
 
1455
1489
  # Gets the combined profile object of a user.
@@ -1466,7 +1500,7 @@ module MatrixSdk::Protocols::CS
1466
1500
 
1467
1501
  user_id = ERB::Util.url_encode user_id.to_s
1468
1502
 
1469
- request(:get, :client_r0, "/profile/#{user_id}", query: query)
1503
+ request(:get, client_api_latest, "/profile/#{user_id}", query: query)
1470
1504
  end
1471
1505
 
1472
1506
  # Gets TURN server connection information and credentials
@@ -1475,7 +1509,7 @@ module MatrixSdk::Protocols::CS
1475
1509
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-voip-turnserver
1476
1510
  # The Matrix Spec, for more information about the event and data
1477
1511
  def get_turn_server
1478
- request(:get, :client_r0, '/voip/turnServer')
1512
+ request(:get, client_api_latest, '/voip/turnServer')
1479
1513
  end
1480
1514
 
1481
1515
  # Sets the typing status for a user
@@ -1496,7 +1530,7 @@ module MatrixSdk::Protocols::CS
1496
1530
  timeout: timeout ? timeout * 1000 : nil
1497
1531
  }.compact
1498
1532
 
1499
- request(:put, :client_r0, "/rooms/#{room_id}/typing/#{user_id}", body: body)
1533
+ request(:put, client_api_latest, "/rooms/#{room_id}/typing/#{user_id}", body: body)
1500
1534
  end
1501
1535
 
1502
1536
  # Gets the presence status of a user
@@ -1508,7 +1542,7 @@ module MatrixSdk::Protocols::CS
1508
1542
  def get_presence_status(user_id)
1509
1543
  user_id = ERB::Util.url_encode user_id.to_s
1510
1544
 
1511
- request(:get, :client_r0, "/presence/#{user_id}/status")
1545
+ request(:get, client_api_latest, "/presence/#{user_id}/status")
1512
1546
  end
1513
1547
 
1514
1548
  # Sets the presence status of a user
@@ -1528,7 +1562,7 @@ module MatrixSdk::Protocols::CS
1528
1562
  status_msg: message
1529
1563
  }.compact
1530
1564
 
1531
- request(:put, :client_r0, "/presence/#{user_id}/status", body: body)
1565
+ request(:put, client_api_latest, "/presence/#{user_id}/status", body: body)
1532
1566
  end
1533
1567
 
1534
1568
  # Converts a Matrix content URL (mxc://) to a media download URL
@@ -1605,7 +1639,7 @@ module MatrixSdk::Protocols::CS
1605
1639
  messages: messages
1606
1640
  }.compact
1607
1641
 
1608
- request(:put, :client_r0, "/sendToDevice/#{event_type}/#{txn_id}", body: body)
1642
+ request(:put, client_api_latest, "/sendToDevice/#{event_type}/#{txn_id}", body: body)
1609
1643
  end
1610
1644
 
1611
1645
  # Gets the room ID for an alias
@@ -1618,7 +1652,7 @@ module MatrixSdk::Protocols::CS
1618
1652
 
1619
1653
  room_alias = ERB::Util.url_encode room_alias.to_s
1620
1654
 
1621
- request(:get, :client_r0, "/directory/room/#{room_alias}", query: query)
1655
+ request(:get, client_api_latest, "/directory/room/#{room_alias}", query: query)
1622
1656
  end
1623
1657
 
1624
1658
  # Sets the room ID for an alias
@@ -1635,7 +1669,7 @@ module MatrixSdk::Protocols::CS
1635
1669
  }
1636
1670
  room_alias = ERB::Util.url_encode room_alias.to_s
1637
1671
 
1638
- request(:put, :client_r0, "/directory/room/#{room_alias}", body: content, query: query)
1672
+ request(:put, client_api_latest, "/directory/room/#{room_alias}", body: content, query: query)
1639
1673
  end
1640
1674
 
1641
1675
  # Remove an alias from its room
@@ -1647,7 +1681,7 @@ module MatrixSdk::Protocols::CS
1647
1681
 
1648
1682
  room_alias = ERB::Util.url_encode room_alias.to_s
1649
1683
 
1650
- request(:delete, :client_r0, "/directory/room/#{room_alias}", query: query)
1684
+ request(:delete, client_api_latest, "/directory/room/#{room_alias}", query: query)
1651
1685
  end
1652
1686
 
1653
1687
  # Gets a list of all the members in a room
@@ -1661,7 +1695,7 @@ module MatrixSdk::Protocols::CS
1661
1695
 
1662
1696
  room_id = ERB::Util.url_encode room_id.to_s
1663
1697
 
1664
- request(:get, :client_r0, "/rooms/#{room_id}/members", query: query.merge(params))
1698
+ request(:get, client_api_latest, "/rooms/#{room_id}/members", query: query.merge(params))
1665
1699
  end
1666
1700
 
1667
1701
  # Gets a list of the joined members in a room
@@ -1676,7 +1710,7 @@ module MatrixSdk::Protocols::CS
1676
1710
 
1677
1711
  room_id = ERB::Util.url_encode room_id.to_s
1678
1712
 
1679
- request(:get, :client_r0, "/rooms/#{room_id}/joined_members", query: query)
1713
+ request(:get, client_api_latest, "/rooms/#{room_id}/joined_members", query: query)
1680
1714
  end
1681
1715
 
1682
1716
  # Gets a list of the current users registered devices
@@ -1684,7 +1718,7 @@ module MatrixSdk::Protocols::CS
1684
1718
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices
1685
1719
  # The Matrix Spec, for more information about the data
1686
1720
  def get_devices
1687
- request(:get, :client_r0, '/devices')
1721
+ request(:get, client_api_latest, '/devices')
1688
1722
  end
1689
1723
 
1690
1724
  # Gets the information about a certain client device
@@ -1695,7 +1729,7 @@ module MatrixSdk::Protocols::CS
1695
1729
  def get_device(device_id)
1696
1730
  device_id = ERB::Util.url_encode device_id.to_s
1697
1731
 
1698
- request(:get, :client_r0, "/devices/#{device_id}")
1732
+ request(:get, client_api_latest, "/devices/#{device_id}")
1699
1733
  end
1700
1734
 
1701
1735
  # Sets the metadata for a device
@@ -1706,7 +1740,7 @@ module MatrixSdk::Protocols::CS
1706
1740
  def set_device(device_id, display_name:)
1707
1741
  device_id = ERB::Util.url_encode device_id.to_s
1708
1742
 
1709
- request(:put, :client_r0, "/devices/#{device_id}", body: { display_name: display_name })
1743
+ request(:put, client_api_latest, "/devices/#{device_id}", body: { display_name: display_name })
1710
1744
  end
1711
1745
 
1712
1746
  # Removes a device from the current user
@@ -1719,7 +1753,7 @@ module MatrixSdk::Protocols::CS
1719
1753
  def delete_device(device_id, auth:)
1720
1754
  device_id = ERB::Util.url_encode device_id.to_s
1721
1755
 
1722
- request(:delete, :client_r0, "/devices/#{device_id}", body: { auth: auth })
1756
+ request(:delete, client_api_latest, "/devices/#{device_id}", body: { auth: auth })
1723
1757
  end
1724
1758
 
1725
1759
  # Run a query for device keys
@@ -1744,7 +1778,7 @@ module MatrixSdk::Protocols::CS
1744
1778
  body[:timeout] = params[:timeout_ms] if params.key? :timeout_ms
1745
1779
  body[:token] = token if token
1746
1780
 
1747
- request(:post, :client_r0, '/keys/query', body: body)
1781
+ request(:post, client_api_latest, '/keys/query', body: body)
1748
1782
  end
1749
1783
 
1750
1784
  # Claim one-time keys for pre-key messaging
@@ -1759,7 +1793,7 @@ module MatrixSdk::Protocols::CS
1759
1793
  one_time_keys: one_time_keys,
1760
1794
  timeout: timeout * 1000
1761
1795
  }
1762
- request(:post, :client_r0, '/keys/claim', body: body)
1796
+ request(:post, client_api_latest, '/keys/claim', body: body)
1763
1797
  end
1764
1798
 
1765
1799
  # Retrieve device key changes between two sync requests
@@ -1775,7 +1809,7 @@ module MatrixSdk::Protocols::CS
1775
1809
  to: to
1776
1810
  }
1777
1811
 
1778
- request(:get, :client_r0, '/keys/changes', query: query)
1812
+ request(:get, client_api_latest, '/keys/changes', query: query)
1779
1813
  end
1780
1814
 
1781
1815
  # Gets the list of registered pushers for the current user
@@ -1784,7 +1818,7 @@ module MatrixSdk::Protocols::CS
1784
1818
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers
1785
1819
  # The Matrix Spec, for more information about the parameters and data
1786
1820
  def get_pushers
1787
- request(:get, :client_r0, '/pushers')
1821
+ request(:get, client_api_latest, '/pushers')
1788
1822
  end
1789
1823
 
1790
1824
  # rubocop:disable Metrics/ParameterLists
@@ -1817,7 +1851,7 @@ module MatrixSdk::Protocols::CS
1817
1851
  append: params[:append]
1818
1852
  }.compact
1819
1853
 
1820
- request(:post, :client_r0, '/pushers/set', body: body)
1854
+ request(:post, client_api_latest, '/pushers/set', body: body)
1821
1855
  end
1822
1856
  # rubocop:enable Metrics/ParameterLists
1823
1857
 
@@ -1838,7 +1872,7 @@ module MatrixSdk::Protocols::CS
1838
1872
  only: only
1839
1873
  }.compact
1840
1874
 
1841
- request(:get, :client_r0, '/notifications', query: query)
1875
+ request(:get, client_api_latest, '/notifications', query: query)
1842
1876
  end
1843
1877
 
1844
1878
  # Retrieves the full list of registered push rules for the current user
@@ -1847,7 +1881,7 @@ module MatrixSdk::Protocols::CS
1847
1881
  # @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
1848
1882
  # The Matrix Spec, for more information about the parameters and data
1849
1883
  def get_pushrules
1850
- request(:get, :client_r0, '/pushrules/')
1884
+ request(:get, client_api_latest, '/pushrules/')
1851
1885
  end
1852
1886
 
1853
1887
  # Retrieves a single registered push rule for the current user
@@ -1863,7 +1897,7 @@ module MatrixSdk::Protocols::CS
1863
1897
  kind = ERB::Util.url_encode kind.to_s
1864
1898
  id = ERB::Util.url_encode id.to_s
1865
1899
 
1866
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}")
1900
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}")
1867
1901
  end
1868
1902
 
1869
1903
  # Checks if a push rule for the current user is enabled
@@ -1879,7 +1913,7 @@ module MatrixSdk::Protocols::CS
1879
1913
  kind = ERB::Util.url_encode kind.to_s
1880
1914
  id = ERB::Util.url_encode id.to_s
1881
1915
 
1882
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled")
1916
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/enabled")
1883
1917
  end
1884
1918
 
1885
1919
  # Enabled/Disables a specific push rule for the current user
@@ -1900,7 +1934,7 @@ module MatrixSdk::Protocols::CS
1900
1934
  enabled: enabled
1901
1935
  }
1902
1936
 
1903
- request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body)
1937
+ request(:put, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body)
1904
1938
  end
1905
1939
 
1906
1940
  # Gets the current list of actions for a specific push rule for the current user
@@ -1916,7 +1950,7 @@ module MatrixSdk::Protocols::CS
1916
1950
  kind = ERB::Util.url_encode kind.to_s
1917
1951
  id = ERB::Util.url_encode id.to_s
1918
1952
 
1919
- request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions")
1953
+ request(:get, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/actions")
1920
1954
  end
1921
1955
 
1922
1956
  # Replaces the list of actions for a push rule for the current user
@@ -1939,7 +1973,7 @@ module MatrixSdk::Protocols::CS
1939
1973
  actions: actions
1940
1974
  }
1941
1975
 
1942
- request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body)
1976
+ request(:put, client_api_latest, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body)
1943
1977
  end
1944
1978
 
1945
1979
  # Gets the MXID of the currently logged-in user
@@ -1948,7 +1982,7 @@ module MatrixSdk::Protocols::CS
1948
1982
  query = {}
1949
1983
  query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
1950
1984
 
1951
- request(:get, :client_r0, '/account/whoami', query: query)
1985
+ request(:get, client_api_latest, '/account/whoami', query: query)
1952
1986
  end
1953
1987
  end
1954
1988
  # rubocop:enable Metrics/ModuleLength
@@ -60,7 +60,9 @@ module MatrixSdk::Protocols::MSC
60
60
  # rubocop:disable Metrics/BlockLength
61
61
  thread = Thread.new(cancellation_token) do |ctx|
62
62
  print_http(req)
63
+ @http_lock.lock
63
64
  http.request req do |response|
65
+ @http_lock.unlock
64
66
  break unless ctx[:run]
65
67
 
66
68
  print_http(response, body: false)
@@ -136,6 +138,8 @@ module MatrixSdk::Protocols::MSC
136
138
  end
137
139
  break unless ctx[:run]
138
140
  end
141
+ rescue StandardError
142
+ @http_lock.unlock if @http_lock.owned?
139
143
  end
140
144
  # rubocop:enable Metrics/BlockLength
141
145
 
@@ -53,7 +53,7 @@ module MatrixSdk
53
53
  # @option data [String] :topic The current topic of the room
54
54
  # @option data [String,MXID] :canonical_alias The canonical alias of the room
55
55
  # @option data [Array(String,MXID)] :aliases All non-canonical aliases of the room
56
- # @option data [:invite,:public] :join_rule The join rule for the room
56
+ # @option data [:invite,:public,:knock] :join_rule The join rule for the room
57
57
  # @option data [:can_join,:forbidden] :guest_access The guest access setting for the room
58
58
  # @option data [Boolean] :world_readable If the room is readable by the entire world
59
59
  # @option data [Array(User)] :members The list of joined members
@@ -230,14 +230,14 @@ module MatrixSdk
230
230
  #
231
231
  # @return [:can_join,:forbidden] The current guest access right
232
232
  def guest_access
233
- client.api.get_room_guest_access(id)[:guest_access].to_sym
233
+ client.api.get_room_guest_access(id)[:guest_access]&.to_sym
234
234
  end
235
235
 
236
236
  # Gets the join rule for the room
237
237
  #
238
238
  # @return [:public,:knock,:invite,:private] The current join rule
239
239
  def join_rule
240
- client.api.get_room_join_rules(id)[:join_rule].to_sym
240
+ client.api.get_room_join_rules(id)[:join_rule]&.to_sym
241
241
  end
242
242
 
243
243
  # Checks if +guest_access+ is set to +:can_join+
@@ -250,11 +250,16 @@ module MatrixSdk
250
250
  join_rule == :invite
251
251
  end
252
252
 
253
+ # Checks if +join_rule+ is set to +:knock+
254
+ def knock_only?
255
+ join_rule == :knock
256
+ end
257
+
253
258
  # Gets the history visibility of the room
254
259
  #
255
260
  # @return [:invited,:joined,:shared,:world_readable] The current history visibility for the room
256
261
  def history_visibility
257
- client.api.get_room_state(id, 'm.room.history_visibility')[:history_visibility].to_sym
262
+ client.api.get_room_state(id, 'm.room.history_visibility')[:history_visibility]&.to_sym
258
263
  end
259
264
 
260
265
  # Checks if the room history is world readable
@@ -272,8 +277,8 @@ module MatrixSdk
272
277
  client.api.get_room_aliases(id).aliases
273
278
  rescue MatrixNotFoundError
274
279
  data = client.api.get_room_state_all(id)
275
- data.select { |chunk| chunk[:type] == 'm.room.aliases' && chunk.key?(:content) && chunk[:content].key?(:aliases) }
276
- .map { |chunk| chunk[:content][:aliases] }
280
+ data.select { |chunk| chunk[:type] == 'm.room.aliases' && !chunk.dig(*%i[content aliases]).nil? }
281
+ .map { |chunk| chunk.dig(*%i[content aliases]) }
277
282
  .flatten
278
283
  .compact
279
284
  end
@@ -737,7 +742,7 @@ module MatrixSdk
737
742
  user = MXID.new(user.to_s) unless user.is_a? MXID
738
743
  raise ArgumentError, 'Must provide a valid user or MXID' unless user.user?
739
744
 
740
- level = power_levels[:users][user.to_s.to_sym]
745
+ level = power_levels.dig(:users, user.to_s.to_sym)
741
746
  level = power_levels[:users_default] || 0 if level.nil? && use_default
742
747
  level
743
748
  end
@@ -812,8 +817,17 @@ module MatrixSdk
812
817
 
813
818
  if users
814
819
  data[:users] = {} unless data.key? :users
815
- data[:users].merge!(users)
816
- data[:users].delete_if { |_k, v| v.nil? }
820
+ users.each do |user, level|
821
+ user = user.id if user.is_a? User
822
+ user = MXID.new(user.to_s) unless user.is_a? MXID
823
+ raise ArgumentError, 'Must provide a valid user or MXID' unless user.user?
824
+
825
+ if level.nil?
826
+ data[:users].delete(user.to_s.to_sym)
827
+ else
828
+ data[:users][user.to_s.to_sym] = level
829
+ end
830
+ end
817
831
  end
818
832
 
819
833
  client.api.set_power_levels(id, data)
@@ -857,27 +871,27 @@ module MatrixSdk
857
871
  end
858
872
 
859
873
  def handle_room_name(event)
860
- tinycache_adapter.write(:name, event[:content][:name])
874
+ tinycache_adapter.write(:name, event.dig(*%i[content name]))
861
875
  end
862
876
 
863
877
  def handle_room_topic(event)
864
- tinycache_adapter.write(:topic, event[:content][:topic])
878
+ tinycache_adapter.write(:topic, event.dig(*%i[content topic]))
865
879
  end
866
880
 
867
881
  def handle_room_guest_access(event)
868
- tinycache_adapter.write(:guest_access, event[:content][:guest_access].to_sym)
882
+ tinycache_adapter.write(:guest_access, event.dig(*%i[content guest_access])&.to_sym)
869
883
  end
870
884
 
871
885
  def handle_room_join_rules(event)
872
- tinycache_adapter.write(:join_rule, event[:content][:join_rule].to_sym)
886
+ tinycache_adapter.write(:join_rule, event.dig(*%i[content join_rule])&.to_sym)
873
887
  end
874
888
 
875
889
  def handle_room_member(event)
876
890
  return unless client.cache == :all
877
891
 
878
- if event[:content][:membership] == 'join'
892
+ if event.dig(*%i[content membership]) == 'join'
879
893
  ensure_member(client.get_user(event[:state_key]).dup.tap do |u|
880
- u.instance_variable_set :@display_name, event[:content][:displayname]
894
+ u.instance_variable_set(:@display_name, event.dig(*%i[content displayname]))
881
895
  end)
882
896
  elsif tinycache_adapter.exist? :joined_members
883
897
  members = tinycache_adapter.read(:joined_members)
@@ -886,7 +900,7 @@ module MatrixSdk
886
900
  end
887
901
 
888
902
  def handle_room_canonical_alias(event)
889
- canonical_alias = tinycache_adapter.write :canonical_alias, event[:content][:alias]
903
+ canonical_alias = tinycache_adapter.write(:canonical_alias, event.dig(*%i[content alias]))
890
904
 
891
905
  data = tinycache_adapter.read(:aliases) || []
892
906
  data << canonical_alias
@@ -897,7 +911,7 @@ module MatrixSdk
897
911
  tinycache_adapter.write(:aliases, []) unless tinycache_adapter.exist? :aliases
898
912
 
899
913
  aliases = tinycache_adapter.read(:aliases) || []
900
- aliases.concat event[:content][:aliases]
914
+ aliases.concat(event.dig(*%i[content aliases]))
901
915
 
902
916
  tinycache_adapter.write(:aliases, aliases)
903
917
  end
@@ -10,7 +10,7 @@ module MatrixSdk::Rooms
10
10
  suggested_only: suggested_only,
11
11
  max_rooms_per_space: max_rooms
12
12
  }.compact
13
- rescue
13
+ rescue MatrixRequestError
14
14
  data = client.api.request :get, :client_r0, "/rooms/#{id}/spaces", query: {
15
15
  suggested_only: suggested_only,
16
16
  max_rooms_per_space: max_rooms
@@ -74,7 +74,7 @@ module MatrixSdk
74
74
  # @see MatrixSdk::Protocols::CS#get_presence_status
75
75
  # @note This information is not cached in the abstraction layer
76
76
  def presence
77
- raw_presence[:presence].to_sym
77
+ raw_presence[:presence]&.to_sym
78
78
  end
79
79
 
80
80
  # Sets the user's current presence status
@@ -133,7 +133,7 @@ module MatrixSdk
133
133
  # Returns all the current device keys for the user, retrieving them if necessary
134
134
  def device_keys
135
135
  @device_keys ||= client.api.keys_query(device_keys: { id => [] }).yield_self do |resp|
136
- resp[:device_keys][id.to_sym]
136
+ resp.dig(:device_keys, id.to_sym)
137
137
  end
138
138
  end
139
139
 
@@ -62,7 +62,7 @@ module MatrixSdk::Util
62
62
  method_names = build_method_names(method_name)
63
63
  tinycache_adapter_config[method_name] = {
64
64
  level: cache_level,
65
- expires: expires_in || 1 * 365 * 24 * 60 * 60 # 1 year
65
+ expires: expires_in || (1 * 365 * 24 * 60 * 60) # 1 year
66
66
  }
67
67
 
68
68
  helper = const_get(cache_helper_module_name)
@@ -99,8 +99,12 @@ module MatrixSdk::Util
99
99
  define_method(method_name) do |*args|
100
100
  unless_proc = opts[:unless].is_a?(Symbol) ? opts[:unless].to_proc : opts[:unless]
101
101
 
102
+ raise ArgumentError, 'Invalid proc provided (must have arity between 1..3)' if unless_proc && !(1..3).include?(unless_proc.arity)
103
+
102
104
  skip_cache = false
103
- skip_cache ||= unless_proc&.call(self, method_name, args)
105
+ skip_cache ||= unless_proc.call(self, method_name, args) if unless_proc&.arity == 3
106
+ skip_cache ||= unless_proc.call(method_name, args) if unless_proc&.arity == 2
107
+ skip_cache ||= unless_proc.call(args) if unless_proc&.arity == 1
104
108
  skip_cache ||= CACHE_LEVELS[client&.cache || :all] < CACHE_LEVELS[cache_level]
105
109
 
106
110
  if skip_cache
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MatrixSdk
4
- VERSION = '2.4.0'
4
+ VERSION = '2.5.0'
5
5
  end
data/lib/matrix_sdk.rb CHANGED
@@ -19,6 +19,11 @@ module MatrixSdk
19
19
 
20
20
  autoload :MatrixError, 'matrix_sdk/errors'
21
21
  autoload :MatrixRequestError, 'matrix_sdk/errors'
22
+ autoload :MatrixNotAuthorizedError, 'matrix_sdk/errors'
23
+ autoload :MatrixForbiddenError, 'matrix_sdk/errors'
24
+ autoload :MatrixNotFoundError, 'matrix_sdk/errors'
25
+ autoload :MatrixConflictError, 'matrix_sdk/errors'
26
+ autoload :MatrixTooManyRequestsError, 'matrix_sdk/errors'
22
27
  autoload :MatrixConnectionError, 'matrix_sdk/errors'
23
28
  autoload :MatrixTimeoutError, 'matrix_sdk/errors'
24
29
  autoload :MatrixUnexpectedResponseError, 'matrix_sdk/errors'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matrix_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Olofsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-19 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mocha
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.2.14
135
+ rubygems_version: 3.2.22
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: SDK for applications using the Matrix protocol