LCOV - code coverage report
Current view: top level - lib/models/messages - quotedmessage.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 26 0.0 %
Date: 2024-08-22 18:05:30 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : 
       3             : import 'package:cwtch/models/message.dart';
       4             : import 'package:cwtch/models/messages/malformedmessage.dart';
       5             : import 'package:cwtch/widgets/malformedbubble.dart';
       6             : import 'package:cwtch/widgets/messageBubbleWidgetHelpers.dart';
       7             : import 'package:cwtch/widgets/messagerow.dart';
       8             : import 'package:cwtch/widgets/quotedmessage.dart';
       9             : import 'package:flutter/widgets.dart';
      10             : import 'package:provider/provider.dart';
      11             : 
      12             : import '../../settings.dart';
      13             : 
      14             : class QuotedMessageStructure {
      15             :   final String quotedHash;
      16             :   final String body;
      17           0 :   QuotedMessageStructure(this.quotedHash, this.body);
      18             : 
      19           0 :   Map<String, dynamic> toJson() => {
      20           0 :         'quotedHash': quotedHash,
      21           0 :         'body': body,
      22             :       };
      23             : }
      24             : 
      25             : class QuotedMessage extends Message {
      26             :   final MessageMetadata metadata;
      27             :   final String content;
      28           0 :   QuotedMessage(this.metadata, this.content);
      29             : 
      30           0 :   @override
      31             :   Widget getPreviewWidget(BuildContext context, {BoxConstraints? constraints}) {
      32           0 :     return ChangeNotifierProvider.value(
      33           0 :         value: this.metadata,
      34           0 :         builder: (bcontext, child) {
      35             :           try {
      36           0 :             dynamic message = jsonDecode(
      37           0 :               this.content,
      38             :             );
      39           0 :             var content = message["body"];
      40           0 :             var formatMessages = Provider.of<Settings>(bcontext).isExperimentEnabled(FormattingExperiment);
      41           0 :             return compileMessageContentWidget(context, constraints ?? BoxConstraints.loose(MediaQuery.sizeOf(context)), false, content, FocusNode(), formatMessages, false);
      42             :           } catch (e) {
      43           0 :             return MalformedBubble();
      44             :           }
      45             :         });
      46             :   }
      47             : 
      48           0 :   @override
      49             :   MessageMetadata getMetadata() {
      50           0 :     return this.metadata;
      51             :   }
      52             : 
      53           0 :   @override
      54             :   Widget getWidget(BuildContext context, Key key, int index) {
      55             :     try {
      56           0 :       dynamic message = jsonDecode(this.content);
      57             : 
      58           0 :       if (message["body"] == null || message["quotedHash"] == null) {
      59           0 :         return MalformedMessage(this.metadata).getWidget(context, key, index);
      60             :       }
      61             : 
      62           0 :       return ChangeNotifierProvider.value(
      63           0 :           value: this.metadata,
      64           0 :           builder: (bcontext, child) {
      65           0 :             return MessageRow(QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, ByContentHash(message["quotedHash"]))), index,
      66             :                 key: key);
      67             :           });
      68             :     } catch (e) {
      69           0 :       return MalformedMessage(this.metadata).getWidget(context, key, index);
      70             :     }
      71             :   }
      72             : }

Generated by: LCOV version 1.14