forked from matrix-org/matrix-ios-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMXRestClient.h
2801 lines (2167 loc) · 111 KB
/
MXRestClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2014 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <Cocoa/Cocoa.h>
#endif
#import "MXHTTPClient.h"
#import "MXEvent.h"
#import "MXError.h"
#import "MXRoomEventFilter.h"
#import "MXInvite3PID.h"
#import "MXEventTimeline.h"
#import "MXJSONModels.h"
#import "MXFilterJSONModel.h"
#import "MXMatrixVersions.h"
#import "MXContentScanResult.h"
#import "MXEncryptedContentFile.h"
#import "MXContentScanEncryptedBody.h"
#import "MXAggregationPaginatedResponse.h"
#import "MXPusher.h"
#import "MXRoomCreationParameters.h"
#import "MXTurnServerResponse.h"
#import "MXSpaceChildrenResponse.h"
#import "MXURLPreview.h"
@class MXThirdpartyProtocolsResponse;
@class MXThirdPartyUsersResponse;
@class MXSyncResponse;
@class MXDeviceListResponse;
@class MXSpaceChildrenRequestParameters;
#pragma mark - Constants definitions
/**
A constant representing the URI path for release 0 of the Client-Server HTTP API.
*/
FOUNDATION_EXPORT NSString *const kMXAPIPrefixPathR0;
/**
A constant representing the URI path for as-yet unspecified of the Client-Server HTTP API.
*/
FOUNDATION_EXPORT NSString *const kMXAPIPrefixPathUnstable;
/**
Account data types
*/
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeDirect;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypePushRules;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeIgnoredUserList;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeUserWidgets;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeIdentityServer;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeAcceptedTerms;
FOUNDATION_EXPORT NSString *const kMXAccountDataTypeAcceptedTermsKey;
/**
Account data keys
*/
FOUNDATION_EXPORT NSString *const kMXAccountDataKeyIgnoredUser;
FOUNDATION_EXPORT NSString *const kMXAccountDataKeyIdentityServer;
/**
MXRestClient error domain
*/
FOUNDATION_EXPORT NSString *const kMXRestClientErrorDomain;
/**
MXRestClient errors
*/
NS_ERROR_ENUM(kMXRestClientErrorDomain)
{
MXRestClientErrorUnknown,
MXRestClientErrorInvalidParameters,
MXRestClientErrorInvalidContentURI,
MXRestClientErrorMissingIdentityServer,
MXRestClientErrorMissingIdentityServerAccessToken
};
/**
Parameters that can be used in [MXRestClient membersOfRoom:withParameters:...].
*/
FOUNDATION_EXPORT NSString *const kMXMembersOfRoomParametersAt;
FOUNDATION_EXPORT NSString *const kMXMembersOfRoomParametersMembership;
FOUNDATION_EXPORT NSString *const kMXMembersOfRoomParametersNotMembership;
/**
Block called when a request needs the identity server access token.
@param success A block object called when the operation succeeds. It provides the access token.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
typedef MXHTTPOperation* (^MXRestClientIdentityServerAccessTokenHandler)(void (^success)(NSString *accessToken), void (^failure)(NSError *error));
/**
`MXRestClient` makes requests to Matrix servers.
It is the single point to send requests to Matrix servers which are:
- the specified Matrix home server
- the Matrix content repository manage by this home server
- the specified Matrix identity server
*/
@interface MXRestClient : NSObject
/**
Credentials for the Matrix Client-Server API.
*/
@property (nonatomic, readonly) MXCredentials *credentials;
/**
The homeserver URL.
Shortcut to credentials.homeServer.
*/
@property (nonatomic, readonly) NSString *homeserver;
/**
The homeserver suffix (for example ":matrix.org"). Available only when credentials have been set.
*/
@property (nonatomic, readonly) NSString *homeserverSuffix;
/**
The identity server URL (ex: "https://vector.im").
TODO: Remove it when all HSes will no more require IS.
*/
@property (nonatomic, copy) NSString *identityServer;
/**
Block called when a request needs the identity server access token.
*/
@property (nonatomic, copy) MXRestClientIdentityServerAccessTokenHandler identityServerAccessTokenHandler;
/**
The antivirus server URL (nil by default).
Set a non-null url to enable the antivirus scanner use.
*/
@property (nonatomic) NSString *antivirusServer;
/**
The Client-Server API prefix to use for the antivirus server
By default, it is defined by the constant kMXAntivirusAPIPrefixPathUnstable.
In case of a custom path prefix use, set it before settings the antivirus server url.
*/
@property (nonatomic) NSString *antivirusServerPathPrefix;
/**
The Client-Server API prefix to use.
By default, it is '_matrix/client/r0'. See kMXAPIPrefixPathR0 and kMXAPIPrefixPathUnstable for constants.
*/
@property (nonatomic) NSString *apiPathPrefix;
/**
The Matrix content repository prefix to use.
By default, it is defined by the constant kMXContentPrefixPath.
*/
@property (nonatomic) NSString *contentPathPrefix;
/**
The current trusted certificate (if any).
*/
@property (nonatomic, readonly) NSData* allowedCertificate;
/**
The queue on which asynchronous response blocks are called.
Default is dispatch_get_main_queue().
*/
@property (nonatomic, strong) dispatch_queue_t completionQueue;
/**
The acceptable MIME types for responses.
*/
@property (nonatomic, copy) NSSet <NSString *> *acceptableContentTypes;
/**
Create an instance based on homeserver url.
@param homeserver the homeserver URL.
@param onUnrecognizedCertBlock the block called to handle unrecognized certificate (nil if unrecognized certificates are ignored).
@return a MXRestClient instance.
*/
-(id)initWithHomeServer:(NSString *)homeserver andOnUnrecognizedCertificateBlock:(MXHTTPClientOnUnrecognizedCertificate)onUnrecognizedCertBlock NS_REFINED_FOR_SWIFT;
/**
Create an instance based on a matrix user account.
@param credentials the response to a login or a register request.
@param onUnrecognizedCertBlock the block called to handle unrecognized certificate (nil if unrecognized certificates are ignored).
@return a MXRestClient instance.
*/
-(id)initWithCredentials:(MXCredentials*)credentials andOnUnrecognizedCertificateBlock:(MXHTTPClientOnUnrecognizedCertificate)onUnrecognizedCertBlock NS_REFINED_FOR_SWIFT;
- (void)close;
#pragma mark - Server administration
/**
Gets the versions of the specification supported by the server.
@param success A block object called when the operation succeeds. It provides
the supported spec versions.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)supportedMatrixVersions:(void (^)(MXMatrixVersions *matrixVersions))success
failure:(void (^)(NSError *error))failure;
/**
Get the wellknwon data of the homeserver.
@param success A block object called when the operation succeeds. It provides
the wellknown data.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)wellKnow:(void (^)(MXWellKnown *wellKnown))success
failure:(void (^)(NSError *error))failure;
#pragma mark - Registration operations
/**
Make a ping to the registration endpoint to detect a possible registration problem earlier.
@param username the user name to test (This value must not be nil).
@param callback A block object called when the operation is completed.
It provides a MXError to check to verify if the user can be registered.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)testUserRegistration:(NSString*)username
callback:(void (^)(MXError *mxError))callback;
/**
Check whether a username is already in use.
@username the user name to test (This value must not be nil).
@param callback A block object called when the operation is completed.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)isUserNameInUse:(NSString*)username
callback:(void (^)(BOOL isUserNameInUse))callback NS_REFINED_FOR_SWIFT;
/**
Get the list of register flows supported by the home server.
@param success A block object called when the operation succeeds. It provides the server response
as an MXAuthenticationSession instance.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)getRegisterSession:(void (^)(MXAuthenticationSession *authSession))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Generic registration action request.
As described in http://matrix.org/docs/spec/client_server/r0.2.0.html#client-authentication some registration flows require to
complete several stages in order to complete user registration.
This can lead to make several requests to the home server with different kinds of parameters.
This generic method with open parameters and response exists to handle any kind of registration flow stage.
At the end of the registration process, the SDK user should be able to construct a MXCredentials object
from the response of the last registration action request.
@note The caller may provide the device display name by adding @"initial_device_display_name" key
in the `parameters` dictionary. If the caller does not provide it, the device display name field
is filled with the device name.
@param parameters the parameters required for the current registration stage
@param success A block object called when the operation succeeds. It provides the raw JSON response
from the server.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)registerWithParameters:(NSDictionary*)parameters
success:(void (^)(NSDictionary *JSONResponse))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Register a user.
This method manages the full flow for simple login types and returns the credentials of the newly created matrix user.
@param loginType the login type. Only kMXLoginFlowTypePassword and kMXLoginFlowTypeDummy (m.login.password and m.login.dummy) are supported.
@param username the user id (ex: "@bob:matrix.org") or the user id localpart (ex: "bob") of the user to register. Can be nil.
@param password his password.
@param success A block object called when the operation succeeds. It provides credentials to use to create a MXRestClient.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)registerWithLoginType:(NSString*)loginType username:(NSString*)username password:(NSString*)password
success:(void (^)(MXCredentials *credentials))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the register fallback page to make registration via a web browser or a web view.
@return the fallback page URL.
*/
- (NSString*)registerFallback NS_REFINED_FOR_SWIFT;
/**
Reset the password server side
Check that the given email address is associated with any account
and then request the validation of an email address.
Check MXMatrixVersion.doesServerRequireIdentityServerParam to determine if
the homeserver requires the id_server parameter to be provided.
@param email the email address to validate.
@param clientSecret a secret key generated by the client. ([MXTools generateSecret] creates such key)
@param sendAttempt the number of the attempt for the validation request. Increment this value to make the
identity server resend the email. Keep it to retry the request in case the previous request
failed.
@param success A block object called when the operation succeeds. It provides the id of the
forget password session.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)forgetPasswordForEmail:(NSString *)email
clientSecret:(NSString *)clientSecret
sendAttempt:(NSUInteger)sendAttempt
success:(void (^)(NSString *sid))success
failure:(void (^)(NSError *error))failure;
#pragma mark - Login operations
/**
Get the list of login flows supported by the home server.
@param success A block object called when the operation succeeds. It provides the server response
as an MXAuthenticationSession instance.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)getLoginSession:(void (^)(MXAuthenticationSession *authSession))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Generic login action request.
@see the register method for explanation of flows that require to make several request to the
home server.
@note The caller may provide the device display name by adding @"initial_device_display_name" key
in the `parameters` dictionary. If the caller does not provide it, the device display name field
is filled with the device name.
@param parameters the parameters required for the current login stage
@param success A block object called when the operation succeeds. It provides the raw JSON response
from the server.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)login:(NSDictionary*)parameters
success:(void (^)(NSDictionary *JSONResponse))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Log a user in.
This method manages the full flow for simple login types and returns the credentials of the logged matrix user.
@note The device display name field is filled with the device name by default.
@param loginType the login type. Only kMXLoginFlowTypePassword (m.login.password) is supported.
@param username the user id (ex: "@bob:matrix.org") or the user id localpart (ex: "bob") of the user to register.
@param password his password.
@param success A block object called when the operation succeeds. It provides credentials to use to create a MXRestClient.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)loginWithLoginType:(NSString*)loginType username:(NSString*)username password:(NSString*)password
success:(void (^)(MXCredentials *credentials))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the login fallback page to make login via a web browser or a web view.
Presently only server auth v1 is supported.
@return the fallback page URL.
*/
- (NSString*)loginFallback NS_REFINED_FOR_SWIFT;
/**
Reset the account password.
@param parameters a set of parameters containing a threepid credentials and the new password.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)resetPasswordWithParameters:(NSDictionary*)parameters
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Replace the account password.
@param oldPassword the current password to update.
@param newPassword the new password.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)changePassword:(NSString*)oldPassword with:(NSString*)newPassword
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Invalidate the access token, so that it can no longer be used for authorization.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)logout:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Deactivate the user's account, removing all ability for the user to login again.
@discussion This API endpoint uses the User-Interactive Authentication API.
@note An access token should be submitted to this endpoint if the client has an active session.
The homeserver may change the flows available depending on whether a valid access token is provided.
@param authParameters The additional authentication information for the user-interactive authentication API.
@param eraseAccount Indicating whether the account should be erased.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)deactivateAccountWithAuthParameters:(NSDictionary*)authParameters
eraseAccount:(BOOL)eraseAccount
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
#pragma mark - Authenticated session
/**
Get an authentication session for a given request.
@param httpMethod The HTTP method for the request.
@param path The request path.
@param parameters Request parameters.
@param success A block object called when the operation succeeds. It provides the server response
as an MXAuthenticationSession instance.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)authSessionForRequestWithMethod:(NSString *)httpMethod
path:(NSString *)path
parameters:(NSDictionary*)parameters
success:(void (^)(MXAuthenticationSession *authSession))success
failure:(void (^)(NSError *error))failure;
#pragma mark - Account data
/**
Set some account_data for the client.
@param data the new data to set for this event type.
@param type The event type of the account_data to set (@see kMXAccountDataType* strings)
Custom types should be namespaced to avoid clashes.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setAccountData:(NSDictionary*)data
forType:(NSString*)type
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
#pragma mark - Filtering
/**
Uploads a new filter definition to the homeserver.
@param filter the filter to set.
@param success A block object called when the operation succeeds. It provides the
id of the created filter.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setFilter:(MXFilterJSONModel*)filter
success:(void (^)(NSString *filterId))success
failure:(void (^)(NSError *error))failure;
/**
Download a filter.
@param filterId The filter id to download.
@param success A block object called when the operation succeeds. It provides the
filter object.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)getFilterWithFilterId:(NSString*)filterId
success:(void (^)(MXFilterJSONModel *filter))success
failure:(void (^)(NSError *error))failure;
/**
Gets a bearer token from the homeserver that the user can
present to a third party in order to prove their ownership
of the Matrix account they are logged into.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)openIdToken:(void (^)(MXOpenIdToken *tokenObject))success
failure:(void (^)(NSError *error))failure;
#pragma mark - 3pid token request
/**
Requests an email verification token for the purposes of adding a
third party identifier to an account.
Check MXMatrixVersion.doesServerRequireIdentityServerParam to determine if
the homeserver requires the id_server parameter to be provided.
If an account with the given email address already exists and is
associated with an account other than the one the user is authed as,
it will either send an email to the address informing them of this
or return M_THREEPID_IN_USE (which one is up to the homeserver).
Use the returned sid to complete operations that require authenticated email
like [MXRestClient add3PID:].
@param email the email address to validate.
@param isDuringRegistration tell whether this request occurs during a registration flow.
@param clientSecret a secret key generated by the client. ([MXTools generateSecret] creates such key)
@param sendAttempt the number of the attempt for the validation request. Increment this value to make the
identity server resend the email. Keep it to retry the request in case the previous request
failed.
@param nextLink the link the validation page will automatically open. Can be nil
@param success A block object called when the operation succeeds. It provides the id of the
email validation session.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)requestTokenForEmail:(NSString*)email
isDuringRegistration:(BOOL)isDuringRegistration
clientSecret:(NSString*)clientSecret
sendAttempt:(NSUInteger)sendAttempt
nextLink:(NSString*)nextLink
success:(void (^)(NSString *sid))success
failure:(void (^)(NSError *error))failure;
/**
Requests a text message verification token for the purposes of registration.
Check MXMatrixVersion.doesServerRequireIdentityServerParam to determine if
the homeserver requires the id_server parameter to be provided.
Use the returned sid to complete operations that require authenticated phone number
like [MXRestClient add3PID:].
@param phoneNumber the phone number (in international or national format).
@param isDuringRegistration tell whether this request occurs during a registration flow.
@param countryCode the ISO 3166-1 country code representation (required when the phone number is in national format).
@param clientSecret a secret key generated by the client. ([MXTools generateSecret] creates such key)
@param sendAttempt the number of the attempt for the validation request. Increment this value to make the
identity server resend the sms token. Keep it to retry the request in case the previous request
failed.
@param nextLink the link the validation page will automatically open. Can be nil
@param success A block object called when the operation succeeds. It provides the id of the validation session and the msisdn.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)requestTokenForPhoneNumber:(NSString*)phoneNumber
isDuringRegistration:(BOOL)isDuringRegistration
countryCode:(NSString*)countryCode
clientSecret:(NSString*)clientSecret
sendAttempt:(NSUInteger)sendAttempt
nextLink:(NSString *)nextLink
success:(void (^)(NSString *sid, NSString *msisdn, NSString *submitUrl))success
failure:(void (^)(NSError *error))failure;
#pragma mark - Push Notifications
/**
Update the pusher for this device on the Home Server.
@param pushkey The pushkey for this pusher. This should be the APNS token formatted as required for your push gateway (base64 is the recommended formatting).
@param kind The kind of pusher your push gateway requires. Generally 'http', or an NSNull to disable the pusher.
@param appId The app ID of this application as required by your push gateway.
@param appDisplayName A human readable display name for this app.
@param deviceDisplayName A human readable display name for this device.
@param profileTag The profile tag for this device. Identifies this device in push rules.
@param lang The user's preferred language for push, eg. 'en' or 'en-US'
@param data Dictionary of data as required by your push gateway (generally the notification URI and aps-environment for APNS).
@param success A block object called when the operation succeeds. It provides credentials to use to create a MXRestClient.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setPusherWithPushkey:(NSString *)pushkey
kind:(NSObject *)kind
appId:(NSString *)appId
appDisplayName:(NSString *)appDisplayName
deviceDisplayName:(NSString *)deviceDisplayName
profileTag:(NSString *)profileTag
lang:(NSString *)lang
data:(NSDictionary *)data
append:(BOOL)append
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Gets all currently active pushers for the authenticated user.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)pushers:(void (^)(NSArray<MXPusher *> *pushers))success
failure:(void (^)(NSError *))failure;
/**
Get all push notifications rules.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)pushRules:(void (^)(MXPushRulesResponse *pushRules))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Enable/Disable a push notification rule.
@param ruleId The identifier for the rule.
@param scope Either 'global' or 'device/<profile_tag>' to specify global rules or device rules for the given profile_tag.
@param kind The kind of rule, ie. 'override', 'underride', 'sender', 'room', 'content' (see MXPushRuleKind).
@param enable YES to enable
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
*/
- (MXHTTPOperation *)enablePushRule:(NSString*)ruleId
scope:(NSString*)scope
kind:(MXPushRuleKind)kind
enable:(BOOL)enable
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Remove a push notification rule.
@param ruleId The identifier for the rule.
@param scope Either 'global' or 'device/<profile_tag>' to specify global rules or device rules for the given profile_tag.
@param kind The kind of rule, ie. 'override', 'underride', 'sender', 'room', 'content' (see MXPushRuleKind).
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
*/
- (MXHTTPOperation *)removePushRule:(NSString*)ruleId
scope:(NSString*)scope
kind:(MXPushRuleKind)kind
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Create a new push rule.
@param ruleId The identifier for the rule (it depends on rule kind: user id for sender rule, room id for room rule...).
@param scope Either 'global' or 'device/<profile_tag>' to specify global rules or device rules for the given profile_tag.
@param kind The kind of rule, ie. 'sender', 'room' or 'content' (see MXPushRuleKind).
@param actions The rule actions: notify, don't notify, set tweak...
@param pattern The pattern relevant for content rule.
@param conditions The conditions relevant for override and underride rule.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
*/
- (MXHTTPOperation *)addPushRule:(NSString*)ruleId
scope:(NSString*)scope
kind:(MXPushRuleKind)kind
actions:(NSArray*)actions
pattern:(NSString*)pattern
conditions:(NSArray<NSDictionary *> *)conditions
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Update push rule actions.
@param ruleId The identifier for the rule (it depends on rule kind: user id for sender rule, room id for room rule...).
@param scope Either 'global' or 'device/<profile_tag>' to specify global rules or device rules for the given profile_tag.
@param kind The kind of rule, ie. 'sender', 'room' or 'content' (see MXPushRuleKind).
@param actions The rule actions: notify, don't notify, set tweak...
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
*/
- (MXHTTPOperation *)updateActionsForPushRule:(NSString*)ruleId
scope:(NSString*)scope
kind:(MXPushRuleKind)kind
actions:(NSArray*)actions
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure;
#pragma mark - Room operations
/**
Send a generic non state event to a room.
@param roomId the id of the room.
@param eventTypeString the type of the event. @see MXEventType.
@param content the content that will be sent to the server as a JSON object.
@param txnId the transaction id to use. If nil, one will be generated.
@param success A block object called when the operation succeeds. It returns
the event id of the event generated on the home server
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)sendEventToRoom:(NSString*)roomId
eventType:(MXEventTypeString)eventTypeString
content:(NSDictionary*)content
txnId:(NSString*)txnId
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Send a generic state event to a room.
@param roomId the id of the room.
@param eventTypeString the type of the event. @see MXEventType.
@param content the content that will be sent to the server as a JSON object.
@param stateKey the optional state key.
@param success A block object called when the operation succeeds. It returns
the event id of the event generated on the home server
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)sendStateEventToRoom:(NSString*)roomId
eventType:(MXEventTypeString)eventTypeString
content:(NSDictionary*)content
stateKey:(NSString*)stateKey
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Send a message to a room
@param roomId the id of the room.
@param msgType the type of the message. @see MXMessageType.
@param content the message content that will be sent to the server as a JSON object.
@param success A block object called when the operation succeeds. It returns
the event id of the event generated on the home server
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)sendMessageToRoom:(NSString*)roomId
msgType:(MXMessageType)msgType
content:(NSDictionary*)content
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Send a text message to a room
@param roomId the id of the room.
@param text the text to send.
@param success A block object called when the operation succeeds. It returns
the event id of the event generated on the home server
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)sendTextMessageToRoom:(NSString*)roomId
text:(NSString*)text
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the topic of a room.
@param roomId the id of the room.
@param topic the topic to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomTopic:(NSString*)roomId
topic:(NSString*)topic
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the topic of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room topic.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)topicOfRoom:(NSString*)roomId
success:(void (^)(NSString *topic))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the avatar of a room.
@param roomId the id of the room.
@param avatar the avatar url to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomAvatar:(NSString*)roomId
avatar:(NSString*)avatar
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the avatar of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room avatar url.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)avatarOfRoom:(NSString*)roomId
success:(void (^)(NSString *avatar))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the name of a room.
@param roomId the id of the room.
@param name the name to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomName:(NSString*)roomId
name:(NSString*)name
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the name of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room name.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)nameOfRoom:(NSString*)roomId
success:(void (^)(NSString *name))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the history visibility of a room.
@param roomId the id of the room.
@param historyVisibility the visibily to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomHistoryVisibility:(NSString*)roomId
historyVisibility:(MXRoomHistoryVisibility)historyVisibility
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the history visibility of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room history visibility.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)historyVisibilityOfRoom:(NSString*)roomId
success:(void (^)(MXRoomHistoryVisibility historyVisibility))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the join rule of a room.
@param roomId the id of the room.
@param joinRule the rule to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomJoinRule:(NSString*)roomId
joinRule:(MXRoomJoinRule)joinRule
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the join rule of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room join rule.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)joinRuleOfRoom:(NSString*)roomId
success:(void (^)(MXRoomJoinRule joinRule))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Set the guest access of a room.
@param roomId the id of the room.
@param guestAccess the guest access to set.
@param success A block object called when the operation succeeds.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)setRoomGuestAccess:(NSString*)roomId
guestAccess:(MXRoomGuestAccess)guestAccess
success:(void (^)(void))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;
/**
Get the guest access of a room.
@param roomId the id of the room.
@param success A block object called when the operation succeeds. It provides the room guest access.
@param failure A block object called when the operation fails.
@return a MXHTTPOperation instance.
*/
- (MXHTTPOperation*)guestAccessOfRoom:(NSString*)roomId
success:(void (^)(MXRoomGuestAccess guestAccess))success
failure:(void (^)(NSError *error))failure NS_REFINED_FOR_SWIFT;