LCOV - code coverage report
Current view: top level - lib/widgets - messagebubble.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 38 0.0 %
Date: 2024-09-10 17:47:43 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/models/contact.dart';
       2             : import 'package:cwtch/models/message.dart';
       3             : import 'package:cwtch/models/redaction.dart';
       4             : import 'package:cwtch/models/profile.dart';
       5             : import 'package:cwtch/widgets/malformedbubble.dart';
       6             : import 'package:flutter/material.dart';
       7             : import 'package:provider/provider.dart';
       8             : 
       9             : import '../settings.dart';
      10             : import 'messageBubbleWidgetHelpers.dart';
      11             : import 'messagebubbledecorations.dart';
      12             : 
      13             : class MessageBubble extends StatefulWidget {
      14             :   final String content;
      15             : 
      16           0 :   MessageBubble(this.content);
      17             : 
      18           0 :   @override
      19           0 :   MessageBubbleState createState() => MessageBubbleState();
      20             : }
      21             : 
      22             : class MessageBubbleState extends State<MessageBubble> {
      23             :   FocusNode _focus = FocusNode();
      24             : 
      25           0 :   @override
      26             :   Widget build(BuildContext context) {
      27           0 :     var fromMe = Provider.of<MessageMetadata>(context).senderHandle == Provider.of<ProfileInfoState>(context).onion;
      28             :     var borderRadiousEh = 15.0;
      29           0 :     var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
      30           0 :     var formatMessages = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
      31           0 :     DateTime messageDate = Provider.of<MessageMetadata>(context).timestamp;
      32             : 
      33             :     // If the sender is not us, then we want to give them a nickname...
      34             :     var senderDisplayStr = "";
      35             :     if (!fromMe) {
      36           0 :       ContactInfoState? contact = Provider.of<ProfileInfoState>(context).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
      37             :       if (contact != null) {
      38           0 :         senderDisplayStr = redactedNick(context, contact.onion, contact.nickname);
      39             :       } else {
      40           0 :         senderDisplayStr = Provider.of<MessageMetadata>(context).senderHandle;
      41             :       }
      42             :     }
      43             : 
      44           0 :     Size size = MediaQuery.sizeOf(context);
      45             : 
      46           0 :     var wdgSender = compileSenderWidget(context, null, fromMe, senderDisplayStr);
      47           0 :     var wdgMessage = compileMessageContentWidget(context, BoxConstraints.loose(size), fromMe, widget.content, _focus, formatMessages, showClickableLinks);
      48           0 :     var wdgDecorations = MessageBubbleDecoration(ackd: Provider.of<MessageMetadata>(context).ackd, errored: Provider.of<MessageMetadata>(context).error, fromMe: fromMe, messageDate: messageDate);
      49           0 :     var error = Provider.of<MessageMetadata>(context).error;
      50             : 
      51           0 :     return Container(
      52           0 :         decoration: BoxDecoration(
      53           0 :           color: error ? malformedColor : (fromMe ? Provider.of<Settings>(context).theme.messageFromMeBackgroundColor : Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
      54           0 :           border: Border.all(
      55           0 :               color: error ? malformedColor : (fromMe ? Provider.of<Settings>(context).theme.messageFromMeBackgroundColor : Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
      56             :               width: 1),
      57           0 :           borderRadius: BorderRadius.only(
      58           0 :             topLeft: Radius.circular(borderRadiousEh),
      59           0 :             topRight: Radius.circular(borderRadiousEh),
      60           0 :             bottomLeft: fromMe ? Radius.circular(borderRadiousEh) : Radius.zero,
      61           0 :             bottomRight: fromMe ? Radius.zero : Radius.circular(borderRadiousEh),
      62             :           ),
      63             :         ),
      64           0 :         child: Padding(
      65           0 :             padding: EdgeInsets.all(9.0),
      66           0 :             child: Theme(
      67           0 :                 data: Theme.of(context).copyWith(
      68           0 :                   textSelectionTheme: TextSelectionThemeData(
      69           0 :                       cursorColor: Provider.of<Settings>(context).theme.messageSelectionColor,
      70           0 :                       selectionColor: Provider.of<Settings>(context).theme.messageSelectionColor,
      71           0 :                       selectionHandleColor: Provider.of<Settings>(context).theme.messageSelectionColor),
      72             : 
      73             :                   // Horrifying Hack: Flutter doesn't give us direct control over system menus but instead picks BG color from TextButtonThemeData ¯\_(ツ)_/¯
      74           0 :                   textButtonTheme: TextButtonThemeData(
      75           0 :                     style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Provider.of<Settings>(context).theme.menuBackgroundColor)),
      76             :                   ),
      77             :                 ),
      78           0 :                 child: Column(
      79             :                     crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
      80             :                     mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start,
      81             :                     mainAxisSize: MainAxisSize.min,
      82           0 :                     children: fromMe ? [wdgMessage, wdgDecorations] : [wdgSender, wdgMessage, wdgDecorations]))));
      83             :   }
      84             : }

Generated by: LCOV version 1.14