2017-09-07 09:32:40 +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.
|
|
|
|
*/
|
|
|
|
|
2017-09-11 14:33:52 +00:00
|
|
|
#import "IntegrationManagerViewController.h"
|
2017-09-07 09:32:40 +00:00
|
|
|
|
|
|
|
#import "WidgetManager.h"
|
|
|
|
|
2017-09-08 14:27:14 +00:00
|
|
|
#import <JavaScriptCore/JavaScriptCore.h>
|
|
|
|
|
2017-09-08 11:51:06 +00:00
|
|
|
NSString *kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@', %@);";
|
2017-09-08 07:18:45 +00:00
|
|
|
|
|
|
|
|
2017-09-11 14:33:52 +00:00
|
|
|
@interface IntegrationManagerViewController ()
|
2017-09-07 09:32:40 +00:00
|
|
|
{
|
|
|
|
MXSession *mxSession;
|
|
|
|
NSString *roomId;
|
|
|
|
NSString *screen;
|
|
|
|
NSString *widgetId;
|
|
|
|
NSString *scalarToken;
|
|
|
|
|
|
|
|
MXHTTPOperation *operation;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-09-11 14:33:52 +00:00
|
|
|
@implementation IntegrationManagerViewController
|
2017-09-07 09:32:40 +00:00
|
|
|
|
|
|
|
- (instancetype)initForMXSession:(MXSession *)theMXSession inRoom:(NSString *)theRoomId screen:(NSString *)theScreen widgetId:(NSString *)theWidgetId
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
mxSession = theMXSession;
|
|
|
|
roomId = theRoomId;
|
|
|
|
screen = theScreen;
|
|
|
|
widgetId = theWidgetId;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
[super destroy];
|
|
|
|
|
|
|
|
[operation cancel];
|
|
|
|
operation = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
webView.scalesPageToFit = NO;
|
2017-09-08 07:18:45 +00:00
|
|
|
|
|
|
|
webView.delegate = self;
|
2017-09-07 09:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
if (!self.URL && !operation)
|
|
|
|
{
|
|
|
|
__weak __typeof__(self) weakSelf = self;
|
|
|
|
|
|
|
|
[self startActivityIndicator];
|
|
|
|
|
2017-09-08 07:18:45 +00:00
|
|
|
// Make sure we a scalar token
|
2017-09-07 09:32:40 +00:00
|
|
|
operation = [[WidgetManager sharedManager] getScalarTokenForMXSession:mxSession success:^(NSString *theScalarToken) {
|
|
|
|
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
self->operation = nil;
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
|
|
|
|
scalarToken = theScalarToken;
|
|
|
|
|
2017-09-08 07:18:45 +00:00
|
|
|
// Launch the webview on the right modular webapp page
|
2017-09-07 09:32:40 +00:00
|
|
|
self.URL = [self interfaceUrl];
|
|
|
|
}
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
typeof(self) self = weakSelf;
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
self->operation = nil;
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Private methods
|
|
|
|
|
|
|
|
/**
|
2017-09-08 07:18:45 +00:00
|
|
|
Build the URL to use in the Modular interface webapp.
|
2017-09-07 09:32:40 +00:00
|
|
|
*/
|
|
|
|
- (NSString *)interfaceUrl
|
|
|
|
{
|
|
|
|
NSMutableString *url;
|
|
|
|
|
|
|
|
if (scalarToken)
|
|
|
|
{
|
|
|
|
url = [NSMutableString stringWithFormat:@"%@?scalar_token=%@&room_id=%@",
|
|
|
|
[[NSUserDefaults standardUserDefaults] objectForKey:@"integrationsUiUrl"],
|
|
|
|
[scalarToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
|
|
|
|
[roomId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
|
|
|
|
];
|
|
|
|
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
[url appendString:@"&screen="];
|
|
|
|
[url appendString:[screen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetId)
|
|
|
|
{
|
|
|
|
[url appendString:@"&integ_id="];
|
|
|
|
[url appendString:[widgetId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
- (void)enableDebug
|
2017-09-08 07:18:45 +00:00
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
// Setup console.log() -> NSLog() route
|
2017-09-08 14:27:14 +00:00
|
|
|
JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
|
|
|
|
ctx[@"console"][@"log"] = ^(JSValue * msg) {
|
2017-09-11 14:22:28 +00:00
|
|
|
NSLog(@"-- JavaScript: %@", msg);
|
2017-09-08 14:27:14 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
// Redirect all console.* logging methods to console.log
|
|
|
|
[webView stringByEvaluatingJavaScriptFromString:@"console.debug = console.log; console.info = console.log; console.warn = console.log; console.error = console.log;"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - UIWebViewDelegate
|
|
|
|
|
|
|
|
-(void)webViewDidFinishLoad:(UIWebView *)theWebView
|
|
|
|
{
|
|
|
|
[self enableDebug];
|
|
|
|
|
2017-09-08 11:51:06 +00:00
|
|
|
// Setup js code
|
2017-09-11 14:33:52 +00:00
|
|
|
NSString *path = [[NSBundle mainBundle] pathForResource:@"IntegrationManager" ofType:@"js"];
|
2017-09-08 11:51:06 +00:00
|
|
|
NSString *js = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
|
|
|
[webView stringByEvaluatingJavaScriptFromString:js];
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
|
|
|
|
{
|
|
|
|
NSString *urlString = [[request URL] absoluteString];
|
|
|
|
|
|
|
|
if ([urlString hasPrefix:@"js:"])
|
|
|
|
{
|
|
|
|
// Listen only to scheme of the JS-UIWebView bridge
|
|
|
|
NSString *jsonString = [[[urlString componentsSeparatedByString:@"js:"] lastObject] stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
|
|
|
|
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers
|
|
|
|
error:&error];
|
|
|
|
if (!error)
|
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
[self onMessage:parameters];
|
|
|
|
}
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
#pragma mark - Modular postMessage API
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
- (void)onMessage:(NSDictionary*)JSData
|
|
|
|
{
|
|
|
|
NSDictionary *eventData;
|
|
|
|
MXJSONModelSetDictionary(eventData, JSData[@"event.data"]);
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
NSString *roomIdInEvent, *userId, *action;
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
MXJSONModelSetString(roomIdInEvent, eventData[@"room_id"]);
|
|
|
|
MXJSONModelSetString(userId, eventData[@"user_id"]);
|
|
|
|
MXJSONModelSetString(action, eventData[@"action"]);
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
if (!roomIdInEvent)
|
|
|
|
{
|
|
|
|
[self sendLocalisedError:@"widget_integration_missing_room_id" toEvent:eventData];
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
if (![roomIdInEvent isEqualToString:roomId])
|
|
|
|
{
|
|
|
|
[self sendError:[NSString stringWithFormat:NSLocalizedStringFromTable(@"widget_integration_room_not_visible", @"Vector", nil), roomIdInEvent] toEvent:eventData];
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 07:18:45 +00:00
|
|
|
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
// These APIs don't require userId
|
|
|
|
if ([@"join_rules_state" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self getJoinRules:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ([@"set_plumbing_state" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self setPlumbingState:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ([@"get_membership_count" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self getMembershipCount:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ([@"set_widget" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self setWidget:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ([@"get_widgets" isEqualToString:action])
|
|
|
|
{
|
|
|
|
[self getWidgets:eventData];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ([@"can_send_event" isEqualToString:action])
|
|
|
|
{
|
|
|
|
[self canSendEvent:eventData];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!userId)
|
|
|
|
{
|
|
|
|
[self sendLocalisedError:@"widget_integration_missing_user_id" toEvent:eventData];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([@"membership_state" isEqualToString:action])
|
|
|
|
{
|
|
|
|
[self getMembershipState:userId eventData:eventData];
|
|
|
|
}
|
|
|
|
else if ([@"invite" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self inviteUser:userId eventData:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
}
|
|
|
|
else if ([@"bot_options" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self getBotOptions:userId eventData:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
}
|
|
|
|
else if ([@"set_bot_options" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self setBotOptions:userId eventData:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
}
|
|
|
|
else if ([@"set_bot_power" isEqualToString:action])
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
[self setBotPower:userId eventData:eventData];
|
2017-09-11 14:22:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-11 14:33:52 +00:00
|
|
|
NSLog(@"[IntegrationManagerViewControllerVC] Unhandled postMessage event with action %@: %@", action, JSData);
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:51:06 +00:00
|
|
|
- (void)sendBoolResponse:(BOOL)response toEvent:(NSDictionary*)eventData
|
2017-09-08 07:18:45 +00:00
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
// Convert BOOL to "true" or "false"
|
2017-09-08 11:51:06 +00:00
|
|
|
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
|
|
|
eventData[@"_id"],
|
|
|
|
response ? @"true" : @"false"];
|
2017-09-08 07:18:45 +00:00
|
|
|
|
2017-09-08 11:51:06 +00:00
|
|
|
[webView stringByEvaluatingJavaScriptFromString:js];
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 07:53:07 +00:00
|
|
|
- (void)sendIntegerResponse:(NSUInteger)response toEvent:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
|
|
|
eventData[@"_id"],
|
|
|
|
@(response)];
|
|
|
|
|
|
|
|
[webView stringByEvaluatingJavaScriptFromString:js];
|
|
|
|
}
|
|
|
|
|
2017-09-08 14:27:14 +00:00
|
|
|
- (void)sendNSObjectResponse:(NSObject*)response toEvent:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSString *jsString;
|
|
|
|
|
|
|
|
if (response)
|
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
// Convert response into a JS object through a JSON string
|
2017-09-08 14:27:14 +00:00
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:response
|
|
|
|
options:0
|
|
|
|
error:0];
|
|
|
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
jsString = [NSString stringWithFormat:@"JSON.parse('%@')", jsonString];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jsString = @"null";
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
|
|
|
eventData[@"_id"],
|
|
|
|
jsString];
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
[webView stringByEvaluatingJavaScriptFromString:js];
|
|
|
|
}
|
2017-09-08 14:27:14 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
- (void)sendError:(NSString*)message toEvent:(NSDictionary*)eventData
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
NSLog(@"[IntegrationManagerVC] sendError: Action %@ failed with message: %@", eventData[@"action"], message);
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
// TODO: JS has an additional optional parameter: nestedError
|
|
|
|
[self sendNSObjectResponse:@{
|
|
|
|
@"error": @{
|
|
|
|
@"message": message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toEvent:eventData];
|
|
|
|
}
|
2017-09-08 14:27:14 +00:00
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
- (void)sendLocalisedError:(NSString*)errorKey toEvent:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
[self sendError:NSLocalizedStringFromTable(errorKey, @"Vector", nil) toEvent:eventData];
|
2017-09-08 14:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-11 14:22:28 +00:00
|
|
|
#pragma mark - Modular postMessage Implementation
|
2017-09-08 07:18:45 +00:00
|
|
|
|
|
|
|
- (MXRoom *)roomCheckWithEvent:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
MXRoom *room = [mxSession roomWithRoomId:roomId];
|
|
|
|
if (!room)
|
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
[self sendLocalisedError:@"widget_integration_room_not_recognised" toEvent:eventData];
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2017-09-14 07:53:07 +00:00
|
|
|
- (void)inviteUser:(NSString*)userId eventData:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to invite %@ into room %@.", userId, roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setWidget:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to set widget in room %@.", roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
2017-09-08 14:27:14 +00:00
|
|
|
- (void)getWidgets:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
MXRoom *room = [self roomCheckWithEvent:eventData];
|
|
|
|
|
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
NSArray<Widget*> *widgets = [[WidgetManager sharedManager] widgetsInRoom:room];
|
|
|
|
|
|
|
|
NSMutableArray<NSDictionary*> *widgetStateEvents = [NSMutableArray arrayWithCapacity:widgets.count];
|
|
|
|
|
|
|
|
for (Widget *widget in widgets)
|
|
|
|
{
|
|
|
|
[widgetStateEvents addObject:widget.widgetEvent.JSONDictionary];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self sendNSObjectResponse:widgetStateEvents toEvent:eventData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 07:18:45 +00:00
|
|
|
- (void)canSendEvent:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSString *eventType;
|
|
|
|
BOOL isState = NO;
|
|
|
|
|
|
|
|
MXRoom *room = [self roomCheckWithEvent:eventData];
|
|
|
|
|
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
if (room.state.membership != MXMembershipJoin)
|
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
[self sendLocalisedError:@"widget_integration_must_be_in_room" toEvent:eventData];
|
2017-09-08 07:18:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MXJSONModelSetString(eventType, eventData[@"event_type"]);
|
|
|
|
MXJSONModelSetBoolean(isState, eventData[@"is_state"]);
|
|
|
|
|
|
|
|
MXRoomPowerLevels *powerLevels = room.state.powerLevels;
|
|
|
|
NSInteger userPowerLevel = [powerLevels powerLevelOfUserWithUserID:mxSession.myUser.userId];
|
|
|
|
|
|
|
|
BOOL canSend = NO;
|
|
|
|
|
|
|
|
if (isState)
|
|
|
|
{
|
|
|
|
canSend = (userPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:eventType]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
canSend = (userPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsMessage:eventType]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canSend)
|
|
|
|
{
|
2017-09-08 11:51:06 +00:00
|
|
|
[self sendBoolResponse:YES toEvent:eventData];
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-11 14:22:28 +00:00
|
|
|
[self sendLocalisedError:@"widget_integration_no_permission_in_room" toEvent:eventData];
|
2017-09-08 07:18:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 14:27:14 +00:00
|
|
|
- (void)getMembershipState:(NSString*)userId eventData:(NSDictionary*)eventData
|
|
|
|
{
|
2017-09-14 07:53:07 +00:00
|
|
|
NSLog(@"[IntegrationManagerVC] membership_state of %@ in room %@ requested.", userId, roomId);
|
2017-09-08 14:27:14 +00:00
|
|
|
|
2017-09-14 07:53:07 +00:00
|
|
|
MXRoom *room = [self roomCheckWithEvent:eventData];
|
2017-09-08 14:27:14 +00:00
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
MXRoomMember *member = [room.state memberWithUserId:userId];
|
|
|
|
[self sendNSObjectResponse:member.originalEvent.JSONDictionary toEvent:eventData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-14 07:53:07 +00:00
|
|
|
- (void)getJoinRules:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] join_rules of %@ requested.", roomId);
|
|
|
|
|
|
|
|
MXRoom *room = [self roomCheckWithEvent:eventData];
|
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
MXEvent *event = [room.state stateEventsWithType:kMXEventTypeStringRoomJoinRules].lastObject;
|
|
|
|
[self sendNSObjectResponse:event.JSONDictionary toEvent:eventData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPlumbingState:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to set plumbing state to status %@ in room %@.", eventData[@"status"], roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)getBotOptions:(NSString*)userId eventData:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to get options for bot %@ in room %@", userId, roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBotOptions:(NSString*)userId eventData:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to set options for bot %@ in room %@", userId, roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBotPower:(NSString*)userId eventData:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
NSLog(@"[IntegrationManagerVC] Received request to set power level to %@ for bot %@ in room %@.", eventData[@"level"], userId, roomId);
|
|
|
|
|
|
|
|
NSAssert(NO, @"TODO");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)getMembershipCount:(NSDictionary*)eventData
|
|
|
|
{
|
|
|
|
MXRoom *room = [self roomCheckWithEvent:eventData];
|
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
NSUInteger membershipCount = room.state.joinedMembers.count;
|
|
|
|
[self sendIntegerResponse:membershipCount toEvent:eventData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 09:32:40 +00:00
|
|
|
@end
|