mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-23 08:02:09 +02:00
Send Stickers: Plug the sticker picker widget with the room datasource to send a sticker
#1860
This commit is contained in:
@@ -75,8 +75,12 @@
|
||||
// Display the widget
|
||||
[widget widgetUrl:^(NSString * _Nonnull widgetUrl) {
|
||||
|
||||
WidgetViewController *widgetVC = [[WidgetViewController alloc] initWithUrl:widgetUrl forWidget:widget];
|
||||
[mxkViewController.navigationController pushViewController:widgetVC animated:YES];
|
||||
WidgetViewController *widgetVC = [[WidgetViewController alloc] initWithUrl:widgetUrl forWidget:widget];
|
||||
|
||||
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
||||
widgetVC.roomDataSource = [roomDataSourceManager roomDataSourceForRoom:roomId create:NO];
|
||||
|
||||
[mxkViewController.navigationController pushViewController:widgetVC animated:YES];
|
||||
|
||||
} failure:^(NSError * _Nonnull error) {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#import "WebViewViewController.h"
|
||||
|
||||
#import "WidgetManager.h"
|
||||
#import "MatrixKit/MatrixKit.h"
|
||||
|
||||
/**
|
||||
`WidgetViewController` displays widget within a webview.
|
||||
@@ -26,6 +27,12 @@
|
||||
*/
|
||||
@interface WidgetViewController : WebViewViewController
|
||||
|
||||
/**
|
||||
The room data source.
|
||||
Required if the widget needs to post messages.
|
||||
*/
|
||||
@property (nonatomic) MXKRoomDataSource *roomDataSource;
|
||||
|
||||
/**
|
||||
Init 'WidgetViewController' instance with a widget.
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
NSString *const kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@', %@);";
|
||||
NSString *const kJavascriptSendResponseToPostMessageAPI = @"riotIOS.sendResponse('%@', %@);";
|
||||
|
||||
@interface WidgetViewController ()
|
||||
{
|
||||
@@ -186,13 +186,42 @@ NSString *const kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@',
|
||||
|
||||
- (void)onPostMessageRequest:(NSString*)requestId data:(NSDictionary*)requestData
|
||||
{
|
||||
// TODO
|
||||
NSString *action;
|
||||
MXJSONModelSetString(action, requestData[@"action"]);
|
||||
|
||||
if ([@"m.sticker" isEqualToString:action])
|
||||
{
|
||||
// Extract the sticker event content and send it as is
|
||||
|
||||
// The key should be "data" according to https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit?usp=sharing
|
||||
// TODO: Fix it once spec is finalised
|
||||
NSDictionary *widgetData;
|
||||
NSDictionary *stickerContent;
|
||||
MXJSONModelSetDictionary(widgetData, requestData[@"widgetData"]);
|
||||
if (widgetData)
|
||||
{
|
||||
MXJSONModelSetDictionary(stickerContent, widgetData[@"content"]);
|
||||
}
|
||||
|
||||
if (stickerContent)
|
||||
{
|
||||
// Let the data source manage the sending cycle
|
||||
[_roomDataSource sendEventOfType:kMXEventTypeStringSticker content:stickerContent success:nil failure:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"[WidgetVC] onPostMessageRequest: ERROR: Invalid content for m.sticker: %@", requestData);
|
||||
}
|
||||
|
||||
// Consider we are done with the sticker picker widget
|
||||
[self withdrawViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sendBoolResponse:(BOOL)response toRequest:(NSString*)requestId
|
||||
{
|
||||
// Convert BOOL to "true" or "false"
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToPostMessageAPI,
|
||||
requestId,
|
||||
response ? @"true" : @"false"];
|
||||
|
||||
@@ -201,7 +230,7 @@ NSString *const kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@',
|
||||
|
||||
- (void)sendIntegerResponse:(NSUInteger)response toRequest:(NSString*)requestId
|
||||
{
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToPostMessageAPI,
|
||||
requestId,
|
||||
@(response)];
|
||||
|
||||
@@ -227,7 +256,7 @@ NSString *const kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@',
|
||||
jsString = @"null";
|
||||
}
|
||||
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToModular,
|
||||
NSString *js = [NSString stringWithFormat:kJavascriptSendResponseToPostMessageAPI,
|
||||
requestId,
|
||||
jsString];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user