LCOV - code coverage report
Current view: top level - lib/msc_extensions/msc_3381_polls - poll_room_extension.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 90.0 % 10 9
Test Date: 2025-11-10 08:03:53 Functions: - 0 0

            Line data    Source code
       1              : import 'package:matrix/matrix.dart';
       2              : 
       3              : extension PollRoomExtension on Room {
       4            2 :   Future<String?> startPoll({
       5              :     required String question,
       6              :     required List<PollAnswer> answers,
       7              :     String? body,
       8              :     PollKind kind = PollKind.undisclosed,
       9              :     int maxSelections = 1,
      10              :     String? txid,
      11              :   }) async {
      12            4 :     if (answers.length > 20) {
      13            0 :       throw Exception('Client must not set more than 20 answers in a poll');
      14              :     }
      15              : 
      16              :     if (body == null) {
      17              :       body = question;
      18            6 :       for (var i = 0; i < answers.length; i++) {
      19            6 :         body = '$body\n$i. ${answers[i].mText}';
      20              :       }
      21              :     }
      22              : 
      23            2 :     final newPollEvent = PollEventContent(
      24              :       mText: body!,
      25            2 :       pollStartContent: PollStartContent(
      26              :         kind: kind,
      27              :         maxSelections: maxSelections,
      28            2 :         question: PollQuestion(mText: question),
      29              :         answers: answers,
      30              :       ),
      31              :     );
      32              : 
      33            2 :     return sendEvent(
      34            2 :       newPollEvent.toJson(),
      35              :       type: PollEventContent.startType,
      36              :       txid: txid,
      37              :     );
      38              :   }
      39              : }
        

Generated by: LCOV version 2.0-1