From 70c532535165aebe404030a0bbacd3821c07afdc Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 13 Jul 2021 14:46:47 -0700 Subject: [PATCH] Fix exceptions when quoting with quotes + fix size of message row without toolbar --- lib/cwtch/cwtchNotifier.dart | 8 +++++++- lib/model.dart | 9 ++------- lib/models/message.dart | 2 -- lib/models/messages/quotedmessage.dart | 11 +++++++++++ lib/views/messageview.dart | 5 +++-- lib/widgets/contactrow.dart | 2 -- lib/widgets/messagerow.dart | 6 ++---- lib/widgets/profileimage.dart | 13 +++++-------- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index e1a96c50..ebd3979c 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -68,7 +68,13 @@ class CwtchNotifier { } if (profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(data["GroupID"]) == null) { profileCN.getProfile(data["ProfileOnion"])?.contactList.add(ContactInfoState(data["ProfileOnion"], data["GroupID"], - authorization: ContactAuthorization.approved, imagePath: data["PicturePath"], nickname: data["GroupName"], status: status, server: data["GroupServer"], isGroup: true, lastMessageTime: DateTime.now())); + authorization: ContactAuthorization.approved, + imagePath: data["PicturePath"], + nickname: data["GroupName"], + status: status, + server: data["GroupServer"], + isGroup: true, + lastMessageTime: DateTime.now())); profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(data["GroupID"], DateTime.now()); } break; diff --git a/lib/model.dart b/lib/model.dart index 086b2916..46a8b508 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -329,14 +329,10 @@ class ProfileInfoState extends ChangeNotifier { } } -enum ContactAuthorization { - unknown, - approved, - blocked -} +enum ContactAuthorization { unknown, approved, blocked } ContactAuthorization stringToContactAuthorization(String authStr) { - switch(authStr) { + switch (authStr) { case "approved": return ContactAuthorization.approved; case "blocked": @@ -346,7 +342,6 @@ ContactAuthorization stringToContactAuthorization(String authStr) { } } - class ContactInfoState extends ChangeNotifier { final String profileOnion; final String onion; diff --git a/lib/models/message.dart b/lib/models/message.dart index 1d5bafd3..b93ce649 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -23,8 +23,6 @@ const TorV3ContactHandleLength = 56; // Defines the length of a Cwtch v2 Group. const GroupConversationHandleLength = 32; - - abstract class Message { MessageMetadata getMetadata(); Widget getWidget(BuildContext context); diff --git a/lib/models/messages/quotedmessage.dart b/lib/models/messages/quotedmessage.dart index 4d71a2d9..3bb85961 100644 --- a/lib/models/messages/quotedmessage.dart +++ b/lib/models/messages/quotedmessage.dart @@ -10,6 +10,17 @@ import 'package:provider/provider.dart'; import '../../main.dart'; import '../../model.dart'; +class QuotedMessageStructure { + final String quotedHash; + final String body; + QuotedMessageStructure(this.quotedHash, this.body); + + Map toJson() => { + 'quotedHash': quotedHash, + 'body': body, + }; +} + class LocallyIndexedMessage { final dynamic message; final int index; diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 13cb7b18..b4f764cc 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:crypto/crypto.dart'; import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:cwtch/models/message.dart'; +import 'package:cwtch/models/messages/quotedmessage.dart'; import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:cwtch/widgets/messageloadingbubble.dart'; import 'package:cwtch/widgets/profileimage.dart'; @@ -127,7 +128,7 @@ class _MessageViewState extends State { var bytes1 = utf8.encode(messageWrapper["PeerID"] + messageWrapper['Message']); var digest1 = sha256.convert(bytes1); var contentHash = base64Encode(digest1.bytes); - var quotedMessage = "{\"quotedHash\":\"" + contentHash + "\",\"body\":\"" + ctrlrCompose.value.text + "\"}"; + var quotedMessage = jsonEncode(QuotedMessageStructure(contentHash, ctrlrCompose.value.text)); ChatMessage cm = new ChatMessage(o: QuotedMessageOverlay, d: quotedMessage); Provider.of(context, listen: false) .cwtch @@ -204,7 +205,7 @@ class _MessageViewState extends State { suffixIcon: IconButton( icon: Icon(CwtchIcons.send_24px, size: 24, color: Provider.of(context).theme.mainTextColor()), tooltip: AppLocalizations.of(context)!.sendMessage, - onPressed: isOffline ? null :_sendMessage, + onPressed: isOffline ? null : _sendMessage, ), )))), ), diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index f8c6f476..fced6b79 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -99,8 +99,6 @@ class _ContactRowState extends State { )); } - - void _btnApprove() { Provider.of(context, listen: false) .cwtch diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index a1d90482..a511f433 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -39,6 +39,7 @@ class MessageRowState extends State { Widget wdgIcons = Visibility( visible: this.showMenu, + maintainSize: true, child: IconButton( tooltip: AppLocalizations.of(context)!.tooltipReplyToThisMessage, onPressed: () { @@ -127,10 +128,7 @@ class MessageRowState extends State { style: ButtonStyle(padding: MaterialStateProperty.all(EdgeInsets.all(20))), child: Text(AppLocalizations.of(context)!.addContact), onPressed: () { - Provider - .of(context, listen: false) - .cwtch - .ImportBundle(profileOnion, senderOnion); + Provider.of(context, listen: false).cwtch.ImportBundle(profileOnion, senderOnion); final snackBar = SnackBar( content: Text(AppLocalizations.of(context)!.successfullAddedContact), duration: Duration(seconds: 2), diff --git a/lib/widgets/profileimage.dart b/lib/widgets/profileimage.dart index 68e9ae11..1516f3e0 100644 --- a/lib/widgets/profileimage.dart +++ b/lib/widgets/profileimage.dart @@ -5,7 +5,8 @@ import 'package:provider/provider.dart'; import '../settings.dart'; class ProfileImage extends StatefulWidget { - ProfileImage({required this.imagePath, required this.diameter, required this.border, this.badgeCount = 0, required this.badgeColor, required this.badgeTextColor, this.maskOut = false, this.tooltip = ""}); + ProfileImage( + {required this.imagePath, required this.diameter, required this.border, this.badgeCount = 0, required this.badgeColor, required this.badgeTextColor, this.maskOut = false, this.tooltip = ""}); final double diameter; final String imagePath; final Color border; @@ -28,8 +29,8 @@ class _ProfileImageState extends State { // We need some theme specific blending here...we might want to consider making this a theme level attribute colorBlendMode: !widget.maskOut ? Provider.of(context).theme.identifier() == "dark" - ? BlendMode.softLight - : BlendMode.darken + ? BlendMode.softLight + : BlendMode.darken : BlendMode.srcOut, color: Provider.of(context).theme.backgroundHilightElementColor(), isAntiAlias: true, @@ -47,11 +48,7 @@ class _ProfileImageState extends State { color: widget.border, child: Padding( padding: const EdgeInsets.all(2.0), //border size - child: ClipOval( - clipBehavior: Clip.antiAlias, - child: widget.tooltip == "" ? image : Tooltip( - message: widget.tooltip, - child: image))))), + child: ClipOval(clipBehavior: Clip.antiAlias, child: widget.tooltip == "" ? image : Tooltip(message: widget.tooltip, child: image))))), Visibility( visible: widget.badgeCount > 0, child: Positioned(