From d126cc6ebb314f597a3783867641538b594522c4 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 14 Jul 2021 13:30:50 -0700 Subject: [PATCH] Autohide messages from blocked contacts --- lib/l10n/intl_de.arb | 4 +- lib/l10n/intl_en.arb | 4 +- lib/l10n/intl_es.arb | 4 +- lib/l10n/intl_fr.arb | 6 ++- lib/l10n/intl_it.arb | 4 +- lib/l10n/intl_pl.arb | 4 +- lib/l10n/intl_pt.arb | 4 +- lib/models/messages/invitemessage.dart | 7 ++-- lib/widgets/invitationbubble.dart | 5 ++- lib/widgets/messagerow.dart | 57 ++++++++++++++++++++++++-- 10 files changed, 83 insertions(+), 16 deletions(-) diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index 11a86cca..86c7175c 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -1,6 +1,8 @@ { "@@locale": "de", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index a412ad79..4320bee4 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -1,6 +1,8 @@ { "@@locale": "en", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/l10n/intl_es.arb b/lib/l10n/intl_es.arb index 42108a5a..e6279499 100644 --- a/lib/l10n/intl_es.arb +++ b/lib/l10n/intl_es.arb @@ -1,6 +1,8 @@ { "@@locale": "es", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 9e55c6dc..7228ae40 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -1,7 +1,9 @@ { "@@locale": "fr", - "@@last_modified": "2021-07-14T21:46:10+02:00", - "placeholderEnterMessage": "Type a message...", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", + "placeholderEnterMessage": "saisissez un message", "plainProfileDescription": "Nous vous recommandons de protéger vos profils Cwtch par un mot de passe. Si vous ne définissez pas de mot de passe sur ce profil, toute personne ayant accès à cet appareil peut être en mesure d'accéder aux informations relatives à ce profil, y compris les contacts, les messages et les clés de chiffrement sensibles.", "encryptedProfileDescription": "Le chiffrement d'un profil à l'aide d'un mot de passe le protège des autres personnes susceptibles d'utiliser également cet appareil. Les profils chiffrés ne peuvent pas être déchiffrés , affichés ou accessibles tant que le mot de passe correct n'a pas été saisi pour les déverrouiller.", "addContactConfirm": "Ajouter le contact %1", diff --git a/lib/l10n/intl_it.arb b/lib/l10n/intl_it.arb index 65f3a737..3628888f 100644 --- a/lib/l10n/intl_it.arb +++ b/lib/l10n/intl_it.arb @@ -1,6 +1,8 @@ { "@@locale": "it", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/l10n/intl_pl.arb b/lib/l10n/intl_pl.arb index 501aa80b..3b7313f9 100644 --- a/lib/l10n/intl_pl.arb +++ b/lib/l10n/intl_pl.arb @@ -1,6 +1,8 @@ { "@@locale": "pl", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/l10n/intl_pt.arb b/lib/l10n/intl_pt.arb index 4e852a56..ee4f37f3 100644 --- a/lib/l10n/intl_pt.arb +++ b/lib/l10n/intl_pt.arb @@ -1,6 +1,8 @@ { "@@locale": "pt", - "@@last_modified": "2021-07-14T21:46:10+02:00", + "@@last_modified": "2021-07-14T22:29:25+02:00", + "showMessageButton": "Show Message", + "blockedMessageMessage": "This message is from a profile you have blocked.", "placeholderEnterMessage": "Type a message...", "plainProfileDescription": "We recommend that you protect your Cwtch profiles with a password. If you do not set a password on this profile then anyone who has access to this device may be able to access information about this profile, including contacts, messages and sensitive cryptographic keys.", "encryptedProfileDescription": "Encrypting a profile with a password protects it from other people who may also use this device. Encrypted profiles cannot be decrypted, displayed or accessed until the correct password is entered to unlock them.", diff --git a/lib/models/messages/invitemessage.dart b/lib/models/messages/invitemessage.dart index 6e31abb8..7313207f 100644 --- a/lib/models/messages/invitemessage.dart +++ b/lib/models/messages/invitemessage.dart @@ -25,6 +25,7 @@ class InviteMessage extends Message { String inviteTarget; String inviteNick; + String invite = this.content; if (this.content.length == TorV3ContactHandleLength) { inviteTarget = this.content; @@ -40,7 +41,7 @@ class InviteMessage extends Message { return MessageRow(MalformedBubble()); } } - return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick), key: Provider.of(bcontext).getMessageKey(idx)); + return MessageRow(InvitationBubble(overlay, inviteTarget, inviteNick, invite), key: Provider.of(bcontext).getMessageKey(idx)); }); } @@ -51,7 +52,7 @@ class InviteMessage extends Message { builder: (bcontext, child) { String inviteTarget; String inviteNick; - + String invite = this.content; if (this.content.length == TorV3ContactHandleLength) { inviteTarget = this.content; var targetContact = Provider.of(context).contactList.getContact(inviteTarget); @@ -66,7 +67,7 @@ class InviteMessage extends Message { return MalformedBubble(); } } - return InvitationBubble(overlay, inviteTarget, inviteNick); + return InvitationBubble(overlay, inviteTarget, inviteNick, invite); }); } diff --git a/lib/widgets/invitationbubble.dart b/lib/widgets/invitationbubble.dart index 0ff47c02..4770283d 100644 --- a/lib/widgets/invitationbubble.dart +++ b/lib/widgets/invitationbubble.dart @@ -19,8 +19,9 @@ class InvitationBubble extends StatefulWidget { final int overlay; final String inviteTarget; final String inviteNick; + final String invite; - InvitationBubble(this.overlay, this.inviteTarget, this.inviteNick); + InvitationBubble(this.overlay, this.inviteTarget, this.inviteNick, this.invite); @override InvitationBubbleState createState() => InvitationBubbleState(); @@ -136,7 +137,7 @@ class InvitationBubbleState extends State { void _btnAccept() { setState(() { var profileOnion = Provider.of(context, listen: false).onion; - Provider.of(context, listen: false).cwtch.ImportBundle(profileOnion, widget.inviteTarget); + Provider.of(context, listen: false).cwtch.ImportBundle(profileOnion, widget.invite); isAccepted = true; }); } diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index 2a822240..85c7a78d 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:cwtch/cwtch_icons_icons.dart'; import 'package:cwtch/models/message.dart'; import 'package:cwtch/views/contactsview.dart'; import 'package:flutter/material.dart'; @@ -21,11 +22,13 @@ class MessageRow extends StatefulWidget { class MessageRowState extends State { bool showMenu = false; - + bool showBlockedMessage = false; @override Widget build(BuildContext context) { var fromMe = Provider.of(context).senderHandle == Provider.of(context).onion; var isContact = Provider.of(context).contactList.getContact(Provider.of(context).senderHandle) != null; + var isBlocked = isContact ? Provider.of(context).contactList.getContact(Provider.of(context).senderHandle)!.isBlocked : false; + var actualMessage = Flexible(flex: 3, fit: FlexFit.loose, child: widget.child); var senderDisplayStr = ""; if (!fromMe) { @@ -53,7 +56,55 @@ class MessageRowState extends State { widgetRow = [ wdgSpacer, wdgIcons, - Flexible(flex: 3, fit: FlexFit.loose, child: widget.child), + actualMessage, + ]; + } else if (isBlocked && !showBlockedMessage) { + Color blockedMessageBackground = Provider.of(context).theme.messageFromOtherBackgroundColor(); + Widget wdgPortrait = Padding(padding: EdgeInsets.all(4.0), child: Icon(CwtchIcons.account_blocked)); + widgetRow = [ + wdgPortrait, + Container( + padding: EdgeInsets.all(2.0), + decoration: BoxDecoration( + color: blockedMessageBackground, + border: Border.all(color: blockedMessageBackground, width: 2), + borderRadius: BorderRadius.only( + topLeft: Radius.circular(15.0), + topRight: Radius.circular(15.0), + bottomLeft: Radius.circular(15.0), + bottomRight: Radius.circular(15.0), + )), + child: Padding( + padding: EdgeInsets.all(9.0), + child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [ + SelectableText( + AppLocalizations.of(context)!.blockedMessageMessage, + //key: Key(myKey), + style: TextStyle( + color: Provider.of(context).theme.messageFromOtherTextColor(), + ), + textAlign: TextAlign.center, + textWidthBasis: TextWidthBasis.longestLine, + ), + Padding( + padding: EdgeInsets.all(1.0), + child: TextButton( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(blockedMessageBackground), + overlayColor: MaterialStateProperty.all(blockedMessageBackground), + ), + child: Text( + AppLocalizations.of(context)!.showMessageButton + '\u202F', + style: TextStyle(decoration: TextDecoration.underline), + ), + onPressed: () { + setState(() { + this.showBlockedMessage = true; + }); + })), + ]))), + wdgIcons, + wdgSpacer, ]; } else { var contact = Provider.of(context); @@ -72,7 +123,7 @@ class MessageRowState extends State { widgetRow = [ wdgPortrait, - Flexible(flex: 3, fit: FlexFit.loose, child: widget.child), + actualMessage, wdgIcons, wdgSpacer, ];