diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index a4a5c6f10..c22562a43 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -39,10 +39,10 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState:(MXRoomState *)roomState error:(MXKEventFormatterError *)error { - // Build strings for modular widget events - // TODO: At the moment, we support only jitsi widgets + // Build strings for widget events if (event.eventType == MXEventTypeCustom - && [event.type isEqualToString:kWidgetEventTypeString]) + && ([event.type isEqualToString:kWidgetMatrixEventTypeString] + || [event.type isEqualToString:kWidgetModularEventTypeString])) { NSString *displayText; @@ -71,7 +71,11 @@ // This is a closed widget // Check if it corresponds to a jitsi widget by looking at other state events for // this jitsi widget (widget id = event.stateKey). - for (MXEvent *widgetStateEvent in [roomState stateEventsWithType:kWidgetEventTypeString]) + // Get all widgets state events in the room + NSMutableArray *widgetStateEvents = [NSMutableArray arrayWithArray:[roomState stateEventsWithType:kWidgetMatrixEventTypeString]]; + [widgetStateEvents addObjectsFromArray:[roomState stateEventsWithType:kWidgetModularEventTypeString]]; + + for (MXEvent *widgetStateEvent in widgetStateEvents) { if ([widgetStateEvent.stateKey isEqualToString:widget.widgetId]) { diff --git a/Riot/Utils/Widgets/Widget.m b/Riot/Utils/Widgets/Widget.m index 6ccddc56d..cbdd10608 100644 --- a/Riot/Utils/Widgets/Widget.m +++ b/Riot/Utils/Widgets/Widget.m @@ -22,9 +22,12 @@ - (instancetype)initWithWidgetEvent:(MXEvent *)widgetEvent inMatrixSession:(MXSession*)mxSession { - if (![widgetEvent.type isEqualToString:kWidgetEventTypeString]) + // TODO - Room widgets need to be moved to 'm.widget' state events + // https://docs.google.com/document/d/1uPF7XWY_dXTKVKV7jZQ2KmsI19wn9-kFRgQ1tFQP7wQ/edit?usp=sharing + if (![widgetEvent.type isEqualToString:kWidgetMatrixEventTypeString] + && ![widgetEvent.type isEqualToString:kWidgetModularEventTypeString]) { - // The Widget class works only with modular, aka "im.vector.modular.widgets", widgets + // The Widget class works only with modular, aka "m.widget" or "im.vector.modular.widgets", widgets return nil; } diff --git a/Riot/Utils/Widgets/WidgetManager.h b/Riot/Utils/Widgets/WidgetManager.h index 8c2e5d4c5..a10898e29 100644 --- a/Riot/Utils/Widgets/WidgetManager.h +++ b/Riot/Utils/Widgets/WidgetManager.h @@ -21,9 +21,15 @@ #import "Widget.h" /** - The type of matrix event used for modular widgets. + The type of matrix event used for matrix widgets. */ -FOUNDATION_EXPORT NSString *const kWidgetEventTypeString; +FOUNDATION_EXPORT NSString *const kWidgetMatrixEventTypeString; + +/** + The type of matrix event used for modular widgets. + TODO: It should be replaced by kWidgetMatrixEventTypeString. + */ +FOUNDATION_EXPORT NSString *const kWidgetModularEventTypeString; /** Known types widgets. diff --git a/Riot/Utils/Widgets/WidgetManager.m b/Riot/Utils/Widgets/WidgetManager.m index 3adf7db81..d795e77bc 100644 --- a/Riot/Utils/Widgets/WidgetManager.m +++ b/Riot/Utils/Widgets/WidgetManager.m @@ -20,7 +20,8 @@ #pragma mark - Contants -NSString *const kWidgetEventTypeString = @"im.vector.modular.widgets"; +NSString *const kWidgetMatrixEventTypeString = @"m.widget"; +NSString *const kWidgetModularEventTypeString = @"im.vector.modular.widgets"; NSString *const kWidgetTypeJitsi = @"jitsi"; NSString *const kWidgetManagerDidUpdateWidgetNotification = @"kWidgetManagerDidUpdateWidgetNotification"; @@ -102,10 +103,11 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; // Widget id -> widget NSMutableDictionary *widgets = [NSMutableDictionary dictionary]; - // Get all im.vector.modular.widgets state events in the room - NSMutableArray *widgetEvents = [NSMutableArray arrayWithArray:[room.state stateEventsWithType:kWidgetEventTypeString]]; + // Get all widgets state events in the room + NSMutableArray *widgetEvents = [NSMutableArray arrayWithArray:[room.state stateEventsWithType:kWidgetMatrixEventTypeString]]; + [widgetEvents addObjectsFromArray:[room.state stateEventsWithType:kWidgetModularEventTypeString]]; - // There can be several im.vector.modular.widgets state events for a same widget but + // There can be several widgets state events for a same widget but // only the last one must be considered. // Order widgetEvents with the last event first @@ -124,7 +126,7 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; return result; }]; - // Create each widget from its lastest im.vector.modular.widgets state event + // Create each widget from its lastest widgets state event for (MXEvent *widgetEvent in widgetEvents) { // Filter widget types if required @@ -192,7 +194,8 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; // Send a state event with the widget data // TODO: This API will be shortly replaced by a pure modular API - return [room sendStateEventOfType:kWidgetEventTypeString + // TODO: Move to kWidgetMatrixEventTypeString ("m.widget") type but when? + return [room sendStateEventOfType:kWidgetModularEventTypeString content:widgetContent stateKey:widgetId success:nil failure:failure]; @@ -247,7 +250,8 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; // Send a state event with an empty content to disable the widget // TODO: This API will be shortly replaced by a pure modular API - return [room sendStateEventOfType:kWidgetEventTypeString + // TODO: Move to kWidgetMatrixEventTypeString ("m.widget") type but when? + return [room sendStateEventOfType:kWidgetModularEventTypeString content:@{} stateKey:widgetId success:^(NSString *eventId) @@ -292,7 +296,7 @@ NSString *const WidgetManagerErrorDomain = @"WidgetManagerErrorDomain"; NSString *hash = [NSString stringWithFormat:@"%p", mxSession]; - id listener = [mxSession listenToEventsOfTypes:@[kWidgetEventTypeString] onEvent:^(MXEvent *event, MXTimelineDirection direction, id customObject) { + id listener = [mxSession listenToEventsOfTypes:@[kWidgetMatrixEventTypeString, kWidgetModularEventTypeString] onEvent:^(MXEvent *event, MXTimelineDirection direction, id customObject) { typeof(self) self = weakSelf; diff --git a/Riot/ViewController/Widgets/IntegrationManagerViewController.m b/Riot/ViewController/Widgets/IntegrationManagerViewController.m index aabd191c8..35bd62e5e 100644 --- a/Riot/ViewController/Widgets/IntegrationManagerViewController.m +++ b/Riot/ViewController/Widgets/IntegrationManagerViewController.m @@ -522,7 +522,8 @@ NSString *const kJavascriptSendResponseToModular = @"riotIOS.sendResponse('%@', __weak __typeof__(self) weakSelf = self; - [room sendStateEventOfType:kWidgetEventTypeString + // TODO: Move to kWidgetMatrixEventTypeString ("m.widget") type but when? + [room sendStateEventOfType:kWidgetModularEventTypeString content:widgetEventContent stateKey:widget_id success:^(NSString *eventId) {