LCOV - code coverage report
Current view: top level - lib/msc_extensions/msc_1236_widgets - msc_1236_widgets.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 33.3 % 18 6
Test Date: 2025-01-14 13:39:53 Functions: - 0 0

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

Generated by: LCOV version 2.0-1