matrix_sdk 1.5.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/matrix_sdk/api.rb +35 -2
- data/lib/matrix_sdk/client.rb +222 -22
- data/lib/matrix_sdk/extensions.rb +1 -0
- data/lib/matrix_sdk/mxid.rb +24 -2
- data/lib/matrix_sdk/protocols/cs.rb +728 -52
- data/lib/matrix_sdk/response.rb +11 -0
- data/lib/matrix_sdk/room.rb +110 -13
- data/lib/matrix_sdk/user.rb +75 -8
- data/lib/matrix_sdk/version.rb +1 -1
- metadata +3 -3
data/lib/matrix_sdk/mxid.rb
CHANGED
@@ -17,9 +17,31 @@ module MatrixSdk
|
|
17
17
|
raise ArgumentError, 'Identifier is not a valid MXID' unless valid?
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
# Gets the homeserver part of the ID
|
21
|
+
#
|
22
|
+
# @example A simple MXID
|
23
|
+
# id = MXID.new('@alice:example.org')
|
24
|
+
# id.homeserver
|
25
|
+
# # => 'example.org'
|
26
|
+
#
|
27
|
+
# @example A fully qualified MXID
|
28
|
+
# id = MXID.new('@user:some.direct.domain:443')
|
29
|
+
# id.homeserver
|
30
|
+
# # => 'some.direct.domain:443'
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
def homeserver
|
21
34
|
port_s = port ? ':' + port.to_s : ''
|
22
|
-
|
35
|
+
domain ? domain + port_s : ''
|
36
|
+
end
|
37
|
+
|
38
|
+
# Gets the homserver part of the ID as a suffix (':homeserver')
|
39
|
+
def homeserver_suffix
|
40
|
+
':' + homeserver if domain
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"#{sigil}#{localpart}#{homeserver_suffix}"
|
23
45
|
end
|
24
46
|
|
25
47
|
# Returns the type of the ID
|
@@ -9,7 +9,7 @@ module MatrixSdk::Protocols::CS
|
|
9
9
|
# api.client_api_versions
|
10
10
|
# # => [ 'r0.1.0', 'r0.2.0', ...
|
11
11
|
# api.client_api_versions.latest
|
12
|
-
# # => '
|
12
|
+
# # => 'latest'
|
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
|
@@ -53,7 +53,7 @@ module MatrixSdk::Protocols::CS
|
|
53
53
|
# @option params [Boolean] :full_state Should the sync include the full state
|
54
54
|
# @option params [Boolean] :set_presence Should the sync set the user status to online
|
55
55
|
# @return [Response]
|
56
|
-
# @see https://matrix.org/docs/spec/client_server/
|
56
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-sync
|
57
57
|
# For more information on the parameters and what they mean
|
58
58
|
def sync(timeout: 30.0, **params)
|
59
59
|
query = params.select do |k, _v|
|
@@ -80,7 +80,7 @@ module MatrixSdk::Protocols::CS
|
|
80
80
|
# @option params [Boolean] :store_token (true) Should the resulting access token be stored for the API
|
81
81
|
# @option params [Boolean] :store_device_id (store_token value) Should the resulting device ID be stored for the API
|
82
82
|
# @return [Response]
|
83
|
-
# @see https://matrix.org/docs/spec/client_server/
|
83
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-register
|
84
84
|
# For options that are permitted in this call
|
85
85
|
def register(kind: 'user', **params)
|
86
86
|
query = {}
|
@@ -96,6 +96,48 @@ module MatrixSdk::Protocols::CS
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
# Requests to register an email address to the current account
|
100
|
+
#
|
101
|
+
# @param secret [String] A random string containing only the characters `[0-9a-zA-Z.=_-]`
|
102
|
+
# @param email [String] The email address to register
|
103
|
+
# @param attempt [Integer] The current attempt count to register the email+secret combo, increase to send another verification email
|
104
|
+
# @param next_link [String,URI] An URL to redirect to after verification is finished
|
105
|
+
# @return [Response] A hash containing the :sid id for the current request
|
106
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-register-email-requesttoken
|
107
|
+
# For options that are permitted in this call
|
108
|
+
def register_email_request(secret, email, attempt: 1, next_link: nil)
|
109
|
+
body = {
|
110
|
+
client_secret: secret,
|
111
|
+
email: email,
|
112
|
+
send_attempt: attempt,
|
113
|
+
next_link: next_link
|
114
|
+
}.compact
|
115
|
+
|
116
|
+
request(:post, :client_r0, '/register/email/requestToken', body: body)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Requests to register a phone number to the current account
|
120
|
+
#
|
121
|
+
# @param secret [String] A random string containing only the characters `[0-9a-zA-Z.=_-]`
|
122
|
+
# @param country [String] The two-letter ISO-3166-1 country identifier of the destination country of the number
|
123
|
+
# @param number [String] The phone number itself
|
124
|
+
# @param attempt [Integer] The current attempt count to register the email+secret combo, increase to send another verification email
|
125
|
+
# @param next_link [String,URI] An URL to redirect to after verification is finished
|
126
|
+
# @return [Response] A hash containing the :sid id for the current request
|
127
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-register-email-requesttoken
|
128
|
+
# For options that are permitted in this call
|
129
|
+
def register_msisdn_request(secret, country, number, attempt: 1, next_link: nil)
|
130
|
+
body = {
|
131
|
+
client_secret: secret,
|
132
|
+
country: country,
|
133
|
+
phone_number: number,
|
134
|
+
send_attempt: attempt,
|
135
|
+
next_link: next_link
|
136
|
+
}.compact
|
137
|
+
|
138
|
+
request(:post, :client_r0, '/register/msisdn/requestToken', body: body)
|
139
|
+
end
|
140
|
+
|
99
141
|
# Checks if a given username is available and valid for registering
|
100
142
|
#
|
101
143
|
# @example Verifying a username
|
@@ -132,7 +174,7 @@ module MatrixSdk::Protocols::CS
|
|
132
174
|
# @option params [String] :initial_device_display_name (USER_AGENT) The device display name to specify for this login attempt
|
133
175
|
# @option params [String] :device_id The device ID to set on the login
|
134
176
|
# @return [Response] A response hash with the parameters :user_id, :access_token, :home_server, and :device_id.
|
135
|
-
# @see https://matrix.org/docs/spec/client_server/
|
177
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-login
|
136
178
|
# The Matrix Spec, for more information about the call and response
|
137
179
|
def login(login_type: 'm.login.password', **params)
|
138
180
|
query = {}
|
@@ -154,9 +196,9 @@ module MatrixSdk::Protocols::CS
|
|
154
196
|
end
|
155
197
|
end
|
156
198
|
|
157
|
-
# Logs out the currently logged in user
|
199
|
+
# Logs out the currently logged in device for the current user
|
158
200
|
# @return [Response] An empty response if the logout was successful
|
159
|
-
# @see https://matrix.org/docs/spec/client_server/
|
201
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-logout
|
160
202
|
# The Matrix Spec, for more information about the call and response
|
161
203
|
def logout(**params)
|
162
204
|
query = {}
|
@@ -165,6 +207,176 @@ module MatrixSdk::Protocols::CS
|
|
165
207
|
request(:post, :client_r0, '/logout', query: query)
|
166
208
|
end
|
167
209
|
|
210
|
+
# Logs out the currently logged in user
|
211
|
+
# @return [Response] An empty response if the logout was successful
|
212
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-logout-all
|
213
|
+
# The Matrix Spec, for more information about the call and response
|
214
|
+
def logout_all(**params)
|
215
|
+
query = {}
|
216
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
217
|
+
|
218
|
+
request(:post, :client_r0, '/logout/all', query: query)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Changes the users password
|
222
|
+
# @param new_password [String] The new password
|
223
|
+
# @param auth [Hash] An auth object returned from an interactive auth query
|
224
|
+
# @return [Response] An empty response if the password change was successful
|
225
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-password
|
226
|
+
# The Matrix Spec, for more information about the call and response
|
227
|
+
def change_password(new_password, auth:, **params)
|
228
|
+
query = {}
|
229
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
230
|
+
|
231
|
+
# raise Error unless auth.is_a?(Hash) && auth.key? :type
|
232
|
+
|
233
|
+
body = {
|
234
|
+
new_password: new_password,
|
235
|
+
auth: auth
|
236
|
+
}
|
237
|
+
|
238
|
+
request(:post, :client_r0, '/account/password', body: body, query: query)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Requests an authentication token based on an email address
|
242
|
+
#
|
243
|
+
# @param secret [String] A random string containing only the characters `[0-9a-zA-Z.=_-]`
|
244
|
+
# @param email [String] The email address to register
|
245
|
+
# @param attempt [Integer] The current attempt count to register the email+secret combo, increase to send another verification email
|
246
|
+
# @param next_link [String,URI] An URL to redirect to after verification is finished
|
247
|
+
# @return [Response] A hash containing the :sid id for the current request
|
248
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-password-email-requesttoken
|
249
|
+
# For options that are permitted in this call
|
250
|
+
def request_email_login_token(secret, email, attempt: 1, next_link: nil)
|
251
|
+
body = {
|
252
|
+
client_secret: secret,
|
253
|
+
email: email,
|
254
|
+
send_attempt: attempt,
|
255
|
+
next_link: next_link
|
256
|
+
}.compact
|
257
|
+
|
258
|
+
request(:post, :client_r0, '/account/password/email/requestToken', body: body)
|
259
|
+
end
|
260
|
+
|
261
|
+
# Requests an authentication token based on a phone number
|
262
|
+
#
|
263
|
+
# @param secret [String] A random string containing only the characters `[0-9a-zA-Z.=_-]`
|
264
|
+
# @param country [String] The two-letter ISO-3166-1 country identifier of the destination country of the number
|
265
|
+
# @param number [String] The phone number itself
|
266
|
+
# @param attempt [Integer] The current attempt count to register the email+secret combo, increase to send another verification email
|
267
|
+
# @param next_link [String,URI] An URL to redirect to after verification is finished
|
268
|
+
# @return [Response] A hash containing the :sid id for the current request
|
269
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-password-msisdn-requesttoken
|
270
|
+
# For options that are permitted in this call
|
271
|
+
def request_msisdn_login_token(secret, country, number, attempt: 1, next_link: nil)
|
272
|
+
body = {
|
273
|
+
client_secret: secret,
|
274
|
+
country: country,
|
275
|
+
phone_number: number,
|
276
|
+
send_attempt: attempt,
|
277
|
+
next_link: next_link
|
278
|
+
}.compact
|
279
|
+
|
280
|
+
request(:post, :client_r0, '/account/password/msisdn/requestToken', body: body)
|
281
|
+
end
|
282
|
+
|
283
|
+
# Deactivates the current account, logging out all connected devices and preventing future logins
|
284
|
+
#
|
285
|
+
# @param auth_data [Hash] Interactive authentication data to verify the request
|
286
|
+
# @param id_server [String] Override the ID server to unbind all 3PIDs from
|
287
|
+
# @return [Response]
|
288
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-deactivate
|
289
|
+
# For options that are permitted in this call
|
290
|
+
def deactivate_account(auth_data, id_server: nil)
|
291
|
+
body = {
|
292
|
+
auth: auth_data,
|
293
|
+
id_server: id_server
|
294
|
+
}.compact
|
295
|
+
|
296
|
+
request(:post, :client_r0, '/account/deactivate', body: body)
|
297
|
+
end
|
298
|
+
|
299
|
+
def get_3pids(**params)
|
300
|
+
query = {}
|
301
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
302
|
+
|
303
|
+
request(:get, :client_r0, '/account/3pid', query: query)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Finishes a 3PID addition to the current user
|
307
|
+
#
|
308
|
+
# @param secret [String] The shared secret with the HS
|
309
|
+
# @param session [String] The session ID to finish the request for
|
310
|
+
# @param auth_data [Hash] Interactive authentication data to verify the request
|
311
|
+
# @return [Response]
|
312
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-add
|
313
|
+
# For options that are permitted in this call
|
314
|
+
def complete_3pid_add(secret:, session:, auth_data: nil)
|
315
|
+
body = {
|
316
|
+
sid: session,
|
317
|
+
client_secret: secret,
|
318
|
+
auth: auth_data
|
319
|
+
}.compact
|
320
|
+
|
321
|
+
request(:post, :client_r0, '/account/3pid/add', body: body)
|
322
|
+
end
|
323
|
+
|
324
|
+
# Finishes binding a 3PID to the current user
|
325
|
+
#
|
326
|
+
# @param secret [String] The shared secret with the identity server
|
327
|
+
# @param id_server [String] The identity server being acted against
|
328
|
+
# @param id_server_token [String] A previous identity server token
|
329
|
+
# @param session [String] The session ID to finish the bind for
|
330
|
+
# @return [Response]
|
331
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-bind
|
332
|
+
# For options that are permitted in this call
|
333
|
+
def bind_3pid(secret:, id_server:, id_server_token:, session:)
|
334
|
+
body = {
|
335
|
+
client_secret: secret,
|
336
|
+
id_server: id_server,
|
337
|
+
id_server_token: id_server_token,
|
338
|
+
sid: session
|
339
|
+
}
|
340
|
+
|
341
|
+
request(:post, :client_r0, '/account/3pid/bind', body: body)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Deletes a 3PID from the current user, this method might not unbind it from the identity server
|
345
|
+
#
|
346
|
+
# @param medium [:email,:msisdn] The medium of 3PID being removed
|
347
|
+
# @param address [String] The address that is to be removed
|
348
|
+
# @param id_server [String] The identity server being acted against
|
349
|
+
# @return [Response]
|
350
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-delete
|
351
|
+
# For options that are permitted in this call
|
352
|
+
def delete_3pid(medium, address, id_server:)
|
353
|
+
body = {
|
354
|
+
address: address,
|
355
|
+
id_server: id_server,
|
356
|
+
medium: medium
|
357
|
+
}
|
358
|
+
|
359
|
+
request(:post, :client_r0, '/account/3pid/delete', body: body)
|
360
|
+
end
|
361
|
+
|
362
|
+
# Unbinds a 3PID from the current user
|
363
|
+
#
|
364
|
+
# @param medium [:email,:msisdn] The medium of 3PID being removed
|
365
|
+
# @param address [String] The address that is to be removed
|
366
|
+
# @param id_server [String] The identity server being acted against
|
367
|
+
# @return [Response]
|
368
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-account-3pid-unbind
|
369
|
+
# For options that are permitted in this call
|
370
|
+
def unbind_3pid(medium, address, id_server:)
|
371
|
+
body = {
|
372
|
+
address: address,
|
373
|
+
id_server: id_server,
|
374
|
+
medium: medium
|
375
|
+
}
|
376
|
+
|
377
|
+
request(:post, :client_r0, '/account/3pid/unbind', body: body)
|
378
|
+
end
|
379
|
+
|
168
380
|
# Gets the list of rooms joined by the current user
|
169
381
|
#
|
170
382
|
# @return [Response] An array of room IDs under the key :joined_rooms
|
@@ -215,7 +427,7 @@ module MatrixSdk::Protocols::CS
|
|
215
427
|
# @option params [String] :room_alias A room alias to apply on creation
|
216
428
|
# @option params [Boolean] :invite Should the room be created invite-only
|
217
429
|
# @return [Response] A response hash with ...
|
218
|
-
# @see https://matrix.org/docs/spec/client_server/
|
430
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-createroom
|
219
431
|
# The Matrix Spec, for more information about the call and response
|
220
432
|
def create_room(visibility: :public, **params)
|
221
433
|
query = {}
|
@@ -236,7 +448,7 @@ module MatrixSdk::Protocols::CS
|
|
236
448
|
# @param params [Hash] Extra room join options
|
237
449
|
# @option params [String[]] :server_name A list of servers to perform the join through
|
238
450
|
# @return [Response] A response hash with the parameter :room_id
|
239
|
-
# @see https://matrix.org/docs/spec/client_server/
|
451
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#post-matrix-client-r0-join-roomidoralias
|
240
452
|
# The Matrix Spec, for more information about the call and response
|
241
453
|
# @todo Add support for 3rd-party signed objects
|
242
454
|
def join_room(id_or_alias, **params)
|
@@ -259,8 +471,8 @@ module MatrixSdk::Protocols::CS
|
|
259
471
|
# @param params [Hash] Options for the request
|
260
472
|
# @option params [String] :state_key The state key of the event, if there is one
|
261
473
|
# @return [Response] A response hash with the parameter :event_id
|
262
|
-
# @see https://matrix.org/docs/spec/client_server/
|
263
|
-
# https://matrix.org/docs/spec/client_server/
|
474
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#put-matrix-client-r0-rooms-roomid-state-eventtype-statekey
|
475
|
+
# https://matrix.org/docs/spec/client_server/latest.html#put-matrix-client-r0-rooms-roomid-state-eventtype
|
264
476
|
# The Matrix Spec, for more information about the call and response
|
265
477
|
def send_state_event(room_id, event_type, content, **params)
|
266
478
|
query = {}
|
@@ -280,7 +492,7 @@ module MatrixSdk::Protocols::CS
|
|
280
492
|
# @param params [Hash] Options for the request
|
281
493
|
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
|
282
494
|
# @return [Response] A response hash with the parameter :event_id
|
283
|
-
# @see https://matrix.org/docs/spec/client_server/
|
495
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid
|
284
496
|
# The Matrix Spec, for more information about the call and response
|
285
497
|
def send_message_event(room_id, event_type, content, **params)
|
286
498
|
query = {}
|
@@ -303,7 +515,7 @@ module MatrixSdk::Protocols::CS
|
|
303
515
|
# @option params [String] :reason The reason for the redaction
|
304
516
|
# @option params [Integer] :txn_id The ID of the transaction, or automatically generated
|
305
517
|
# @return [Response] A response hash with the parameter :event_id
|
306
|
-
# @see https://matrix.org/docs/spec/client_server/
|
518
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid
|
307
519
|
# The Matrix Spec, for more information about the call and response
|
308
520
|
def redact_event(room_id, event_id, **params)
|
309
521
|
query = {}
|
@@ -358,10 +570,10 @@ module MatrixSdk::Protocols::CS
|
|
358
570
|
# @option params [Hash] :extra_content Extra data to insert into the content hash
|
359
571
|
# @return [Response] A response hash with the parameter :event_id
|
360
572
|
# @see send_message_event For more information on the underlying call
|
361
|
-
# @see https://matrix.org/docs/spec/client_server/
|
362
|
-
# https://matrix.org/docs/spec/client_server/
|
363
|
-
# https://matrix.org/docs/spec/client_server/
|
364
|
-
# https://matrix.org/docs/spec/client_server/
|
573
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-image
|
574
|
+
# https://matrix.org/docs/spec/client_server/latest.html#m-file
|
575
|
+
# https://matrix.org/docs/spec/client_server/latest.html#m-video
|
576
|
+
# https://matrix.org/docs/spec/client_server/latest.html#m-audio
|
365
577
|
# The Matrix Spec, for more information about the call and response
|
366
578
|
def send_content(room_id, url, name, msg_type, **params)
|
367
579
|
content = {
|
@@ -386,7 +598,7 @@ module MatrixSdk::Protocols::CS
|
|
386
598
|
# @option params [Hash] :thumbnail_info Image information about the location thumbnail
|
387
599
|
# @return [Response] A response hash with the parameter :event_id
|
388
600
|
# @see send_message_event For more information on the underlying call
|
389
|
-
# @see https://matrix.org/docs/spec/client_server/
|
601
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-location
|
390
602
|
# The Matrix Spec, for more information about the call and response
|
391
603
|
def send_location(room_id, geo_uri, name, **params)
|
392
604
|
content = {
|
@@ -409,7 +621,7 @@ module MatrixSdk::Protocols::CS
|
|
409
621
|
# @option params [String] :msg_type ('m.text') The message type to send
|
410
622
|
# @return [Response] A response hash with the parameter :event_id
|
411
623
|
# @see send_message_event For more information on the underlying call
|
412
|
-
# @see https://matrix.org/docs/spec/client_server/
|
624
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-text
|
413
625
|
# The Matrix Spec, for more information about the call and response
|
414
626
|
def send_message(room_id, message, **params)
|
415
627
|
content = {
|
@@ -427,7 +639,7 @@ module MatrixSdk::Protocols::CS
|
|
427
639
|
# @option params [String] :msg_type ('m.emote') The message type to send
|
428
640
|
# @return [Response] A response hash with the parameter :event_id
|
429
641
|
# @see send_message_event For more information on the underlying call
|
430
|
-
# @see https://matrix.org/docs/spec/client_server/
|
642
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-emote
|
431
643
|
# The Matrix Spec, for more information about the call and response
|
432
644
|
def send_emote(room_id, emote, **params)
|
433
645
|
content = {
|
@@ -445,7 +657,7 @@ module MatrixSdk::Protocols::CS
|
|
445
657
|
# @option params [String] :msg_type ('m.notice') The message type to send
|
446
658
|
# @return [Response] A response hash with the parameter :event_id
|
447
659
|
# @see send_message_event For more information on the underlying call
|
448
|
-
# @see https://matrix.org/docs/spec/client_server/
|
660
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-notice
|
449
661
|
# The Matrix Spec, for more information about the call and response
|
450
662
|
def send_notice(room_id, notice, **params)
|
451
663
|
content = {
|
@@ -455,6 +667,29 @@ module MatrixSdk::Protocols::CS
|
|
455
667
|
send_message_event(room_id, 'm.room.message', content, params)
|
456
668
|
end
|
457
669
|
|
670
|
+
# Report an event in a room
|
671
|
+
#
|
672
|
+
# @param room_id [MXID,String] The room ID in which the event occurred
|
673
|
+
# @param room_id [MXID,String] The event ID to report
|
674
|
+
# @param score [Integer] The severity of the report, range between -100 - 0
|
675
|
+
# @param reason [String] The reason for the report
|
676
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-report-eventid
|
677
|
+
# The Matrix Spec, for more information about the call and response
|
678
|
+
def report_event(room_id, event_id, score:, reason:, **params)
|
679
|
+
query = {}
|
680
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
681
|
+
|
682
|
+
body = {
|
683
|
+
score: score,
|
684
|
+
reason: reason
|
685
|
+
}
|
686
|
+
|
687
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
688
|
+
event_id = ERB::Util.url_encode event_id.to_s
|
689
|
+
|
690
|
+
request(:post, :client_r0, "/rooms/#{room_id}/report/#{event_id}", body: body, query: query)
|
691
|
+
end
|
692
|
+
|
458
693
|
# Retrieve additional messages in a room
|
459
694
|
#
|
460
695
|
# @param room_id [MXID,String] The room ID to retrieve messages for
|
@@ -465,7 +700,7 @@ module MatrixSdk::Protocols::CS
|
|
465
700
|
# @option params [String] :to A token to limit retrieval to
|
466
701
|
# @option params [String] :filter A filter to limit the retrieval to
|
467
702
|
# @return [Response] A response hash with the message information containing :start, :end, and :chunk fields
|
468
|
-
# @see https://matrix.org/docs/spec/client_server/
|
703
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages
|
469
704
|
# The Matrix Spec, for more information about the call and response
|
470
705
|
def get_room_messages(room_id, token, direction, limit: 10, **params)
|
471
706
|
query = {
|
@@ -482,14 +717,31 @@ module MatrixSdk::Protocols::CS
|
|
482
717
|
request(:get, :client_r0, "/rooms/#{room_id}/messages", query: query)
|
483
718
|
end
|
484
719
|
|
720
|
+
# Gets a specific event from a room
|
721
|
+
#
|
722
|
+
# @param room_id [MXID,String] The room ID to read from
|
723
|
+
# @param event_id [MXID,String] The event ID to retrieve
|
724
|
+
# @return [Response] A response hash with the contents of the event
|
725
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-rooms-roomid-event-eventid
|
726
|
+
# The Matrix Spec, for more information about the call and response
|
727
|
+
def get_room_event(room_id, event_id, **params)
|
728
|
+
query = {}
|
729
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
730
|
+
|
731
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
732
|
+
event_id = ERB::Util.url_encode event_id.to_s
|
733
|
+
|
734
|
+
request(:get, :client_r0, "/rooms/#{room_id}/event/#{event_id}", query: query)
|
735
|
+
end
|
736
|
+
|
485
737
|
# Reads the latest instance of a room state event
|
486
738
|
#
|
487
739
|
# @param room_id [MXID,String] The room ID to read from
|
488
740
|
# @param state_type [String] The state type to read
|
489
741
|
# @return [Response] A response hash with the contents of the state event
|
490
|
-
# @see https://matrix.org/docs/spec/client_server/
|
742
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-state-eventtype
|
491
743
|
# The Matrix Spec, for more information about the call and response
|
492
|
-
def get_room_state(room_id, state_type
|
744
|
+
def get_room_state(room_id, state_type, key: nil, **params)
|
493
745
|
query = {}
|
494
746
|
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
495
747
|
|
@@ -497,7 +749,22 @@ module MatrixSdk::Protocols::CS
|
|
497
749
|
state_type = ERB::Util.url_encode state_type.to_s
|
498
750
|
key = ERB::Util.url_encode key.to_s
|
499
751
|
|
500
|
-
request(:get, :client_r0, "/rooms/#{room_id}/state
|
752
|
+
request(:get, :client_r0, "/rooms/#{room_id}/state/#{state_type}#{key.empty? ? nil : "/#{key}"}", query: query)
|
753
|
+
end
|
754
|
+
|
755
|
+
# Retrieves all current state objects from a room
|
756
|
+
#
|
757
|
+
# @param room_id [MXID,String] The room ID to read from
|
758
|
+
# @return [Response] A response hash with the contents of all state events
|
759
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-rooms-roomid-event-eventid
|
760
|
+
# The Matrix Spec, for more information about the call and response
|
761
|
+
def get_room_state_all(room_id, **params)
|
762
|
+
query = {}
|
763
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
764
|
+
|
765
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
766
|
+
|
767
|
+
request(:get, :client_r0, "/rooms/#{room_id}/state", query: query)
|
501
768
|
end
|
502
769
|
|
503
770
|
## Specialized getters for specced state
|
@@ -510,7 +777,7 @@ module MatrixSdk::Protocols::CS
|
|
510
777
|
# @return [Response] A response hash with the parameter :name
|
511
778
|
# @raise [MatrixNotFoundError] Raised if no name has been set on the room
|
512
779
|
# @see get_room_state
|
513
|
-
# @see https://matrix.org/docs/spec/client_server/
|
780
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-name
|
514
781
|
# The Matrix Spec, for more information about the event and data
|
515
782
|
def get_room_name(room_id, **params)
|
516
783
|
get_room_state(room_id, 'm.room.name', params)
|
@@ -522,7 +789,7 @@ module MatrixSdk::Protocols::CS
|
|
522
789
|
# @param [String] name The new name of the room
|
523
790
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
524
791
|
# @return [Response] The resulting state event
|
525
|
-
# @see https://matrix.org/docs/spec/client_server/
|
792
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-name
|
526
793
|
# The Matrix Spec, for more information about the event and data
|
527
794
|
def set_room_name(room_id, name, **params)
|
528
795
|
content = {
|
@@ -538,7 +805,7 @@ module MatrixSdk::Protocols::CS
|
|
538
805
|
# @return [Response] A response hash with the parameter :topic
|
539
806
|
# @raise [MatrixNotFoundError] Raised if no topic has been set on the room
|
540
807
|
# @see get_room_state
|
541
|
-
# @see https://matrix.org/docs/spec/client_server/
|
808
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-topic
|
542
809
|
# The Matrix Spec, for more information about the event and data
|
543
810
|
def get_room_topic(room_id, **params)
|
544
811
|
get_room_state(room_id, 'm.room.topic', params)
|
@@ -550,7 +817,7 @@ module MatrixSdk::Protocols::CS
|
|
550
817
|
# @param [String] topic The new topic of the room
|
551
818
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
552
819
|
# @return [Response] The resulting state event
|
553
|
-
# @see https://matrix.org/docs/spec/client_server/
|
820
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-topic
|
554
821
|
# The Matrix Spec, for more information about the event and data
|
555
822
|
def set_room_topic(room_id, topic, **params)
|
556
823
|
content = {
|
@@ -566,7 +833,7 @@ module MatrixSdk::Protocols::CS
|
|
566
833
|
# @return [Response] A response hash with the parameters :url and (optionally) :info
|
567
834
|
# @raise [MatrixNotFoundError] Raised if no avatar has been set on the room
|
568
835
|
# @see get_room_state
|
569
|
-
# @see https://matrix.org/docs/spec/client_server/
|
836
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-avatar
|
570
837
|
# The Matrix Spec, for more information about the event and data
|
571
838
|
def get_room_avatar(room_id, **params)
|
572
839
|
get_room_state(room_id, 'm.room.avatar', params)
|
@@ -578,7 +845,7 @@ module MatrixSdk::Protocols::CS
|
|
578
845
|
# @param [String,URI] url The new avatar URL for the room
|
579
846
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
580
847
|
# @return [Response] The resulting state event
|
581
|
-
# @see https://matrix.org/docs/spec/client_server/
|
848
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-avatar
|
582
849
|
# The Matrix Spec, for more information about the event and data
|
583
850
|
def set_room_avatar(room_id, url, **params)
|
584
851
|
content = {
|
@@ -594,7 +861,7 @@ module MatrixSdk::Protocols::CS
|
|
594
861
|
# @return [Response] A response hash with the array :aliases
|
595
862
|
# @raise [MatrixNotFoundError] Raised if no aliases has been set on the room by the specified HS
|
596
863
|
# @see get_room_state
|
597
|
-
# @see https://matrix.org/docs/spec/client_server/
|
864
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-avatar
|
598
865
|
# The Matrix Spec, for more information about the event and data
|
599
866
|
# @example Looking up aliases for a room
|
600
867
|
# api.get_room_aliases('!QtykxKocfZaZOUrTwp:matrix.org')
|
@@ -621,7 +888,7 @@ module MatrixSdk::Protocols::CS
|
|
621
888
|
# @return [Response] A response hash with the array :pinned
|
622
889
|
# @raise [MatrixNotFoundError] Raised if no aliases has been set on the room by the specified HS
|
623
890
|
# @see get_room_state
|
624
|
-
# @see https://matrix.org/docs/spec/client_server/
|
891
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-pinned-events
|
625
892
|
# The Matrix Spec, for more information about the event and data
|
626
893
|
def get_room_pinned_events(room_id, **params)
|
627
894
|
get_room_state(room_id, 'm.room.pinned_events', params)
|
@@ -633,7 +900,7 @@ module MatrixSdk::Protocols::CS
|
|
633
900
|
# @param [Array[String]] events The new list of events to set as pinned
|
634
901
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
635
902
|
# @return [Response] The resulting state event
|
636
|
-
# @see https://matrix.org/docs/spec/client_server/
|
903
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-pinned-events
|
637
904
|
# The Matrix Spec, for more information about the event and data
|
638
905
|
def set_room_pinned_events(room_id, events, **params)
|
639
906
|
content = {
|
@@ -648,7 +915,7 @@ module MatrixSdk::Protocols::CS
|
|
648
915
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
649
916
|
# @return [Response] A response hash with power level information
|
650
917
|
# @see get_room_state
|
651
|
-
# @see https://matrix.org/docs/spec/client_server/
|
918
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-power-levels
|
652
919
|
# The Matrix Spec, for more information about the event and data
|
653
920
|
def get_room_power_levels(room_id, **params)
|
654
921
|
get_room_state(room_id, 'm.room.power_levels', params)
|
@@ -661,7 +928,7 @@ module MatrixSdk::Protocols::CS
|
|
661
928
|
# @param [Hash] content The new power level configuration
|
662
929
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
663
930
|
# @return [Response] The resulting state event
|
664
|
-
# @see https://matrix.org/docs/spec/client_server/
|
931
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-power-levels
|
665
932
|
# The Matrix Spec, for more information about the event and data
|
666
933
|
def set_room_power_levels(room_id, content, **params)
|
667
934
|
content[:events] = {} unless content.key? :events
|
@@ -675,7 +942,7 @@ module MatrixSdk::Protocols::CS
|
|
675
942
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
676
943
|
# @return [Response] A response hash with the key :join_rule
|
677
944
|
# @see get_room_state
|
678
|
-
# @see https://matrix.org/docs/spec/client_server/
|
945
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-join-rules
|
679
946
|
# The Matrix Spec, for more information about the event and data
|
680
947
|
def get_room_join_rules(room_id, **params)
|
681
948
|
get_room_state(room_id, 'm.room.join_rules', params)
|
@@ -687,7 +954,7 @@ module MatrixSdk::Protocols::CS
|
|
687
954
|
# @param [String,Symbol] join_rule The new join rule setting (Currently only public and invite are implemented)
|
688
955
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
689
956
|
# @return [Response] The resulting state event
|
690
|
-
# @see https://matrix.org/docs/spec/client_server/
|
957
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-join-rules
|
691
958
|
# The Matrix Spec, for more information about the event and data
|
692
959
|
def set_room_join_rules(room_id, join_rule, **params)
|
693
960
|
content = {
|
@@ -703,7 +970,7 @@ module MatrixSdk::Protocols::CS
|
|
703
970
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
704
971
|
# @return [Response] A response hash with the key :guest_acces, either :can_join or :forbidden
|
705
972
|
# @see get_room_state
|
706
|
-
# @see https://matrix.org/docs/spec/client_server/
|
973
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-guest-access
|
707
974
|
# The Matrix Spec, for more information about the event and data
|
708
975
|
def get_room_guest_access(room_id, **params)
|
709
976
|
get_room_state(room_id, 'm.room.guest_access', params)
|
@@ -715,7 +982,7 @@ module MatrixSdk::Protocols::CS
|
|
715
982
|
# @param [:can_join, :forbidden] guest_access The new guest access setting for the room
|
716
983
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
717
984
|
# @return [Response] The resulting state event
|
718
|
-
# @see https://matrix.org/docs/spec/client_server/
|
985
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-guest-access
|
719
986
|
# The Matrix Spec, for more information about the event and data
|
720
987
|
def set_room_guest_access(room_id, guest_access, **params)
|
721
988
|
content = {
|
@@ -731,7 +998,7 @@ module MatrixSdk::Protocols::CS
|
|
731
998
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
732
999
|
# @return [Response] A response hash with the configuration the room was created for
|
733
1000
|
# @see get_room_state
|
734
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1001
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-create
|
735
1002
|
# The Matrix Spec, for more information about the event and data
|
736
1003
|
def get_room_creation_info(room_id, **params)
|
737
1004
|
get_room_state(room_id, 'm.room.create', params)
|
@@ -743,7 +1010,7 @@ module MatrixSdk::Protocols::CS
|
|
743
1010
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
744
1011
|
# @return [Response] A response hash with the configuration the room was created for
|
745
1012
|
# @see get_room_state
|
746
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1013
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-encryption
|
747
1014
|
# The Matrix Spec, for more information about the event and data
|
748
1015
|
def get_room_encryption_settings(room_id, **params)
|
749
1016
|
get_room_state(room_id, 'm.room.encryption', params)
|
@@ -757,7 +1024,7 @@ module MatrixSdk::Protocols::CS
|
|
757
1024
|
# @param [Integer] rotation_period_msgs The interval between key rotation in messages
|
758
1025
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
759
1026
|
# @return [Response] The resulting state event
|
760
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1027
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-guest-encryption
|
761
1028
|
# The Matrix Spec, for more information about the event and data
|
762
1029
|
def set_room_encryption_settings(room_id, algorithm: 'm.megolm.v1.aes-sha2', rotation_period_ms: 1 * 7 * 24 * 60 * 60 * 1000, rotation_period_msgs: 100, **params)
|
763
1030
|
content = {
|
@@ -774,7 +1041,7 @@ module MatrixSdk::Protocols::CS
|
|
774
1041
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
775
1042
|
# @return [Response] A response hash with the key :history_visibility
|
776
1043
|
# @see get_room_state
|
777
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1044
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-history-visibility
|
778
1045
|
# The Matrix Spec, for more information about the event and data
|
779
1046
|
def get_room_history_visibility(room_id, **params)
|
780
1047
|
get_room_state(room_id, 'm.room.history_visibility', params)
|
@@ -786,7 +1053,7 @@ module MatrixSdk::Protocols::CS
|
|
786
1053
|
# @param [:invited, :joined, :shared, :world_readable] visibility The new history visibility level
|
787
1054
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
788
1055
|
# @return [Response] The resulting state event
|
789
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1056
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-guest-history-visibility
|
790
1057
|
# The Matrix Spec, for more information about the event and data
|
791
1058
|
def set_room_history_visibility(room_id, visibility, **params)
|
792
1059
|
content = {
|
@@ -802,7 +1069,7 @@ module MatrixSdk::Protocols::CS
|
|
802
1069
|
# @param [Hash] params Extra options to provide to the request, see #get_room_state
|
803
1070
|
# @return [Response] A response hash with server ACL information
|
804
1071
|
# @see get_room_state
|
805
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1072
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-server-acl
|
806
1073
|
# The Matrix Spec, for more information about the event and data
|
807
1074
|
def get_room_server_acl(room_id, **params)
|
808
1075
|
get_room_state(room_id, 'm.room.server_acl', params)
|
@@ -816,7 +1083,7 @@ module MatrixSdk::Protocols::CS
|
|
816
1083
|
# @param [Array[String]] deny A list of HS wildcards that are denied from communicating with the room
|
817
1084
|
# @param [Hash] params Extra options to set on the request, see #send_state_event
|
818
1085
|
# @return [Response] The resulting state event
|
819
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1086
|
+
# @see https://matrix.org/docs/spec/client_server/latest.html#m-room-guest-server-acl
|
820
1087
|
# The Matrix Spec, for more information about the event and data
|
821
1088
|
def set_room_server_acl(room_id, allow_ip_literals: false, allow:, deny:, **params)
|
822
1089
|
content = {
|
@@ -846,6 +1113,26 @@ module MatrixSdk::Protocols::CS
|
|
846
1113
|
request(:post, :client_r0, "/rooms/#{room_id}/forget", query: query)
|
847
1114
|
end
|
848
1115
|
|
1116
|
+
# Directly joins a room by ID
|
1117
|
+
#
|
1118
|
+
# @param room_id [MXID,String] The room ID to join
|
1119
|
+
# @param third_party_signed [Hash] The 3PID signature allowing the user to join
|
1120
|
+
# @return [Response] A response hash with the parameter :room_id
|
1121
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-rooms-roomid-join
|
1122
|
+
# The Matrix Spec, for more information about the call and response
|
1123
|
+
def join_room_id(room_id, third_party_signed: nil, **params)
|
1124
|
+
query = {}
|
1125
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
1126
|
+
|
1127
|
+
body = {
|
1128
|
+
third_party_signed: third_party_signed
|
1129
|
+
}.compact
|
1130
|
+
|
1131
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
1132
|
+
|
1133
|
+
request(:post, :client_r0, "/rooms/#{room_id}/join", body: body, query: query)
|
1134
|
+
end
|
1135
|
+
|
849
1136
|
def invite_user(room_id, user_id, **params)
|
850
1137
|
query = {}
|
851
1138
|
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
@@ -918,6 +1205,41 @@ module MatrixSdk::Protocols::CS
|
|
918
1205
|
request(:post, :client_r0, "/rooms/#{room_id}/unban", body: content, query: query)
|
919
1206
|
end
|
920
1207
|
|
1208
|
+
# Gets the room directory visibility status for a room
|
1209
|
+
#
|
1210
|
+
# @param [MXID,String] room_id The room ID to look up
|
1211
|
+
# @return [Response] A response hash with a :visibility key
|
1212
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-directory-list-room-roomid
|
1213
|
+
# The Matrix Spec, for more information about the event and data
|
1214
|
+
def get_room_directory_visibility(room_id, **params)
|
1215
|
+
query = {}
|
1216
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
1217
|
+
|
1218
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
1219
|
+
|
1220
|
+
request(:get, :client_r0, "/directory/list/room/#{room_id}", query: query)
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
# Sets the room directory visibility status for a room
|
1224
|
+
#
|
1225
|
+
# @param [MXID,String] room_id The room ID to change visibility for
|
1226
|
+
# @param [:public,:private] visibility The new visibility status
|
1227
|
+
# @return [Response] An empty response hash if the visibilty change succeeded
|
1228
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-directory-list-room-roomid
|
1229
|
+
# The Matrix Spec, for more information about the event and data
|
1230
|
+
def set_room_directory_visibility(room_id, visibility, **params)
|
1231
|
+
query = {}
|
1232
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
1233
|
+
|
1234
|
+
body = {
|
1235
|
+
visibility: visibility
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
1239
|
+
|
1240
|
+
request(:put, :client_r0, "/directory/list/room/#{room_id}", body: body, query: query)
|
1241
|
+
end
|
1242
|
+
|
921
1243
|
def get_user_tags(user_id, room_id, **params)
|
922
1244
|
query = {}
|
923
1245
|
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
@@ -999,6 +1321,18 @@ module MatrixSdk::Protocols::CS
|
|
999
1321
|
request(:put, :client_r0, "/user/#{user_id}/rooms/#{room_id}/account_data/#{type_key}", body: account_data, query: query)
|
1000
1322
|
end
|
1001
1323
|
|
1324
|
+
# Retrieve user information
|
1325
|
+
#
|
1326
|
+
# @param [String] user_id The MXID to look up
|
1327
|
+
# @return [Response] A response hash containing the requested user's information
|
1328
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-admin-whois-userid
|
1329
|
+
# The Matrix Spec, for more information about the parameters and data
|
1330
|
+
def whois(user_id)
|
1331
|
+
user_id = ERB::Util.url_encode user_id.to_s
|
1332
|
+
|
1333
|
+
request(:get, :client_r0, "/admin/whois/#{user_id}")
|
1334
|
+
end
|
1335
|
+
|
1002
1336
|
def get_filter(user_id, filter_id, **params)
|
1003
1337
|
query = {}
|
1004
1338
|
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
@@ -1060,6 +1394,27 @@ module MatrixSdk::Protocols::CS
|
|
1060
1394
|
request(:get, :client_r0, "/profile/#{user_id}/avatar_url", query: query)
|
1061
1395
|
end
|
1062
1396
|
|
1397
|
+
# Sets the avatar URL for a user
|
1398
|
+
#
|
1399
|
+
# @example Reuploading a gravatar as an avatar
|
1400
|
+
# require 'digest/md5'
|
1401
|
+
#
|
1402
|
+
# # Get a 256x256 gravatar of user@example.com, returning 404 if one doesn't exist
|
1403
|
+
# email = 'user@example.com'
|
1404
|
+
# url = "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest email.striprim.downcase}?d=404&s=256"
|
1405
|
+
#
|
1406
|
+
# data = Net::HTTP.get_response(URI(url))
|
1407
|
+
# data.value
|
1408
|
+
#
|
1409
|
+
# # Reupload the gravatar to your connected HS before setting the resulting MXC URL as the new avatar
|
1410
|
+
# mxc = api.media_upload(data.body, data.content_type)[:content_uri]
|
1411
|
+
# api.set_avatar_url(api.whoami?[:user_id], mxc)
|
1412
|
+
#
|
1413
|
+
# @param [String,MXID] user_id The ID of the user to set the avatar for
|
1414
|
+
# @param [String,URI::MATRIX] url The new avatar URL, should be a mxc:// URL
|
1415
|
+
# @return [Response] An empty response hash if the change was successful
|
1416
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-profile-userid-avatar-url
|
1417
|
+
# The Matrix Spec, for more information about the event and data
|
1063
1418
|
def set_avatar_url(user_id, url, **params)
|
1064
1419
|
query = {}
|
1065
1420
|
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
@@ -1090,6 +1445,68 @@ module MatrixSdk::Protocols::CS
|
|
1090
1445
|
request(:get, :client_r0, "/profile/#{user_id}", query: query)
|
1091
1446
|
end
|
1092
1447
|
|
1448
|
+
# Gets TURN server connection information and credentials
|
1449
|
+
#
|
1450
|
+
# @return [Response] A response hash according to the spec
|
1451
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-voip-turnserver
|
1452
|
+
# The Matrix Spec, for more information about the event and data
|
1453
|
+
def get_turn_server
|
1454
|
+
request(:get, :client_r0, '/voip/turnServer')
|
1455
|
+
end
|
1456
|
+
|
1457
|
+
# Sets the typing status for a user
|
1458
|
+
#
|
1459
|
+
# @param [String,MXID] room_id The ID of the room to set the typing status in
|
1460
|
+
# @param [String,MXID] user_id The ID of the user to set the typing status for
|
1461
|
+
# @param [Boolean] typing Is the user typing or not
|
1462
|
+
# @param [Numeric] timeout The timeout in seconds for how long the typing status should be valid
|
1463
|
+
# @return [Response] An empty response hash if the typing change was successful
|
1464
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-rooms-roomid-typing-userid
|
1465
|
+
# The Matrix Spec, for more information about the event and data
|
1466
|
+
def set_typing(room_id, user_id, typing: true, timeout: nil)
|
1467
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
1468
|
+
user_id = ERB::Util.url_encode user_id.to_s
|
1469
|
+
|
1470
|
+
body = {
|
1471
|
+
typing: typing,
|
1472
|
+
timeout: timeout ? timeout * 1000 : nil
|
1473
|
+
}.compact
|
1474
|
+
|
1475
|
+
request(:put, :client_r0, "/rooms/#{room_id}/typing/#{user_id}", body: body)
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
# Gets the presence status of a user
|
1479
|
+
#
|
1480
|
+
# @param [String,MXID] user_id The User ID to read the status for
|
1481
|
+
# @return [Response] A response hash containing the current user presence status
|
1482
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-presence-userid-status
|
1483
|
+
# The Matrix Spec, for more information about the event and data
|
1484
|
+
def get_presence_status(user_id)
|
1485
|
+
user_id = ERB::Util.url_encode user_id.to_s
|
1486
|
+
|
1487
|
+
request(:get, :client_r0, "/presence/#{user_id}/status")
|
1488
|
+
end
|
1489
|
+
|
1490
|
+
# Sets the presence status of a user
|
1491
|
+
#
|
1492
|
+
# @param [String,MXID] user_id The User ID to set the status for
|
1493
|
+
# @param [:online,:offline,:unavailable] status The status to set
|
1494
|
+
# @param [String] messge The status message to store for the new status
|
1495
|
+
# @return [Response] An empty response hash if the status update succeeded
|
1496
|
+
# @note The specified user_id should be of the local user unless used for AS purposes
|
1497
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-presence-userid-status
|
1498
|
+
# The Matrix Spec, for more information about the event and data
|
1499
|
+
def set_presence_status(user_id, status, message: nil)
|
1500
|
+
user_id = ERB::Util.url_encode user_id.to_s
|
1501
|
+
|
1502
|
+
body = {
|
1503
|
+
presence: status,
|
1504
|
+
status_msg: message
|
1505
|
+
}.compact
|
1506
|
+
|
1507
|
+
request(:put, :client_r0, "/presence/#{user_id}/status", body: body)
|
1508
|
+
end
|
1509
|
+
|
1093
1510
|
# Converts a Matrix content URL (mxc://) to a media download URL
|
1094
1511
|
# @param [String,URI] mxcurl The Matrix content URL to convert
|
1095
1512
|
# @param [String,URI] source A source HS to use for the convertion, defaults to the connected HS
|
@@ -1118,6 +1535,55 @@ module MatrixSdk::Protocols::CS
|
|
1118
1535
|
end
|
1119
1536
|
end
|
1120
1537
|
|
1538
|
+
# Gets a preview of the given URL
|
1539
|
+
#
|
1540
|
+
# @param [String,URI] url The URL to retrieve a preview for
|
1541
|
+
# @return [Response] A response hash containing OpenGraph data for the URL
|
1542
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-media-r0-preview-url
|
1543
|
+
# The Matrix Spec, for more information about the data
|
1544
|
+
def get_url_preview(url, timestamp: nil)
|
1545
|
+
ts = (timestamp.to_i * 1000) if timestamp.is_a? Time
|
1546
|
+
ts = timestamp if timestamp.is_a? Integer
|
1547
|
+
|
1548
|
+
query = {
|
1549
|
+
url: url,
|
1550
|
+
ts: ts
|
1551
|
+
}.compact
|
1552
|
+
|
1553
|
+
request(:get, :media_r0, '/preview_url', query: query)
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
# Gets the media configuration of the current server
|
1557
|
+
#
|
1558
|
+
# @return [Response] A response hash containing media configuration informtion
|
1559
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-media-r0-config
|
1560
|
+
# The Matrix Spec, for more information about the data
|
1561
|
+
def get_media_config
|
1562
|
+
request(:get, :media_r0, '/config')
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
# Sends events directly to the specified devices
|
1566
|
+
#
|
1567
|
+
# @param [String] event_type The type of event to send
|
1568
|
+
# @param [Hash] messages The hash of events to send and devices to send them to
|
1569
|
+
# @param [Hash] params Additional parameters
|
1570
|
+
# @option params [Integer] :txn_id The ID of the transaction, automatically generated if not specified
|
1571
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-sendtodevice-eventtype-txnid
|
1572
|
+
# The Matrix Spec, for more information about the data
|
1573
|
+
def send_to_device(event_type, messages:, **params)
|
1574
|
+
txn_id = transaction_id
|
1575
|
+
txn_id = params.fetch(:txn_id, "#{txn_id}#{Time.now.to_i}")
|
1576
|
+
|
1577
|
+
event_type = ERB::Util.url_encode event_type.to_s
|
1578
|
+
txn_id = ERB::Util.url_encode txn_id.to_s
|
1579
|
+
|
1580
|
+
body = {
|
1581
|
+
messages: messages
|
1582
|
+
}.compact
|
1583
|
+
|
1584
|
+
request(:put, :client_r0, "/sendToDevice/#{event_type}/#{txn_id}", body: body)
|
1585
|
+
end
|
1586
|
+
|
1121
1587
|
# Gets the room ID for an alias
|
1122
1588
|
# @param [String,MXID] room_alias The room alias to look up
|
1123
1589
|
# @return [Response] An object containing the :room_id key and a key of :servers that know of the room
|
@@ -1163,7 +1629,7 @@ module MatrixSdk::Protocols::CS
|
|
1163
1629
|
# Gets a list of all the members in a room
|
1164
1630
|
# @param [String,MXID] room_id The ID of the room
|
1165
1631
|
# @return [Response] A chunked object
|
1166
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1632
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-rooms-roomid-members
|
1167
1633
|
# The Matrix Spec, for more information about the data
|
1168
1634
|
def get_room_members(room_id, **params)
|
1169
1635
|
query = {}
|
@@ -1174,9 +1640,24 @@ module MatrixSdk::Protocols::CS
|
|
1174
1640
|
request(:get, :client_r0, "/rooms/#{room_id}/members", query: query)
|
1175
1641
|
end
|
1176
1642
|
|
1643
|
+
# Gets a list of the joined members in a room
|
1644
|
+
#
|
1645
|
+
# @param [String,MXID] room_id The ID of the room
|
1646
|
+
# @return [Response] A chunked object
|
1647
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-rooms-roomid-joined-members
|
1648
|
+
# The Matrix Spec, for more information about the data
|
1649
|
+
def get_room_joined_members(room_id, **params)
|
1650
|
+
query = {}
|
1651
|
+
query[:user_id] = params.delete(:user_id) if protocol?(:AS) && params.key?(:user_id)
|
1652
|
+
|
1653
|
+
room_id = ERB::Util.url_encode room_id.to_s
|
1654
|
+
|
1655
|
+
request(:get, :client_r0, "/rooms/#{room_id}/joined_members", query: query)
|
1656
|
+
end
|
1657
|
+
|
1177
1658
|
# Gets a list of the current users registered devices
|
1178
1659
|
# @return [Response] An object including all information about the users devices.
|
1179
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1660
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices
|
1180
1661
|
# The Matrix Spec, for more information about the data
|
1181
1662
|
def get_devices
|
1182
1663
|
request(:get, :client_r0, '/devices')
|
@@ -1185,7 +1666,7 @@ module MatrixSdk::Protocols::CS
|
|
1185
1666
|
# Gets the information about a certain client device
|
1186
1667
|
# @param [String] device_id The ID of the device to look up
|
1187
1668
|
# @return [Response] An object containing all available device information
|
1188
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1669
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-devices-deviceid
|
1189
1670
|
# The Matrix Spec, for more information about the data
|
1190
1671
|
def get_device(device_id)
|
1191
1672
|
device_id = ERB::Util.url_encode device_id.to_s
|
@@ -1196,7 +1677,7 @@ module MatrixSdk::Protocols::CS
|
|
1196
1677
|
# Sets the metadata for a device
|
1197
1678
|
# @param [String] device_id The ID of the device to modify
|
1198
1679
|
# @param [String] display_name The new display name to set for the device
|
1199
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1680
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-devices-deviceid
|
1200
1681
|
# The Matrix Spec, for more information about the data
|
1201
1682
|
def set_device(device_id, display_name:)
|
1202
1683
|
device_id = ERB::Util.url_encode device_id.to_s
|
@@ -1209,7 +1690,7 @@ module MatrixSdk::Protocols::CS
|
|
1209
1690
|
# @param [Hash] auth Authentication data for the removal request
|
1210
1691
|
# @raise [MatrixNotAuthorizeedError] The request did not contain enough authentication information,
|
1211
1692
|
# the data in this error will include the necessary information to perform interactive auth
|
1212
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1693
|
+
# @see https://matrix.org/docs/spec/client_server/latest#delete-matrix-client-r0-devices-deviceid
|
1213
1694
|
# The Matrix Spec, for more information about the data
|
1214
1695
|
def delete_device(device_id, auth:)
|
1215
1696
|
device_id = ERB::Util.url_encode device_id.to_s
|
@@ -1229,7 +1710,7 @@ module MatrixSdk::Protocols::CS
|
|
1229
1710
|
# @example Looking up a specific device for a user
|
1230
1711
|
# api.keys_query(device_keys: { '@alice:example.com': ['ABCDEFGHIJ'] })
|
1231
1712
|
# # => { :device_keys => { :'@alice:example.com' => { :ABCDEFGHIJ => { ...
|
1232
|
-
# @see https://matrix.org/docs/spec/client_server/
|
1713
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-keys-query
|
1233
1714
|
# The Matrix Spec, for more information about the parameters and data
|
1234
1715
|
def keys_query(timeout: nil, device_keys:, token: nil, **params)
|
1235
1716
|
body = {
|
@@ -1242,6 +1723,201 @@ module MatrixSdk::Protocols::CS
|
|
1242
1723
|
request(:post, :client_r0, '/keys/query', body: body)
|
1243
1724
|
end
|
1244
1725
|
|
1726
|
+
# Claim one-time keys for pre-key messaging
|
1727
|
+
#
|
1728
|
+
# @param [Hash] one_time_keys Hash mapping user IDs to hashes of device IDs and key types
|
1729
|
+
# @param [Numeric] timeout (10) The timeout - in seconds - for the request
|
1730
|
+
# @return [Response] A response hash containing one-time keys for the requested users and devices
|
1731
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-keys-claim
|
1732
|
+
# The Matrix Spec, for more information about the parameters and data
|
1733
|
+
def claim_one_time_keys(one_time_keys, timeout: 10)
|
1734
|
+
body = {
|
1735
|
+
one_time_keys: one_time_keys,
|
1736
|
+
timeout: timeout * 1000
|
1737
|
+
}
|
1738
|
+
request(:post, :client_r0, '/keys/claim', body: body)
|
1739
|
+
end
|
1740
|
+
|
1741
|
+
# Retrieve device key changes between two sync requests
|
1742
|
+
#
|
1743
|
+
# @param [String] from The sync token denoting the start of the range
|
1744
|
+
# @param [String] to The sync token denoting the end of the range
|
1745
|
+
# @return [Response] The users with device key changes during the specified range
|
1746
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-keys-changes
|
1747
|
+
# The Matrix Spec, for more information about the parameters and data
|
1748
|
+
def get_key_changes(from:, to:)
|
1749
|
+
query = {
|
1750
|
+
from: from,
|
1751
|
+
to: to
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
request(:get, :client_r0, '/keys/changes', query: query)
|
1755
|
+
end
|
1756
|
+
|
1757
|
+
# Gets the list of registered pushers for the current user
|
1758
|
+
#
|
1759
|
+
# @return [Response] A response hash containing all the currently registered pushers for the current user
|
1760
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers
|
1761
|
+
# The Matrix Spec, for more information about the parameters and data
|
1762
|
+
def get_pushers
|
1763
|
+
request(:get, :client_r0, '/pushers')
|
1764
|
+
end
|
1765
|
+
|
1766
|
+
# rubocop:disable Metrics/ParameterLists
|
1767
|
+
|
1768
|
+
# Sets a pusher on the current user
|
1769
|
+
#
|
1770
|
+
# @param [String] key The pushkey for the pusher, used for routing purposes and for unique identification in coordination with app_id
|
1771
|
+
# @param [String] kind The kind of pusher, should be either 'http' or 'email'
|
1772
|
+
# @param [String] app_id The ID of the application to push to
|
1773
|
+
# @param [String] app_name The user-visible name of the application to push to
|
1774
|
+
# @param [String] device_name The user-visible name of the device to push to
|
1775
|
+
# @param [String] lang The language that pushes should be sent in
|
1776
|
+
# @param [Hash] data Pusher configuration data, depends on the kind parameter
|
1777
|
+
# @param [Hash] params Additional optional parameters
|
1778
|
+
# @option params [String] profile_tag Specifies which device rules to use
|
1779
|
+
# @option params [Boolean] append Specifies if the pusher should replace or be appended to the pusher list based on uniqueness
|
1780
|
+
# @return [Response] An empty response hash if the pusher was added/replaced correctly
|
1781
|
+
# @see https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers
|
1782
|
+
# The Matrix Spec, for more information about the parameters and data
|
1783
|
+
def set_pusher(key, kind:, app_id:, app_name:, device_name:, lang:, data:, **params)
|
1784
|
+
body = {
|
1785
|
+
pushkey: key,
|
1786
|
+
kind: kind,
|
1787
|
+
app_id: app_id,
|
1788
|
+
app_display_name: app_name,
|
1789
|
+
device_display_name: device_name,
|
1790
|
+
profile_tag: params[:profile_tag],
|
1791
|
+
lang: lang,
|
1792
|
+
data: data,
|
1793
|
+
append: params[:append]
|
1794
|
+
}.compact
|
1795
|
+
|
1796
|
+
request(:post, :client_r0, '/pushers/set', body: body)
|
1797
|
+
end
|
1798
|
+
# rubocop:enable Metrics/ParameterLists
|
1799
|
+
|
1800
|
+
# Enumerates the list of notifies that the current user has/should have received.
|
1801
|
+
#
|
1802
|
+
# @param [String] from The pagination token to continue reading events from
|
1803
|
+
# @param [Integer] limit The maximum number of event to return
|
1804
|
+
# @param [String] only A filter string that is to be applied to the notification events
|
1805
|
+
# @return [Response] A response hash containing notifications for the current user
|
1806
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-notifications
|
1807
|
+
# The Matrix Spec, for more information about the parameters and data
|
1808
|
+
def get_notifications(from: nil, limit: nil, only: nil)
|
1809
|
+
raise ArgumentError, 'Limit must be an integer' unless limit.nil? || limit.is_a?(Integer)
|
1810
|
+
|
1811
|
+
query = {
|
1812
|
+
from: from,
|
1813
|
+
limit: limit,
|
1814
|
+
only: only
|
1815
|
+
}.compact
|
1816
|
+
|
1817
|
+
request(:get, :client_r0, '/notifications', query: query)
|
1818
|
+
end
|
1819
|
+
|
1820
|
+
# Retrieves the full list of registered push rules for the current user
|
1821
|
+
#
|
1822
|
+
# @return [Response] A response hash containing the current list of push rules for the current user
|
1823
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules
|
1824
|
+
# The Matrix Spec, for more information about the parameters and data
|
1825
|
+
def get_pushrules
|
1826
|
+
request(:get, :client_r0, '/pushrules')
|
1827
|
+
end
|
1828
|
+
|
1829
|
+
# Retrieves a single registered push rule for the current user
|
1830
|
+
#
|
1831
|
+
# @param [String] scope ('global') The scope to look up push rules from
|
1832
|
+
# @param [:override,:underride,:sender,:room,:content] kind The kind of push rule to look up
|
1833
|
+
# @param [String] id The ID of the rule that's being retrieved
|
1834
|
+
# @return [Response] A response hash containing the full data of the requested push rule
|
1835
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules-scope-kind-ruleid
|
1836
|
+
# The Matrix Spec, for more information about the parameters and data
|
1837
|
+
def get_pushrule(scope: 'global', kind:, id:)
|
1838
|
+
scope = ERB::Util.url_encode scope.to_s
|
1839
|
+
kind = ERB::Util.url_encode kind.to_s
|
1840
|
+
id = ERB::Util.url_encode id.to_s
|
1841
|
+
|
1842
|
+
request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}")
|
1843
|
+
end
|
1844
|
+
|
1845
|
+
# Checks if a push rule for the current user is enabled
|
1846
|
+
#
|
1847
|
+
# @param [String] scope ('global') The scope to look up push rules from
|
1848
|
+
# @param [:override,:underride,:sender,:room,:content] kind The kind of push rule to look up
|
1849
|
+
# @param [String] id The ID of the rule that's being retrieved
|
1850
|
+
# @return [Response] A response hash containing an :enabled key for if the rule is enabled or not
|
1851
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules-scope-kind-ruleid-enabled
|
1852
|
+
# The Matrix Spec, for more information about the parameters and data
|
1853
|
+
def get_pushrule_enabled(scope: 'global', kind:, id:)
|
1854
|
+
scope = ERB::Util.url_encode scope.to_s
|
1855
|
+
kind = ERB::Util.url_encode kind.to_s
|
1856
|
+
id = ERB::Util.url_encode id.to_s
|
1857
|
+
|
1858
|
+
request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled")
|
1859
|
+
end
|
1860
|
+
|
1861
|
+
# Enabled/Disables a specific push rule for the current user
|
1862
|
+
#
|
1863
|
+
# @param [Boolean] enabled Should the push rule be enabled or not
|
1864
|
+
# @param [String] scope ('global') The scope to look up push rules from
|
1865
|
+
# @param [:override,:underride,:sender,:room,:content] kind The kind of push rule to look up
|
1866
|
+
# @param [String] id The ID of the rule that's being retrieved
|
1867
|
+
# @return [Response] An empty response hash if the push rule was enabled/disabled successfully
|
1868
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-pushrules-scope-kind-ruleid-enabled
|
1869
|
+
# The Matrix Spec, for more information about the parameters and data
|
1870
|
+
def set_pushrule_enabled(enabled, scope: 'global', kind:, id:)
|
1871
|
+
scope = ERB::Util.url_encode scope.to_s
|
1872
|
+
kind = ERB::Util.url_encode kind.to_s
|
1873
|
+
id = ERB::Util.url_encode id.to_s
|
1874
|
+
|
1875
|
+
body = {
|
1876
|
+
enabled: enabled
|
1877
|
+
}
|
1878
|
+
|
1879
|
+
request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/enabled", body: body)
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
# Gets the current list of actions for a specific push rule for the current user
|
1883
|
+
#
|
1884
|
+
# @param [String] scope ('global') The scope to look up push rules from
|
1885
|
+
# @param [:override,:underride,:sender,:room,:content] kind The kind of push rule to look up
|
1886
|
+
# @param [String] id The ID of the rule that's being retrieved
|
1887
|
+
# @return [Response] A response hash containing an :enabled key for if the rule is enabled or not
|
1888
|
+
# @see https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushrules-scope-kind-ruleid-actions
|
1889
|
+
# The Matrix Spec, for more information about the parameters and data
|
1890
|
+
def get_pushrule_actions(scope: 'global', kind:, id:)
|
1891
|
+
scope = ERB::Util.url_encode scope.to_s
|
1892
|
+
kind = ERB::Util.url_encode kind.to_s
|
1893
|
+
id = ERB::Util.url_encode id.to_s
|
1894
|
+
|
1895
|
+
request(:get, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions")
|
1896
|
+
end
|
1897
|
+
|
1898
|
+
# Replaces the list of actions for a push rule for the current user
|
1899
|
+
#
|
1900
|
+
# @param [String,Array[String]] actions The list of actions to apply on the push rule
|
1901
|
+
# @param [String] scope ('global') The scope to look up push rules from
|
1902
|
+
# @param [:override,:underride,:sender,:room,:content] kind The kind of push rule to look up
|
1903
|
+
# @param [String] id The ID of the rule that's being retrieved
|
1904
|
+
# @return [Response] An empty response hash if the push rule actions were modified successfully
|
1905
|
+
# @see https://matrix.org/docs/spec/client_server/latest#put-matrix-client-r0-pushrules-scope-kind-ruleid-actions
|
1906
|
+
# The Matrix Spec, for more information about the parameters and data
|
1907
|
+
def set_pushrule_actions(actions, scope: 'global', kind:, id:)
|
1908
|
+
scope = ERB::Util.url_encode scope.to_s
|
1909
|
+
kind = ERB::Util.url_encode kind.to_s
|
1910
|
+
id = ERB::Util.url_encode id.to_s
|
1911
|
+
|
1912
|
+
actions = [actions] unless actions.is_a? Array
|
1913
|
+
|
1914
|
+
body = {
|
1915
|
+
actions: actions
|
1916
|
+
}
|
1917
|
+
|
1918
|
+
request(:put, :client_r0, "/pushrules/#{scope}/#{kind}/#{id}/actions", body: body)
|
1919
|
+
end
|
1920
|
+
|
1245
1921
|
# Gets the MXID of the currently logged-in user
|
1246
1922
|
# @return [Response] An object containing the key :user_id
|
1247
1923
|
def whoami?(**params)
|