LCOV - code coverage report
Current view: top level - lib/msc_extensions/msc_1236_widgets - msc_1236_widgets.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 6 18 33.3 %
Date: 2024-09-27 11:38:01 Functions: 0 0 -

          Line data    Source code
       1             : library msc_1236_widgets;
       2             : 
       3             : import 'package:matrix/matrix.dart';
       4             : 
       5             : export 'src/widget.dart';
       6             : 
       7             : extension MatrixWidgets on Room {
       8             :   /// Returns all present Widgets in the room.
       9           4 :   List<MatrixWidget> get widgets => {
      10          10 :         ...states['m.widget'] ?? states['im.vector.modular.widgets'] ?? {},
      11           6 :       }.values.expand((e) {
      12             :         try {
      13           6 :           return [MatrixWidget.fromJson(e.content, this)];
      14             :         } catch (_) {
      15           2 :           return <MatrixWidget>[];
      16             :         }
      17           2 :       }).toList();
      18             : 
      19           0 :   Future<String> addWidget(MatrixWidget widget) {
      20           0 :     final user = client.userID;
      21             :     final widgetId =
      22           0 :         '${widget.name!.toLowerCase().replaceAll(RegExp(r'\W'), '_')}_${user!}';
      23             : 
      24           0 :     final json = widget.toJson();
      25           0 :     json['creatorUserId'] = user;
      26           0 :     json['id'] = widgetId;
      27           0 :     return client.setRoomStateWithKey(
      28           0 :       id,
      29             :       'im.vector.modular.widgets',
      30             :       widgetId,
      31             :       json,
      32             :     );
      33             :   }
      34             : 
      35           0 :   Future<String> deleteWidget(String widgetId) {
      36           0 :     return client.setRoomStateWithKey(
      37           0 :       id,
      38             :       'im.vector.modular.widgets',
      39             :       widgetId,
      40           0 :       {},
      41             :     );
      42             :   }
      43             : }

Generated by: LCOV version 1.14