Merge branch 'nico/widget-fix' into 'main'
fix: exception on removed widgets Closes #267 See merge request famedly/company/frontend/famedlysdk!956
This commit is contained in:
commit
e11ec12a63
|
|
@ -374,12 +374,13 @@ class Room {
|
|||
List<MatrixWidget> get widgets => {
|
||||
...states['m.widget'] ?? {},
|
||||
...states['im.vector.modular.widgets'] ?? {},
|
||||
}.values.expand((e) {
|
||||
try {
|
||||
return [MatrixWidget.fromJson(e.content, this)];
|
||||
} catch (_) {
|
||||
return <MatrixWidget>[];
|
||||
}
|
||||
.values
|
||||
.map(
|
||||
(e) => MatrixWidget.fromJson(e.content, this),
|
||||
)
|
||||
.toList();
|
||||
}).toList();
|
||||
|
||||
/// Your current client instance.
|
||||
final Client client;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ class MatrixWidget {
|
|||
final String? creatorUserId;
|
||||
final Map<String, dynamic>? data;
|
||||
final String? id;
|
||||
final String name;
|
||||
final String? name;
|
||||
final String type;
|
||||
|
||||
/// use [buildWidgetUrl] instead
|
||||
|
|
|
|||
|
|
@ -923,6 +923,62 @@ void main() {
|
|||
|
||||
test('Widgets', () {
|
||||
expect(room.widgets.isEmpty, true);
|
||||
room.states['m.widget'] = {
|
||||
'test': Event.fromJson({
|
||||
'content': {
|
||||
'creatorUserId': '@rxl881:matrix.org',
|
||||
'data': {'title': 'Bridges Dashboard', 'dateRange': '1y'},
|
||||
'id': 'grafana_@rxl881:matrix.org_1514573757015',
|
||||
'name': 'Grafana',
|
||||
'type': 'm.grafana',
|
||||
'url': 'https://matrix.org/grafana/whatever',
|
||||
'waitForIframeLoad': true
|
||||
},
|
||||
'room_id': '!foo:bar',
|
||||
'event_id': '\$15104760642668662QICBu:matrix.org',
|
||||
'sender': '@rxl881:matrix.org',
|
||||
'state_key': 'test',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'type': 'm.widget'
|
||||
}, room),
|
||||
};
|
||||
expect(room.widgets.length, 1);
|
||||
room.states['m.widget'] = {
|
||||
'test2': Event.fromJson({
|
||||
'content': {
|
||||
'creatorUserId': '@rxl881:matrix.org',
|
||||
'data': {'title': 'Bridges Dashboard', 'dateRange': '1y'},
|
||||
'id': 'grafana_@rxl881:matrix.org_1514573757016',
|
||||
'type': 'm.grafana',
|
||||
'url': 'https://matrix.org/grafana/whatever',
|
||||
'waitForIframeLoad': true
|
||||
},
|
||||
'room_id': '!foo:bar',
|
||||
'event_id': '\$15104760642668663QICBu:matrix.org',
|
||||
'sender': '@rxl881:matrix.org',
|
||||
'state_key': 'test2',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'type': 'm.widget'
|
||||
}, room),
|
||||
};
|
||||
expect(room.widgets.length, 1);
|
||||
room.states['m.widget'] = {
|
||||
'test3': Event.fromJson({
|
||||
'content': {
|
||||
'creatorUserId': '@rxl881:matrix.org',
|
||||
'data': {'title': 'Bridges Dashboard', 'dateRange': '1y'},
|
||||
'type': 'm.grafana',
|
||||
'waitForIframeLoad': true
|
||||
},
|
||||
'room_id': '!foo:bar',
|
||||
'event_id': '\$15104760642668662QICBu:matrix.org',
|
||||
'sender': '@rxl881:matrix.org',
|
||||
'state_key': 'test3',
|
||||
'origin_server_ts': 1432735824655,
|
||||
'type': 'm.widget'
|
||||
}, room),
|
||||
};
|
||||
expect(room.widgets.length, 0);
|
||||
});
|
||||
|
||||
test('Spaces', () async {
|
||||
|
|
|
|||
Loading…
Reference in New Issue