2017-08-04 11:05:07 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
#import <MatrixSDK/MatrixSDK.h>
|
|
|
|
|
|
|
|
#import "Widget.h"
|
|
|
|
|
|
|
|
/**
|
2017-08-30 09:28:51 +00:00
|
|
|
The type of matrix event used for modular widgets.
|
2017-08-04 11:05:07 +00:00
|
|
|
*/
|
|
|
|
FOUNDATION_EXPORT NSString *const kWidgetEventTypeString;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Known types widgets.
|
|
|
|
*/
|
|
|
|
FOUNDATION_EXPORT NSString *const kWidgetTypeJitsi;
|
|
|
|
|
|
|
|
/**
|
2017-08-18 07:49:14 +00:00
|
|
|
Posted when a widget has been created, updated or disabled.
|
|
|
|
The notification object is the `Widget` instance.
|
2017-08-04 11:05:07 +00:00
|
|
|
*/
|
2017-08-18 07:49:14 +00:00
|
|
|
FOUNDATION_EXPORT NSString *const kWidgetManagerDidUpdateWidgetNotification;
|
2017-08-17 10:17:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
`WidgetManager` NSError domain and codes.
|
|
|
|
*/
|
|
|
|
FOUNDATION_EXPORT NSString *const WidgetManagerErrorDomain;
|
|
|
|
|
|
|
|
typedef enum : NSUInteger
|
|
|
|
{
|
2017-08-17 16:45:49 +00:00
|
|
|
WidgetManagerErrorCodeNotEnoughPower,
|
|
|
|
WidgetManagerErrorCodeCreationFailed
|
|
|
|
}
|
|
|
|
WidgetManagerErrorCode;
|
2017-08-04 11:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-30 09:28:51 +00:00
|
|
|
The `WidgetManager` helps to handle modular widgets.
|
2017-08-04 11:05:07 +00:00
|
|
|
*/
|
|
|
|
@interface WidgetManager : NSObject
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the shared widget manager.
|
|
|
|
|
|
|
|
@return the shared widget manager.
|
|
|
|
*/
|
|
|
|
+ (instancetype)sharedManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
List all active widgets in a room.
|
|
|
|
|
|
|
|
@param room the room to check.
|
|
|
|
@return a list of widgets.
|
|
|
|
*/
|
2017-08-10 13:43:25 +00:00
|
|
|
- (NSArray<Widget*> *)widgetsInRoom:(MXRoom*)room;
|
2017-08-04 11:05:07 +00:00
|
|
|
|
2017-08-16 09:49:01 +00:00
|
|
|
/**
|
|
|
|
List all active widgets of a given type in a room.
|
|
|
|
|
2017-09-27 13:21:38 +00:00
|
|
|
@param widgetTypes the types of widget to search. Nil means all types.
|
2017-08-16 09:49:01 +00:00
|
|
|
@param room the room to check.
|
|
|
|
@return a list of widgets.
|
|
|
|
*/
|
|
|
|
- (NSArray<Widget*> *)widgetsOfTypes:(NSArray<NSString*>*)widgetTypes inRoom:(MXRoom*)room;
|
|
|
|
|
2017-09-27 13:21:38 +00:00
|
|
|
/**
|
|
|
|
List all active widgets of a given type in a room, excluding some types.
|
|
|
|
|
|
|
|
@param notWidgetTypes the types of widget to not consider. Nil means all types.
|
|
|
|
@param room the room to check.
|
|
|
|
@return a list of widgets.
|
|
|
|
*/
|
|
|
|
- (NSArray<Widget*> *)widgetsNotOfTypes:(NSArray<NSString*>*)notWidgetTypes inRoom:(MXRoom*)room;
|
2017-08-17 15:22:40 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-30 09:28:51 +00:00
|
|
|
Add a modular widget to a room.
|
2017-08-17 15:22:40 +00:00
|
|
|
|
|
|
|
@param widgetId the id of the widget.
|
|
|
|
@param widgetContent the widget content.
|
|
|
|
@param room the room to create the widget to.
|
|
|
|
|
|
|
|
@param success A block object called when the operation succeeds. It provides the newly added widget.
|
|
|
|
@param failure A block object called when the operation fails.
|
|
|
|
|
|
|
|
@return a MXHTTPOperation instance.
|
|
|
|
*/
|
|
|
|
- (MXHTTPOperation *)createWidget:(NSString*)widgetId
|
|
|
|
withContent:(NSDictionary<NSString*, NSObject*>*)widgetContent
|
|
|
|
inRoom:(MXRoom*)room
|
|
|
|
success:(void (^)(Widget *widget))success
|
|
|
|
failure:(void (^)(NSError *error))failure;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Add a jitsi conference widget to a room.
|
|
|
|
|
|
|
|
@param room the room to create the widget to.
|
|
|
|
@param video the conference type
|
|
|
|
|
|
|
|
@param success A block object called when the operation succeeds. It provides the newly added widget.
|
|
|
|
@param failure A block object called when the operation fails.
|
|
|
|
|
|
|
|
@return a MXHTTPOperation instance.
|
|
|
|
*/
|
|
|
|
- (MXHTTPOperation *)createJitsiWidgetInRoom:(MXRoom*)room
|
|
|
|
withVideo:(BOOL)video
|
|
|
|
success:(void (^)(Widget *jitsiWidget))success
|
|
|
|
failure:(void (^)(NSError *error))failure;
|
|
|
|
|
2017-08-17 10:17:07 +00:00
|
|
|
/**
|
|
|
|
Close/Disable a widget in a room.
|
|
|
|
|
|
|
|
@param widgetId the id of the widget to close.
|
|
|
|
@param room the room the widget is in.
|
|
|
|
|
|
|
|
@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 *)closeWidget:(NSString*)widgetId inRoom:(MXRoom*)room
|
|
|
|
success:(void (^)())success
|
|
|
|
failure:(void (^)(NSError *error))failure;
|
|
|
|
|
2017-08-17 15:22:40 +00:00
|
|
|
|
2017-08-04 11:05:07 +00:00
|
|
|
/**
|
|
|
|
Add/remove matrix session.
|
|
|
|
|
2017-08-18 07:49:14 +00:00
|
|
|
Registering session allows to generate `kWidgetManagerDidUpdateWidgetNotification` notifications.
|
2017-08-04 11:05:07 +00:00
|
|
|
|
|
|
|
@param mxSession the session to add/remove.
|
|
|
|
*/
|
|
|
|
- (void)addMatrixSession:(MXSession*)mxSession;
|
|
|
|
- (void)removeMatrixSession:(MXSession*)mxSession;
|
|
|
|
|
2017-09-15 13:35:27 +00:00
|
|
|
/**
|
|
|
|
Delete the data associated with an user.
|
|
|
|
|
|
|
|
@param userId the id of the user.
|
|
|
|
*/
|
|
|
|
- (void)deleteDataForUser:(NSString*)userId;
|
2017-09-07 09:32:40 +00:00
|
|
|
|
|
|
|
#pragma mark - Modular interface
|
|
|
|
|
|
|
|
/**
|
|
|
|
Make sure there is a scalar token for the given Matrix session.
|
|
|
|
|
|
|
|
If no token was gotten and stored before, the operation will make http requests
|
|
|
|
to get one.
|
|
|
|
|
|
|
|
@param mxSession the session to check.
|
|
|
|
|
|
|
|
@param success A block object called when the operation succeeds.
|
|
|
|
@param failure A block object called when the operation fails.
|
|
|
|
*/
|
|
|
|
- (MXHTTPOperation *)getScalarTokenForMXSession:(MXSession*)mxSession
|
|
|
|
success:(void (^)(NSString *scalarToken))success
|
|
|
|
failure:(void (^)(NSError *error))failure;
|
|
|
|
|
|
|
|
/**
|
|
|
|
The current scalar token for the given Matrix session.
|
|
|
|
|
|
|
|
It may be nil if `getScalarTokenForMXSession` was never called before.
|
|
|
|
|
|
|
|
@param mxSession the session to check.
|
|
|
|
@return the current scalar token .
|
|
|
|
*/
|
|
|
|
- (NSString *)scalarTokenForMXSession:(MXSession*)mxSession;
|
|
|
|
|
2017-08-04 11:05:07 +00:00
|
|
|
@end
|