Merge branch 'widgets' into 'main'
feat: implement mofifying widgets See merge request famedly/company/frontend/famedlysdk!983
This commit is contained in:
commit
118f2e6b97
|
|
@ -368,8 +368,7 @@ class Room {
|
|||
|
||||
/// Returns all present Widgets in the room.
|
||||
List<MatrixWidget> get widgets => {
|
||||
...states['m.widget'] ?? {},
|
||||
...states['im.vector.modular.widgets'] ?? {},
|
||||
...states['m.widget'] ?? states['im.vector.modular.widgets'] ?? {},
|
||||
}.values.expand((e) {
|
||||
try {
|
||||
return [MatrixWidget.fromJson(e.content, this)];
|
||||
|
|
@ -378,6 +377,31 @@ class Room {
|
|||
}
|
||||
}).toList();
|
||||
|
||||
Future<String> addWidget(MatrixWidget widget) {
|
||||
final user = client.userID;
|
||||
final widgetId =
|
||||
widget.name!.toLowerCase().replaceAll(RegExp(r'\W'), '_') + '_' + user!;
|
||||
|
||||
final json = widget.toJson();
|
||||
json['creatorUserId'] = user;
|
||||
json['id'] = widgetId;
|
||||
return client.setRoomStateWithKey(
|
||||
id,
|
||||
'im.vector.modular.widgets',
|
||||
widgetId,
|
||||
json,
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> deleteWidget(String widgetId) {
|
||||
return client.setRoomStateWithKey(
|
||||
id,
|
||||
'im.vector.modular.widgets',
|
||||
widgetId,
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
/// Your current client instance.
|
||||
final Client client;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,55 @@ class MatrixWidget {
|
|||
: false,
|
||||
);
|
||||
|
||||
/// creates an `m.etherpad` [MatrixWidget]
|
||||
factory MatrixWidget.etherpad(Room room, String name, Uri url) =>
|
||||
MatrixWidget(
|
||||
room: room,
|
||||
name: name,
|
||||
type: 'm.etherpad',
|
||||
url: url.toString(),
|
||||
data: {
|
||||
'url': url.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
/// creates an `m.jitsi` [MatrixWidget]
|
||||
factory MatrixWidget.jitsi(Room room, String name, Uri url,
|
||||
{bool isAudioOnly = false}) =>
|
||||
MatrixWidget(
|
||||
room: room,
|
||||
name: name,
|
||||
type: 'm.jitsi',
|
||||
url: url.toString(),
|
||||
data: {
|
||||
'domain': url.host,
|
||||
'conferenceId': url.pathSegments.last,
|
||||
'isAudioOnly': isAudioOnly,
|
||||
},
|
||||
);
|
||||
|
||||
/// creates an `m.video` [MatrixWidget]
|
||||
factory MatrixWidget.video(Room room, String name, Uri url) => MatrixWidget(
|
||||
room: room,
|
||||
name: name,
|
||||
type: 'm.video',
|
||||
url: url.toString(),
|
||||
data: {
|
||||
'url': url.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
/// creates an `m.custom` [MatrixWidget]
|
||||
factory MatrixWidget.custom(Room room, String name, Uri url) => MatrixWidget(
|
||||
room: room,
|
||||
name: name,
|
||||
type: 'm.custom',
|
||||
url: url.toString(),
|
||||
data: {
|
||||
'url': url.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
Future<Uri> buildWidgetUrl() async {
|
||||
// See https://github.com/matrix-org/matrix-doc/issues/1236 for a
|
||||
// description, specifically the section
|
||||
|
|
@ -66,4 +115,14 @@ class MatrixWidget {
|
|||
|
||||
return Uri.parse(parsedUri);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'creatorUserId': creatorUserId,
|
||||
'data': data,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'url': url,
|
||||
'waitForIframeLoad': waitForIframeLoad,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue