LCOV - code coverage report
Current view: top level - lib/views - messageview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 560 0.0 %
Date: 2024-11-08 20:12:38 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:async';
       2             : import 'dart:convert';
       3             : import 'dart:io';
       4             : import 'dart:math';
       5             : import 'package:crypto/crypto.dart';
       6             : import 'package:cwtch/cwtch/cwtch.dart';
       7             : import 'package:cwtch/cwtch_icons_icons.dart';
       8             : import 'package:cwtch/models/appstate.dart';
       9             : import 'package:cwtch/models/chatmessage.dart';
      10             : import 'package:cwtch/models/contact.dart';
      11             : import 'package:cwtch/models/message.dart';
      12             : import 'package:cwtch/models/messagecache.dart';
      13             : import 'package:cwtch/models/messages/quotedmessage.dart';
      14             : import 'package:cwtch/models/profile.dart';
      15             : import 'package:cwtch/models/search.dart';
      16             : import 'package:cwtch/themes/opaque.dart';
      17             : import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
      18             : import 'package:cwtch/widgets/conversation_options.dart';
      19             : import 'package:cwtch/widgets/malformedbubble.dart';
      20             : import 'package:cwtch/widgets/messageloadingbubble.dart';
      21             : import 'package:cwtch/widgets/profileimage.dart';
      22             : import 'package:cwtch/controllers/filesharing.dart' as filesharing;
      23             : import 'package:cwtch/widgets/staticmessagebubble.dart';
      24             : import 'package:flutter/material.dart';
      25             : import 'package:cwtch/views/peersettingsview.dart';
      26             : import 'package:cwtch/widgets/DropdownContacts.dart';
      27             : import 'package:flutter/services.dart';
      28             : import 'package:provider/provider.dart';
      29             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
      30             : import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
      31             : 
      32             : import '../config.dart';
      33             : import '../constants.dart';
      34             : import '../main.dart';
      35             : import '../settings.dart';
      36             : import '../widgets/messagelist.dart';
      37             : import 'filesharingview.dart';
      38             : import 'groupsettingsview.dart';
      39             : 
      40             : class MessageView extends StatefulWidget {
      41           0 :   @override
      42           0 :   _MessageViewState createState() => _MessageViewState();
      43             : }
      44             : 
      45             : class _MessageViewState extends State<MessageView> {
      46             :   final focusNode = FocusNode();
      47             :   int selectedContact = -1;
      48             :   ItemPositionsListener scrollListener = ItemPositionsListener.create();
      49             :   File? imagePreview;
      50             :   bool showDown = false;
      51             :   bool showPreview = false;
      52             :   final scaffoldKey = GlobalKey<ScaffoldState>(); // <---- Another instance variable
      53           0 :   @override
      54             :   void initState() {
      55           0 :     scrollListener.itemPositions.addListener(() {
      56           0 :       if (scrollListener.itemPositions.value.length != 0 &&
      57           0 :           Provider.of<AppState>(context, listen: false).unreadMessagesBelow == true &&
      58           0 :           scrollListener.itemPositions.value.any((element) => element.index == 0)) {
      59           0 :         Provider.of<AppState>(context, listen: false).initialScrollIndex = 0;
      60           0 :         Provider.of<AppState>(context, listen: false).unreadMessagesBelow = false;
      61             :       }
      62             : 
      63           0 :       if (scrollListener.itemPositions.value.length != 0 && !scrollListener.itemPositions.value.any((element) => element.index == 0)) {
      64           0 :         showDown = true;
      65             :       } else {
      66           0 :         showDown = false;
      67             :       }
      68             :     });
      69           0 :     super.initState();
      70             :   }
      71             : 
      72           0 :   @override
      73             :   void didChangeDependencies() {
      74           0 :     var appState = Provider.of<AppState>(context, listen: false);
      75             : 
      76             :     // using "8" because "# of messages that fit on one screen" isnt trivial to calculate at this point
      77           0 :     if (appState.initialScrollIndex > 4 && appState.unreadMessagesBelow == false) {
      78           0 :       WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) {
      79           0 :         appState.unreadMessagesBelow = true;
      80             :       });
      81             :     }
      82           0 :     super.didChangeDependencies();
      83             :   }
      84             : 
      85           0 :   @override
      86             :   void dispose() {
      87           0 :     focusNode.dispose();
      88           0 :     super.dispose();
      89             :   }
      90             : 
      91           0 :   @override
      92             :   Widget build(BuildContext context) {
      93             :     // After leaving a conversation the selected conversation is set to null...
      94           0 :     if (Provider.of<ContactInfoState>(context, listen: false).profileOnion == "") {
      95           0 :       return Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Center(child: Text(AppLocalizations.of(context)!.addContactFirst)));
      96             :     }
      97             : 
      98           0 :     var showMessageFormattingPreview = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
      99           0 :     var showFileSharing = Provider.of<Settings>(context).isExperimentEnabled(FileSharingExperiment);
     100           0 :     var appBarButtons = <Widget>[];
     101             : 
     102           0 :     var profile = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
     103           0 :     var conversation = Provider.of<ContactInfoState>(context, listen: false).identifier;
     104             : 
     105           0 :     if (Provider.of<FlwtchState>(context, listen: false).cwtch.IsBlodeuweddSupported() && Provider.of<Settings>(context).isExperimentEnabled(BlodeuweddExperiment)) {
     106           0 :       appBarButtons.add(IconButton(
     107           0 :           splashRadius: Material.defaultSplashRadius / 2,
     108           0 :           icon: Icon(Icons.summarize),
     109           0 :           tooltip: AppLocalizations.of(context)!.blodeuweddSummarize,
     110           0 :           onPressed: () async {
     111           0 :             Provider.of<ContactInfoState>(context, listen: false).summary = "";
     112           0 :             Provider.of<ContactInfoState>(context, listen: false).updateSummaryEvent("");
     113           0 :             Provider.of<FlwtchState>(context, listen: false).cwtch.SummarizeConversation(profile, conversation);
     114           0 :             _summarizeConversation(context, Provider.of<ProfileInfoState>(context, listen: false), Provider.of<Settings>(context, listen: false));
     115             :           }));
     116             :     }
     117             : 
     118           0 :     if (Provider.of<ContactInfoState>(context).isOnline()) {
     119             :       if (showFileSharing) {
     120           0 :         appBarButtons.add(IconButton(
     121           0 :           splashRadius: Material.defaultSplashRadius / 2,
     122           0 :           icon: Icon(CwtchIcons.attached_file_3, size: 26, color: Provider.of<Settings>(context).theme.mainTextColor),
     123           0 :           tooltip: AppLocalizations.of(context)!.tooltipSendFile,
     124           0 :           onPressed: Provider.of<AppState>(context).disableFilePicker
     125             :               ? null
     126           0 :               : () {
     127           0 :                   imagePreview = null;
     128           0 :                   filesharing.showFilePicker(context, MaxGeneralFileSharingSize, (File file) {
     129           0 :                     _confirmFileSend(context, file.path);
     130           0 :                   }, () {
     131           0 :                     final snackBar = SnackBar(
     132           0 :                       content: Text(AppLocalizations.of(context)!.msgFileTooBig),
     133           0 :                       duration: Duration(seconds: 4),
     134             :                     );
     135           0 :                     ScaffoldMessenger.of(context).showSnackBar(snackBar);
     136           0 :                   }, () {});
     137             :                 },
     138             :         ));
     139             :       }
     140             : 
     141           0 :       appBarButtons.add(IconButton(
     142           0 :           splashRadius: Material.defaultSplashRadius / 2,
     143           0 :           icon: Icon(CwtchIcons.send_invite, size: 24),
     144           0 :           tooltip: AppLocalizations.of(context)!.sendInvite,
     145           0 :           onPressed: () {
     146           0 :             _modalSendInvitation(context);
     147             :           }));
     148             :     }
     149             : 
     150           0 :     appBarButtons.add(ConversationOptions(_pushContactSettings, _pushFileSharingSettings));
     151             : 
     152           0 :     var appState = Provider.of<AppState>(context);
     153           0 :     return PopScope(
     154           0 :         onPopInvoked: _onWillPop,
     155           0 :         child: Scaffold(
     156           0 :           backgroundColor: Provider.of<Settings>(context).theme.backgroundMainColor,
     157           0 :           floatingActionButton: showDown
     158           0 :               ? FloatingActionButton(
     159             :                   // heroTags need to be unique per screen (important when we pop up and down)...
     160           0 :                   heroTag: "popDown" + Provider.of<ContactInfoState>(context, listen: false).onion,
     161           0 :                   child: Icon(Icons.arrow_downward, color: Provider.of<Settings>(context).current().defaultButtonTextColor),
     162           0 :                   onPressed: () {
     163           0 :                     Provider.of<AppState>(context, listen: false).initialScrollIndex = 0;
     164           0 :                     Provider.of<AppState>(context, listen: false).unreadMessagesBelow = false;
     165           0 :                     Provider.of<ContactInfoState>(context, listen: false).messageScrollController.scrollTo(index: 0, duration: Duration(milliseconds: 600));
     166             :                   })
     167             :               : null,
     168           0 :           appBar: AppBar(
     169             :             // setting leading(Width) to null makes it do the default behaviour; container() hides it
     170           0 :             leadingWidth: Provider.of<Settings>(context).uiColumns(appState.isLandscape(context)).length > 1 ? 0 : null,
     171           0 :             leading: Provider.of<Settings>(context).uiColumns(appState.isLandscape(context)).length > 1
     172           0 :                 ? Container(
     173             :                     padding: EdgeInsets.zero,
     174             :                     margin: EdgeInsets.zero,
     175             :                     width: 0,
     176             :                     height: 0,
     177             :                   )
     178             :                 : null,
     179           0 :             title: Row(children: [
     180           0 :               ProfileImage(
     181           0 :                   imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
     182           0 :                       ? Provider.of<ContactInfoState>(context).imagePath
     183           0 :                       : Provider.of<ContactInfoState>(context).defaultImagePath,
     184             :                   diameter: 42,
     185           0 :                   border: Provider.of<ContactInfoState>(context).getBorderColor(Provider.of<Settings>(context).theme),
     186             :                   badgeTextColor: Colors.red,
     187           0 :                   badgeColor: Provider.of<Settings>(context).theme.portraitContactBadgeColor,
     188           0 :                   badgeIcon: Provider.of<ContactInfoState>(context).isGroup
     189           0 :                       ? (Tooltip(
     190           0 :                           message: Provider.of<ContactInfoState>(context).isOnline()
     191           0 :                               ? Provider.of<ContactInfoState>(context).antispamTickets == 0
     192           0 :                                   ? AppLocalizations.of(context)!.acquiringTicketsFromServer
     193           0 :                                   : AppLocalizations.of(context)!.acquiredTicketsFromServer
     194           0 :                               : AppLocalizations.of(context)!.serverConnectivityDisconnected,
     195           0 :                           child: Provider.of<ContactInfoState>(context).isOnline()
     196           0 :                               ? Provider.of<ContactInfoState>(context).antispamTickets == 0
     197           0 :                                   ? Icon(
     198             :                                       CwtchIcons.anti_spam_3,
     199             :                                       size: 14.0,
     200           0 :                                       semanticLabel: AppLocalizations.of(context)!.acquiringTicketsFromServer,
     201           0 :                                       color: Provider.of<Settings>(context).theme.portraitContactBadgeTextColor,
     202             :                                     )
     203           0 :                                   : Icon(
     204             :                                       CwtchIcons.anti_spam_2,
     205           0 :                                       color: Provider.of<Settings>(context).theme.portraitContactBadgeTextColor,
     206             :                                       size: 14.0,
     207             :                                     )
     208           0 :                               : Icon(
     209             :                                   CwtchIcons.onion_off,
     210           0 :                                   color: Provider.of<Settings>(context).theme.portraitContactBadgeTextColor,
     211             :                                   size: 14.0,
     212             :                                 )))
     213             :                       : null),
     214           0 :               SizedBox(
     215             :                 width: 10,
     216             :               ),
     217           0 :               Expanded(
     218           0 :                   child: Container(
     219             :                       height: 42,
     220             :                       clipBehavior: Clip.hardEdge,
     221           0 :                       decoration: BoxDecoration(),
     222           0 :                       child: Align(
     223             :                           alignment: Alignment.centerLeft,
     224           0 :                           child: Text(
     225           0 :                             Provider.of<ContactInfoState>(context).augmentedNickname(context),
     226           0 :                             style: TextStyle(fontFamily: "Inter", fontWeight: FontWeight.bold, fontSize: 14.0 * Provider.of<Settings>(context).fontScaling),
     227             :                             overflow: TextOverflow.clip,
     228             :                             maxLines: 1,
     229             :                           ))))
     230             :             ]),
     231             :             actions: appBarButtons,
     232             :           ),
     233           0 :           body: Padding(
     234           0 :               padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 164.0),
     235           0 :               child: MessageList(
     236           0 :                 scrollListener,
     237             :               )),
     238           0 :           bottomSheet: showPreview && showMessageFormattingPreview ? _buildPreviewBox() : _buildComposeBox(context),
     239             :         ));
     240             :   }
     241             : 
     242           0 :   Future<bool> _onWillPop(popd) async {
     243           0 :     Provider.of<ContactInfoState>(context, listen: false).unreadMessages = 0;
     244             : 
     245           0 :     var previouslySelected = Provider.of<AppState>(context, listen: false).selectedConversation;
     246             :     if (previouslySelected != null) {
     247           0 :       Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(previouslySelected)!.unselected();
     248             :     }
     249           0 :     Provider.of<SearchState>(context, listen: false).clearSearch();
     250           0 :     Provider.of<AppState>(context, listen: false).selectedConversation = null;
     251           0 :     Provider.of<AppState>(context, listen: false).initialScrollIndex = 0;
     252             :     return true;
     253             :   }
     254             : 
     255           0 :   void _pushFileSharingSettings() {
     256           0 :     var profileInfoState = Provider.of<ProfileInfoState>(context, listen: false);
     257           0 :     var contactInfoState = Provider.of<ContactInfoState>(context, listen: false);
     258           0 :     Navigator.of(context).push(
     259           0 :       PageRouteBuilder(
     260           0 :         pageBuilder: (builderContext, a1, a2) {
     261           0 :           return MultiProvider(
     262           0 :             providers: [ChangeNotifierProvider.value(value: profileInfoState), ChangeNotifierProvider.value(value: contactInfoState)],
     263           0 :             child: FileSharingView(),
     264             :           );
     265             :         },
     266           0 :         transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     267           0 :         transitionDuration: Duration(milliseconds: 200),
     268             :       ),
     269             :     );
     270             :   }
     271             : 
     272           0 :   void _pushContactSettings() {
     273           0 :     var profileInfoState = Provider.of<ProfileInfoState>(context, listen: false);
     274           0 :     var contactInfoState = Provider.of<ContactInfoState>(context, listen: false);
     275             : 
     276           0 :     if (Provider.of<ContactInfoState>(context, listen: false).isGroup == true) {
     277           0 :       Navigator.of(context).push(
     278           0 :         PageRouteBuilder(
     279           0 :           pageBuilder: (builderContext, a1, a2) {
     280           0 :             return MultiProvider(
     281           0 :               providers: [ChangeNotifierProvider.value(value: profileInfoState), ChangeNotifierProvider.value(value: contactInfoState)],
     282           0 :               child: GroupSettingsView(),
     283             :             );
     284             :           },
     285           0 :           transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     286           0 :           transitionDuration: Duration(milliseconds: 200),
     287             :         ),
     288             :       );
     289             :     } else {
     290           0 :       Navigator.of(context).push(
     291           0 :         PageRouteBuilder(
     292           0 :           pageBuilder: (builderContext, a1, a2) {
     293           0 :             return MultiProvider(
     294           0 :               providers: [ChangeNotifierProvider.value(value: profileInfoState), ChangeNotifierProvider.value(value: contactInfoState)],
     295           0 :               child: PeerSettingsView(),
     296             :             );
     297             :           },
     298           0 :           transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     299           0 :           transitionDuration: Duration(milliseconds: 200),
     300             :         ),
     301             :       );
     302             :     }
     303             :   }
     304             : 
     305             :   // todo: legacy groups currently have restricted message
     306             :   // size because of the additional wrapping end encoding
     307             :   // hybrid groups should allow these numbers to be the same.
     308             :   static const P2PMessageLengthMax = 7000;
     309             :   static const GroupMessageLengthMax = 1600;
     310             : 
     311           0 :   void _sendMessage([String? ignoredParam]) {
     312             :     // Do this after we trim to preserve enter-behaviour...
     313           0 :     bool cannotSend = Provider.of<ContactInfoState>(context, listen: false).canSend() == false;
     314           0 :     bool isGroup = Provider.of<ContactInfoState>(context, listen: false).isGroup;
     315             :     if (cannotSend) {
     316             :       return;
     317             :     }
     318             : 
     319           0 :     var attachedInvite = Provider.of<ContactInfoState>(context, listen: false).messageDraft.getInviteHandle();
     320             :     if (attachedInvite != null) {
     321           0 :       this._sendInvitation(attachedInvite);
     322             :     }
     323             : 
     324             :     // Trim message
     325           0 :     var messageText = Provider.of<ContactInfoState>(context, listen: false).messageDraft.messageText ?? "";
     326           0 :     final messageWithoutNewLine = messageText.trimRight();
     327             : 
     328             :     // peers and groups currently have different length constraints (servers can store less)...
     329           0 :     var actualMessageLength = messageText.length;
     330           0 :     var lengthOk = (isGroup && actualMessageLength < GroupMessageLengthMax) || actualMessageLength <= P2PMessageLengthMax;
     331             : 
     332           0 :     if (messageWithoutNewLine.isNotEmpty && lengthOk) {
     333           0 :       if (Provider.of<AppState>(context, listen: false).selectedConversation != null && Provider.of<ContactInfoState>(context, listen: false).messageDraft.getQuotedMessage() != null) {
     334           0 :         var conversationId = Provider.of<AppState>(context, listen: false).selectedConversation!;
     335           0 :         MessageCache? cache = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(conversationId)?.messageCache;
     336           0 :         ById(Provider.of<ContactInfoState>(context, listen: false).messageDraft.getQuotedMessage()!.index)
     337           0 :             .get(Provider.of<FlwtchState>(context, listen: false).cwtch, Provider.of<AppState>(context, listen: false).selectedProfile!, conversationId, cache!)
     338           0 :             .then((MessageInfo? data) {
     339             :           try {
     340           0 :             var bytes1 = utf8.encode(data!.metadata.senderHandle + data.wrapper);
     341           0 :             var digest1 = sha256.convert(bytes1);
     342           0 :             var contentHash = base64Encode(digest1.bytes);
     343           0 :             var quotedMessage = jsonEncode(QuotedMessageStructure(contentHash, messageWithoutNewLine));
     344           0 :             ChatMessage cm = new ChatMessage(o: QuotedMessageOverlay, d: quotedMessage);
     345           0 :             Provider.of<FlwtchState>(context, listen: false)
     346           0 :                 .cwtch
     347           0 :                 .SendMessage(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, jsonEncode(cm))
     348           0 :                 .then(_sendMessageHandler);
     349             :           } catch (e) {
     350           0 :             EnvironmentConfig.debugLog("Exception: reply to message could not be found: " + e.toString());
     351             :           }
     352           0 :           Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearQuotedReference();
     353             :         });
     354             :       } else {
     355           0 :         ChatMessage cm = new ChatMessage(o: TextMessageOverlay, d: messageWithoutNewLine);
     356           0 :         Provider.of<FlwtchState>(context, listen: false)
     357           0 :             .cwtch
     358           0 :             .SendMessage(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, jsonEncode(cm))
     359           0 :             .then(_sendMessageHandler);
     360             :       }
     361             :     }
     362             :   }
     363             : 
     364           0 :   void _sendInvitation(int contact) {
     365           0 :     Provider.of<FlwtchState>(context, listen: false)
     366           0 :         .cwtch
     367           0 :         .SendInvitation(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, contact)
     368           0 :         .then(_sendMessageHandler);
     369             :   }
     370             : 
     371           0 :   void _sendFile(String filePath) {
     372           0 :     Provider.of<FlwtchState>(context, listen: false)
     373           0 :         .cwtch
     374           0 :         .ShareFile(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, filePath)
     375           0 :         .then(_sendMessageHandler);
     376             :   }
     377             : 
     378           0 :   void _sendMessageHandler(dynamic messageJson) {
     379           0 :     if (Provider.of<ContactInfoState>(context, listen: false).isGroup && Provider.of<ContactInfoState>(context, listen: false).antispamTickets == 0) {
     380           0 :       final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.acquiringTicketsFromServer));
     381           0 :       ScaffoldMessenger.of(context).showSnackBar(snackBar);
     382             :       return;
     383             :     }
     384             : 
     385             :     // At this point we have decided to send the text to the backend, failure is still possible
     386             :     // but it will show as an error-ed message, as such the draft can be purged.
     387           0 :     Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearDraft();
     388             : 
     389           0 :     var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
     390           0 :     var identifier = Provider.of<ContactInfoState>(context, listen: false).identifier;
     391           0 :     var profile = Provider.of<ProfileInfoState>(context, listen: false);
     392             : 
     393           0 :     var messageInfo = messageJsonToInfo(profileOnion, identifier, messageJson);
     394             :     if (messageInfo != null) {
     395           0 :       profile.newMessage(
     396           0 :         messageInfo.metadata.conversationIdentifier,
     397           0 :         messageInfo.metadata.messageID,
     398           0 :         messageInfo.metadata.timestamp,
     399           0 :         messageInfo.metadata.senderHandle,
     400           0 :         messageInfo.metadata.senderImage ?? "",
     401           0 :         messageInfo.metadata.isAuto,
     402           0 :         messageInfo.wrapper,
     403           0 :         messageInfo.metadata.contenthash,
     404             :         true,
     405             :         true,
     406             :       );
     407             :     }
     408             : 
     409           0 :     Provider.of<FlwtchState>(context, listen: false).cwtch.SetConversationAttribute(profileOnion, identifier, LastMessageSeenTimeKey, DateTime.now().toIso8601String());
     410           0 :     focusNode.requestFocus();
     411           0 :     Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearDraft();
     412             :   }
     413             : 
     414           0 :   Widget senderInviteChrome(String chrome, String targetName) {
     415           0 :     var settings = Provider.of<Settings>(context);
     416             : 
     417           0 :     return Wrap(children: [
     418           0 :       SelectableText(
     419           0 :         chrome + '\u202F',
     420           0 :         style: settings.scaleFonts(defaultMessageTextStyle.copyWith(color: Provider.of<Settings>(context).theme.messageFromMeTextColor)),
     421             :         textAlign: TextAlign.left,
     422             :         maxLines: 2,
     423             :         textWidthBasis: TextWidthBasis.longestLine,
     424             :       ),
     425           0 :       SelectableText(
     426           0 :         targetName + '\u202F',
     427           0 :         style: settings.scaleFonts(defaultMessageTextStyle.copyWith(color: Provider.of<Settings>(context).theme.messageFromMeTextColor)),
     428             :         textAlign: TextAlign.left,
     429             :         maxLines: 2,
     430             :         textWidthBasis: TextWidthBasis.longestLine,
     431             :       )
     432             :     ]);
     433             :   }
     434             : 
     435           0 :   Widget _buildPreviewBox() {
     436           0 :     var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
     437             : 
     438           0 :     var wdgMessage = Padding(
     439           0 :         padding: EdgeInsets.all(8),
     440           0 :         child: SelectableLinkify(
     441           0 :           text: Provider.of<ContactInfoState>(context).messageDraft.messageText + '\n',
     442           0 :           options: LinkifyOptions(messageFormatting: true, parseLinks: showClickableLinks, looseUrl: true, defaultToHttps: true),
     443           0 :           linkifiers: [UrlLinkifier()],
     444             :           onOpen: showClickableLinks ? null : null,
     445           0 :           style: TextStyle(
     446           0 :             color: Provider.of<Settings>(context).theme.messageFromMeTextColor,
     447             :             fontFamily: "Inter",
     448             :             fontWeight: FontWeight.normal,
     449           0 :             fontSize: 16.0 * Provider.of<Settings>(context).fontScaling,
     450             :           ),
     451           0 :           linkStyle: TextStyle(
     452           0 :             color: Provider.of<Settings>(context).theme.messageFromMeTextColor,
     453             :             fontFamily: "Inter",
     454             :             fontWeight: FontWeight.normal,
     455           0 :             fontSize: 16.0 * Provider.of<Settings>(context).fontScaling,
     456             :           ),
     457           0 :           codeStyle: TextStyle(
     458             :               // note: these colors are flipped
     459             :               fontWeight: FontWeight.normal,
     460           0 :               fontSize: 16.0 * Provider.of<Settings>(context).fontScaling,
     461           0 :               color: Provider.of<Settings>(context).theme.messageFromOtherTextColor,
     462           0 :               backgroundColor: Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
     463             :           textAlign: TextAlign.left,
     464             :           textWidthBasis: TextWidthBasis.longestLine,
     465             :           constraints: null,
     466             :         ));
     467             : 
     468           0 :     var showMessageFormattingPreview = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
     469             :     var preview = showMessageFormattingPreview
     470           0 :         ? IconButton(
     471           0 :             tooltip: AppLocalizations.of(context)!.tooltipBackToMessageEditing,
     472           0 :             icon: Icon(Icons.text_fields),
     473           0 :             onPressed: () {
     474           0 :               setState(() {
     475           0 :                 showPreview = false;
     476             :               });
     477             :             })
     478           0 :         : Container();
     479             : 
     480           0 :     var composeBox = Container(
     481           0 :       color: Provider.of<Settings>(context).theme.backgroundMainColor,
     482           0 :       padding: EdgeInsets.all(2),
     483           0 :       margin: EdgeInsets.all(2),
     484             : 
     485             :       // 164 minimum height + 16px for every line of text so the entire message is displayed when previewed.
     486           0 :       height: 164 + ((Provider.of<ContactInfoState>(context).messageDraft.messageText.split("\n").length - 1) * 16),
     487           0 :       child: Column(
     488           0 :         children: [
     489           0 :           Container(
     490           0 :               decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.toolbarBackgroundColor),
     491           0 :               child: Row(mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [preview])),
     492           0 :           Container(
     493           0 :               decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.defaultButtonActiveColor))),
     494           0 :               child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [wdgMessage])),
     495             :         ],
     496             :       ),
     497             :     );
     498           0 :     return Container(
     499           0 :         color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [composeBox]));
     500             :   }
     501             : 
     502           0 :   Widget _buildComposeBox(BuildContext context) {
     503           0 :     bool cannotSend = Provider.of<ContactInfoState>(context).canSend() == false;
     504           0 :     bool isGroup = Provider.of<ContactInfoState>(context).isGroup;
     505           0 :     var showToolbar = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
     506           0 :     var charLength = Provider.of<ContactInfoState>(context).messageDraft.messageText.characters.length;
     507           0 :     var expectedLength = Provider.of<ContactInfoState>(context).messageDraft.messageText.length;
     508           0 :     var numberOfBytesMoreThanChar = (expectedLength - charLength);
     509             : 
     510           0 :     var bold = IconButton(
     511           0 :         icon: Icon(Icons.format_bold),
     512           0 :         tooltip: AppLocalizations.of(context)!.tooltipBoldText,
     513           0 :         onPressed: () {
     514           0 :           setState(() {
     515           0 :             var ctrlrCompose = Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose;
     516           0 :             var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
     517           0 :             var selection = ctrlrCompose.selection;
     518           0 :             var start = ctrlrCompose.selection.start;
     519           0 :             var end = ctrlrCompose.selection.end;
     520           0 :             ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "**" + selected + "**");
     521           0 :             ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 2, extentOffset: selection.start + 2);
     522           0 :             Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose = ctrlrCompose;
     523             :           });
     524             :         });
     525             : 
     526           0 :     var italic = IconButton(
     527           0 :         icon: Icon(Icons.format_italic),
     528           0 :         tooltip: AppLocalizations.of(context)!.tooltipItalicize,
     529           0 :         onPressed: () {
     530           0 :           setState(() {
     531           0 :             var ctrlrCompose = Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose;
     532           0 :             var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
     533           0 :             var selection = ctrlrCompose.selection;
     534           0 :             var start = ctrlrCompose.selection.start;
     535           0 :             var end = ctrlrCompose.selection.end;
     536           0 :             ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "*" + selected + "*");
     537           0 :             ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
     538           0 :             Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose = ctrlrCompose;
     539             :           });
     540             :         });
     541             : 
     542           0 :     var code = IconButton(
     543           0 :         icon: Icon(Icons.code),
     544           0 :         tooltip: AppLocalizations.of(context)!.tooltipCode,
     545           0 :         onPressed: () {
     546           0 :           setState(() {
     547           0 :             var ctrlrCompose = Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose;
     548           0 :             var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
     549           0 :             var selection = ctrlrCompose.selection;
     550           0 :             var start = ctrlrCompose.selection.start;
     551           0 :             var end = ctrlrCompose.selection.end;
     552           0 :             ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "`" + selected + "`");
     553           0 :             ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
     554           0 :             Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose = ctrlrCompose;
     555             :           });
     556             :         });
     557             : 
     558           0 :     var superscript = IconButton(
     559           0 :         icon: Icon(Icons.superscript),
     560           0 :         tooltip: AppLocalizations.of(context)!.tooltipSuperscript,
     561           0 :         onPressed: () {
     562           0 :           setState(() {
     563           0 :             var ctrlrCompose = Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose;
     564           0 :             var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
     565           0 :             var selection = ctrlrCompose.selection;
     566           0 :             var start = ctrlrCompose.selection.start;
     567           0 :             var end = ctrlrCompose.selection.end;
     568           0 :             ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "^" + selected + "^");
     569           0 :             ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 1, extentOffset: selection.start + 1);
     570           0 :             Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose = ctrlrCompose;
     571             :           });
     572             :         });
     573             : 
     574           0 :     var strikethrough = IconButton(
     575           0 :         icon: Icon(Icons.format_strikethrough),
     576           0 :         tooltip: AppLocalizations.of(context)!.tooltipStrikethrough,
     577           0 :         onPressed: () {
     578           0 :           setState(() {
     579           0 :             var ctrlrCompose = Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose;
     580           0 :             var selected = ctrlrCompose.selection.textInside(ctrlrCompose.text);
     581           0 :             var selection = ctrlrCompose.selection;
     582           0 :             var start = ctrlrCompose.selection.start;
     583           0 :             var end = ctrlrCompose.selection.end;
     584           0 :             ctrlrCompose.text = ctrlrCompose.text.replaceRange(start, end, "~~" + selected + "~~");
     585           0 :             ctrlrCompose.selection = selection.copyWith(baseOffset: selection.start + 2, extentOffset: selection.start + 2);
     586           0 :             Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose = ctrlrCompose;
     587             :           });
     588             :         });
     589             : 
     590           0 :     var preview = IconButton(
     591           0 :         icon: Icon(Icons.text_format),
     592           0 :         tooltip: AppLocalizations.of(context)!.tooltipPreviewFormatting,
     593           0 :         onPressed: () {
     594           0 :           setState(() {
     595           0 :             showPreview = true;
     596             :           });
     597             :         });
     598             : 
     599           0 :     var vline = Padding(
     600           0 :         padding: EdgeInsets.symmetric(vertical: 1, horizontal: 2), child: Container(height: 16, width: 1, decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.toolbarIconColor)));
     601             : 
     602           0 :     var formattingToolbar = Container(
     603           0 :         decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.toolbarBackgroundColor),
     604           0 :         child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [bold, italic, code, superscript, strikethrough, vline, preview]));
     605             : 
     606           0 :     var textField = Container(
     607           0 :         decoration: BoxDecoration(border: Border(top: BorderSide(color: Provider.of<Settings>(context).theme.backgroundHilightElementColor))),
     608           0 :         child: KeyboardListener(
     609           0 :             focusNode: FocusNode(),
     610           0 :             onKeyEvent: handleKeyPress,
     611           0 :             child: Padding(
     612           0 :               padding: EdgeInsets.all(8),
     613           0 :               child: TextFormField(
     614           0 :                   key: Key('txtCompose'),
     615           0 :                   controller: Provider.of<ContactInfoState>(context).messageDraft.ctrlCompose,
     616           0 :                   focusNode: focusNode,
     617           0 :                   autofocus: !Platform.isAndroid,
     618             :                   textInputAction: TextInputAction.newline,
     619             :                   textCapitalization: TextCapitalization.sentences,
     620             :                   keyboardType: TextInputType.multiline,
     621             :                   enableIMEPersonalizedLearning: false,
     622             :                   minLines: 1,
     623           0 :                   maxLength: max(1, (isGroup ? GroupMessageLengthMax : P2PMessageLengthMax) - numberOfBytesMoreThanChar),
     624             :                   autocorrect: true,
     625           0 :                   buildCounter: (context, {currentLength = 0, isFocused = true, maxLength}) {
     626           0 :                     return Text("$currentLength/$maxLength", style: Provider.of<Settings>(context).scaleFonts(defaultTextStyle));
     627             :                   },
     628             :                   maxLengthEnforcement: MaxLengthEnforcement.enforced,
     629             :                   maxLines: 3,
     630           0 :                   onFieldSubmitted: _sendMessage,
     631           0 :                   style: Provider.of<Settings>(context).scaleFonts(defaultMessageTextStyle).copyWith(
     632             :                         fontWeight: FontWeight.w500,
     633             :                       ),
     634             :                   enabled: true, // always allow editing...
     635             : 
     636           0 :                   onChanged: (String x) {
     637           0 :                     setState(() {
     638             :                       // we need to force a rerender here to update the max length count
     639             :                     });
     640             :                   },
     641           0 :                   decoration: InputDecoration(
     642           0 :                       hintText: AppLocalizations.of(context)!.placeholderEnterMessage,
     643             :                       hintStyle:
     644           0 :                           Provider.of<Settings>(context).scaleFonts(defaultMessageTextStyle).copyWith(color: Provider.of<Settings>(context).theme.sendHintTextColor, fontWeight: FontWeight.bold),
     645             :                       enabledBorder: InputBorder.none,
     646             :                       focusedBorder: InputBorder.none,
     647             :                       enabled: true,
     648           0 :                       suffixIcon: ElevatedButton(
     649           0 :                         key: Key("btnSend"),
     650           0 :                         style: ElevatedButton.styleFrom(padding: EdgeInsets.all(0.0), shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(45.0))),
     651           0 :                         child: Tooltip(
     652             :                             message: cannotSend
     653           0 :                                 ? (isGroup ? AppLocalizations.of(context)!.serverNotSynced : AppLocalizations.of(context)!.peerOfflineMessage)
     654           0 :                                 : (isGroup && Provider.of<ContactInfoState>(context, listen: false).antispamTickets == 0)
     655           0 :                                     ? AppLocalizations.of(context)!.acquiringTicketsFromServer
     656           0 :                                     : AppLocalizations.of(context)!.sendMessage,
     657           0 :                             child: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of<Settings>(context).theme.defaultButtonTextColor)),
     658           0 :                         onPressed: cannotSend || (isGroup && Provider.of<ContactInfoState>(context, listen: false).antispamTickets == 0) ? null : _sendMessage,
     659             :                       ))),
     660             :             )));
     661             : 
     662             :     var textEditChildren;
     663             :     if (showToolbar) {
     664           0 :       textEditChildren = [formattingToolbar, textField];
     665             :     } else {
     666           0 :       textEditChildren = [textField];
     667             :     }
     668             : 
     669             :     var composeBox =
     670           0 :         Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, padding: EdgeInsets.all(2), margin: EdgeInsets.all(2), height: 164, child: Column(children: textEditChildren));
     671             : 
     672             :     var children;
     673           0 :     Widget invite = Container();
     674           0 :     if (Provider.of<ContactInfoState>(context).messageDraft.getInviteHandle() != null) {
     675           0 :       invite = FutureBuilder(
     676           0 :           future: Future.value(Provider.of<ContactInfoState>(context).messageDraft.getInviteHandle()),
     677           0 :           builder: (context, snapshot) {
     678           0 :             if (snapshot.hasData) {
     679           0 :               var contactInvite = snapshot.data! as int;
     680           0 :               var contact = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(contactInvite);
     681           0 :               return Container(
     682           0 :                   margin: EdgeInsets.all(5),
     683           0 :                   padding: EdgeInsets.all(5),
     684           0 :                   color: Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
     685           0 :                   child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
     686           0 :                     Stack(children: [
     687           0 :                       Container(
     688           0 :                           margin: EdgeInsets.all(5),
     689           0 :                           padding: EdgeInsets.all(5),
     690             :                           clipBehavior: Clip.antiAlias,
     691           0 :                           decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.messageFromMeBackgroundColor),
     692             :                           height: 75,
     693           0 :                           child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
     694           0 :                             Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Icon(CwtchIcons.send_invite, size: 32)),
     695           0 :                             Flexible(
     696           0 :                                 child: DefaultTextStyle(
     697             :                               textWidthBasis: TextWidthBasis.parent,
     698           0 :                               child: senderInviteChrome("", contact!.nickname),
     699           0 :                               style: Provider.of<Settings>(context).scaleFonts(defaultTextStyle),
     700             :                               overflow: TextOverflow.fade,
     701             :                             ))
     702             :                           ])),
     703           0 :                       Align(
     704             :                           alignment: Alignment.topRight,
     705           0 :                           child: IconButton(
     706           0 :                             icon: Icon(Icons.highlight_remove),
     707           0 :                             splashRadius: Material.defaultSplashRadius / 2,
     708           0 :                             color: Provider.of<Settings>(context).theme.messageFromMeTextColor,
     709           0 :                             tooltip: AppLocalizations.of(context)!.tooltipRemoveThisQuotedMessage,
     710           0 :                             onPressed: () {
     711           0 :                               Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearInvite();
     712           0 :                               setState(() {});
     713             :                             },
     714             :                           )),
     715             :                     ]),
     716             :                   ]));
     717             :             }
     718           0 :             return Container();
     719             :           });
     720             :     }
     721             : 
     722           0 :     if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<ContactInfoState>(context).messageDraft.getQuotedMessage() != null) {
     723           0 :       var quoted = FutureBuilder(
     724           0 :         future: messageHandler(context, Provider.of<AppState>(context).selectedProfile!, Provider.of<AppState>(context).selectedConversation!,
     725           0 :             ById(Provider.of<ContactInfoState>(context).messageDraft.getQuotedMessage()!.index)),
     726           0 :         builder: (context, snapshot) {
     727           0 :           if (snapshot.hasData) {
     728           0 :             var message = snapshot.data! as Message;
     729           0 :             var qTextColor = message.getMetadata().senderHandle != Provider.of<AppState>(context).selectedProfile
     730           0 :                 ? Provider.of<Settings>(context).theme.messageFromOtherTextColor
     731           0 :                 : Provider.of<Settings>(context).theme.messageFromMeTextColor;
     732           0 :             return Container(
     733           0 :                 margin: EdgeInsets.all(5),
     734           0 :                 padding: EdgeInsets.all(5),
     735           0 :                 color: message.getMetadata().senderHandle != Provider.of<AppState>(context).selectedProfile
     736           0 :                     ? Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor
     737           0 :                     : Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
     738           0 :                 child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
     739           0 :                   Stack(children: [
     740           0 :                     Container(
     741           0 :                         margin: EdgeInsets.all(5),
     742           0 :                         padding: EdgeInsets.all(5),
     743             :                         clipBehavior: Clip.antiAlias,
     744           0 :                         decoration: BoxDecoration(
     745           0 :                           color: message.getMetadata().senderHandle != Provider.of<AppState>(context).selectedProfile
     746           0 :                               ? Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor
     747           0 :                               : Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
     748             :                         ),
     749             :                         height: 75,
     750           0 :                         child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
     751           0 :                           Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Icon(Icons.reply, size: 32, color: qTextColor)),
     752           0 :                           Flexible(
     753           0 :                               child: DefaultTextStyle(
     754             :                             textWidthBasis: TextWidthBasis.parent,
     755           0 :                             child: message.getPreviewWidget(context),
     756           0 :                             style: TextStyle(color: qTextColor),
     757             :                             overflow: TextOverflow.fade,
     758             :                           ))
     759             :                         ])),
     760           0 :                     Align(
     761             :                         alignment: Alignment.topRight,
     762           0 :                         child: IconButton(
     763           0 :                           icon: Icon(Icons.highlight_remove),
     764           0 :                           splashRadius: Material.defaultSplashRadius / 2,
     765           0 :                           color: message.getMetadata().senderHandle != Provider.of<AppState>(context).selectedProfile
     766           0 :                               ? Provider.of<Settings>(context).theme.messageFromOtherTextColor
     767           0 :                               : Provider.of<Settings>(context).theme.messageFromMeTextColor,
     768           0 :                           tooltip: AppLocalizations.of(context)!.tooltipRemoveThisQuotedMessage,
     769           0 :                           onPressed: () {
     770           0 :                             Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearQuotedReference();
     771           0 :                             setState(() {});
     772             :                           },
     773             :                         )),
     774             :                   ]),
     775             :                 ]));
     776             :           } else {
     777           0 :             return MessageLoadingBubble();
     778             :           }
     779             :         },
     780             :       );
     781             : 
     782           0 :       children = [invite, quoted, composeBox];
     783             :     } else {
     784           0 :       children = [invite, composeBox];
     785             :     }
     786             : 
     787           0 :     return Container(
     788           0 :         color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: children));
     789             :   }
     790             : 
     791             :   // Send the message if enter is pressed without the shift key...
     792           0 :   void handleKeyPress(KeyEvent event) {
     793           0 :     var key = event.logicalKey;
     794           0 :     if ((event.logicalKey == LogicalKeyboardKey.enter && !HardwareKeyboard.instance.isShiftPressed) || event.logicalKey == LogicalKeyboardKey.numpadEnter && HardwareKeyboard.instance.isShiftPressed) {
     795             :       // Don't send when inserting a new line that is not at the end of the message
     796           0 :       if (Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose.selection.baseOffset !=
     797           0 :           Provider.of<ContactInfoState>(context, listen: false).messageDraft.ctrlCompose.text.length) {
     798             :         return;
     799             :       }
     800           0 :       _sendMessage();
     801           0 :       Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearDraft();
     802             :     }
     803             :   }
     804             : 
     805             :   // explicitly passing BuildContext ctx here is important, change at risk to own health
     806             :   // otherwise some Providers will become inaccessible to subwidgets...?
     807             :   // https://stackoverflow.com/a/63818697
     808           0 :   void _modalSendInvitation(BuildContext ctx) {
     809           0 :     showModalBottomSheet<void>(
     810             :         context: ctx,
     811           0 :         builder: (BuildContext bcontext) {
     812           0 :           return Container(
     813             :               height: 200, // bespoke value courtesy of the [TextField] docs
     814           0 :               child: Center(
     815           0 :                 child: Padding(
     816           0 :                     padding: EdgeInsets.all(10.0),
     817           0 :                     child: Column(
     818             :                       mainAxisAlignment: MainAxisAlignment.center,
     819             :                       mainAxisSize: MainAxisSize.min,
     820             :                       crossAxisAlignment: CrossAxisAlignment.stretch,
     821           0 :                       children: <Widget>[
     822           0 :                         Text(AppLocalizations.of(bcontext)!.invitationLabel),
     823           0 :                         SizedBox(
     824             :                           height: 20,
     825             :                         ),
     826           0 :                         ChangeNotifierProvider.value(
     827           0 :                             value: Provider.of<ProfileInfoState>(ctx, listen: false),
     828           0 :                             child: DropdownContacts(filter: (contact) {
     829           0 :                               return contact.onion != Provider.of<ContactInfoState>(ctx).onion;
     830           0 :                             }, onChanged: (newVal) {
     831           0 :                               setState(() {
     832           0 :                                 this.selectedContact = Provider.of<ProfileInfoState>(ctx, listen: false).contactList.findContact(newVal)!.identifier;
     833             :                               });
     834             :                             })),
     835           0 :                         SizedBox(
     836             :                           height: 20,
     837             :                         ),
     838           0 :                         ElevatedButton(
     839           0 :                           child: Text(AppLocalizations.of(bcontext)!.inviteBtn, semanticsLabel: AppLocalizations.of(bcontext)!.inviteBtn),
     840           0 :                           onPressed: () {
     841           0 :                             if (this.selectedContact != -1) {
     842           0 :                               Provider.of<ContactInfoState>(context, listen: false).messageDraft.attachInvite(this.selectedContact);
     843             :                             }
     844           0 :                             Navigator.pop(bcontext);
     845           0 :                             setState(() {});
     846             :                           },
     847             :                         ),
     848             :                       ],
     849             :                     )),
     850             :               ));
     851             :         });
     852             :   }
     853             : 
     854           0 :   void _confirmFileSend(BuildContext ctx, String path) async {
     855           0 :     showModalBottomSheet<void>(
     856             :         context: ctx,
     857           0 :         builder: (BuildContext bcontext) {
     858             :           var showPreview = false;
     859           0 :           if (Provider.of<Settings>(context, listen: false).shouldPreview(path)) {
     860             :             showPreview = true;
     861           0 :             if (imagePreview == null) {
     862           0 :               imagePreview = new File(path);
     863             :             }
     864             :           }
     865           0 :           return Container(
     866             :               height: 300, // bespoke value courtesy of the [TextField] docs
     867           0 :               child: Center(
     868           0 :                 child: Padding(
     869           0 :                     padding: EdgeInsets.all(10.0),
     870           0 :                     child: Column(
     871             :                       mainAxisAlignment: MainAxisAlignment.center,
     872             :                       mainAxisSize: MainAxisSize.min,
     873           0 :                       children: <Widget>[
     874           0 :                         Text(AppLocalizations.of(context)!.msgConfirmSend + " $path?"),
     875           0 :                         SizedBox(
     876             :                           height: 20,
     877             :                         ),
     878           0 :                         Visibility(
     879             :                             visible: showPreview,
     880             :                             child: showPreview
     881           0 :                                 ? Image.file(
     882           0 :                                     imagePreview!,
     883             :                                     cacheHeight: 150, // limit the amount of space the image can decode too, we keep this high-ish to allow quality previews...
     884             :                                     filterQuality: FilterQuality.medium,
     885             :                                     fit: BoxFit.fill,
     886             :                                     alignment: Alignment.center,
     887             :                                     height: 150,
     888             :                                     isAntiAlias: false,
     889           0 :                                     errorBuilder: (context, error, stackTrace) {
     890           0 :                                       return MalformedBubble();
     891             :                                     },
     892             :                                   )
     893           0 :                                 : Container()),
     894           0 :                         Visibility(
     895             :                             visible: showPreview,
     896           0 :                             child: SizedBox(
     897             :                               height: 10,
     898             :                             )),
     899           0 :                         Row(mainAxisAlignment: MainAxisAlignment.center, children: [
     900           0 :                           OutlinedButton(
     901           0 :                             child: Text(AppLocalizations.of(context)!.cancel, semanticsLabel: AppLocalizations.of(context)!.cancel),
     902           0 :                             onPressed: () {
     903           0 :                               Navigator.pop(bcontext);
     904             :                             },
     905             :                           ),
     906           0 :                           SizedBox(
     907             :                             width: 20,
     908             :                           ),
     909           0 :                           FilledButton(
     910           0 :                             child: Text(AppLocalizations.of(context)!.btnSendFile, semanticsLabel: AppLocalizations.of(context)!.btnSendFile),
     911           0 :                             onPressed: () {
     912           0 :                               _sendFile(path);
     913           0 :                               Navigator.pop(bcontext);
     914             :                             },
     915             :                           ),
     916             :                         ]),
     917             :                       ],
     918             :                     )),
     919             :               ));
     920             :         });
     921             :   }
     922             : }
     923             : 
     924           0 : void _summarizeConversation(BuildContext context, ProfileInfoState profile, Settings settings) async {
     925           0 :   showModalBottomSheet<void>(
     926           0 :       builder: (
     927             :         BuildContext bcontext,
     928             :       ) {
     929           0 :         return StatefulBuilder(builder: (BuildContext scontext, StateSetter setState /*You can rename this!*/) {
     930           0 :           if (scontext.mounted) {
     931           0 :             new Timer.periodic(Duration(seconds: 1), (Timer t) {
     932           0 :               if (scontext.mounted) {
     933           0 :                 setState(() {});
     934             :               }
     935             :             });
     936             :           }
     937             : 
     938           0 :           var bubble = StaticMessageBubble(
     939             :               profile,
     940             :               settings,
     941           0 :               MessageMetadata(profile.onion, Provider.of<ContactInfoState>(context).identifier, 1, DateTime.now(), "blodeuwedd", null, null, null, true, false, false, ""),
     942           0 :               Row(children: [
     943           0 :                 Provider.of<ContactInfoState>(context).summary == ""
     944           0 :                     ? Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
     945           0 :                         CircularProgressIndicator(color: settings.theme.defaultButtonActiveColor),
     946           0 :                         Padding(padding: EdgeInsets.all(5.0), child: Text(AppLocalizations.of(context)!.blodeuweddProcessing))
     947             :                       ])
     948           0 :                     : Flexible(child: Text(Provider.of<ContactInfoState>(context).summary))
     949             :               ]));
     950             : 
     951           0 :           var image = Padding(
     952           0 :               padding: EdgeInsets.all(4.0),
     953           0 :               child: ProfileImage(
     954             :                 imagePath: "assets/blodeuwedd.png",
     955             :                 diameter: 48.0,
     956           0 :                 border: settings.theme.portraitOnlineBorderColor,
     957             :                 badgeTextColor: Colors.red,
     958             :                 badgeColor: Colors.red,
     959             :               ));
     960             : 
     961           0 :           return Container(
     962             :               height: 300, // bespoke value courtesy of the [TextField] docs
     963           0 :               child: Container(
     964             :                   alignment: Alignment.center,
     965           0 :                   child: Padding(
     966           0 :                       padding: EdgeInsets.all(10.0),
     967           0 :                       child: Padding(
     968           0 :                           padding: EdgeInsets.all(10.0),
     969           0 :                           child: Row(
     970             :                             mainAxisSize: MainAxisSize.min,
     971           0 :                             children: [image, Flexible(child: bubble)],
     972             :                           )))));
     973             :         });
     974             :       },
     975             :       context: context);
     976             : }

Generated by: LCOV version 1.14