From 224642e00db4e99ea241dd2e23ba280d53a921db Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Mon, 25 Sep 2023 12:05:28 -0700 Subject: [PATCH] Partially Redact Contact Onions where Nicks are unavailable. Upgrade Cwtch --- LIBCWTCH-GO.version | 2 +- lib/models/contact.dart | 4 +++- lib/models/redaction.dart | 10 ++++++++++ lib/views/contactsview.dart | 6 +++++- lib/widgets/filebubble.dart | 3 ++- lib/widgets/invitationbubble.dart | 3 ++- lib/widgets/messagebubble.dart | 3 ++- lib/widgets/messagerow.dart | 3 ++- lib/widgets/quotedmessage.dart | 3 ++- lib/widgets/staticmessagebubble.dart | 3 ++- 10 files changed, 31 insertions(+), 9 deletions(-) diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index bb47a353..dd279b82 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2023-09-24-09-56-v0.0.8-1-gb80db89 \ No newline at end of file +2023-09-25-18-37-v0.0.9 \ No newline at end of file diff --git a/lib/models/contact.dart b/lib/models/contact.dart index ae9dc713..3f454af9 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -3,6 +3,7 @@ import 'dart:ffi'; import 'package:cwtch/main.dart'; import 'package:cwtch/models/message_draft.dart'; import 'package:cwtch/models/profile.dart'; +import 'package:cwtch/models/redaction.dart'; import 'package:cwtch/themes/opaque.dart'; import 'package:cwtch/views/contactsview.dart'; import 'package:cwtch/widgets/messagerow.dart'; @@ -440,7 +441,8 @@ class ContactInfoState extends ChangeNotifier { } String augmentedNickname(BuildContext context) { - return this.nickname + (this.availabilityStatus == ProfileStatusMenu.available ? "" : " (" + this.statusString(context) + ")"); + var nick = redactedNick(context, this.onion, this.nickname); + return nick + (this.availabilityStatus == ProfileStatusMenu.available ? "" : " (" + this.statusString(context) + ")"); } // Never use this for message lookup - can be a non-indexed value diff --git a/lib/models/redaction.dart b/lib/models/redaction.dart index ae5d71f5..a9a9021b 100644 --- a/lib/models/redaction.dart +++ b/lib/models/redaction.dart @@ -6,6 +6,16 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../settings.dart'; import 'package:intl/intl.dart'; +String redactedNick(BuildContext context, String handle, String nick) { + var settings = Provider.of(context, listen: false); + if (settings.streamerMode) { + if (handle == nick) { + return handle.substring(0, 7) + "..."; + } + } + return nick; +} + String prettyDateString(BuildContext context, DateTime date) { var settings = Provider.of(context, listen: false); if (settings.streamerMode) { diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index d950ef69..fd2e8d4a 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -20,6 +20,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../config.dart'; import '../main.dart'; import '../models/message.dart'; +import '../models/redaction.dart'; import '../settings.dart'; import '../themes/opaque.dart'; import 'addcontactview.dart'; @@ -337,7 +338,10 @@ class _ContactsViewState extends State { width: 10, ), Expanded( - child: Text("%1 » %2".replaceAll("%1", Provider.of(context).nickname).replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts), + child: Text( + "%1 » %2" + .replaceAll("%1", redactedNick(context, Provider.of(context).onion, Provider.of(context).nickname)) + .replaceAll("%2", AppLocalizations.of(context)!.titleManageContacts), overflow: TextOverflow.ellipsis, style: TextStyle( color: Provider.of(context).current().mainTextColor, diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index ff3a2fe9..99905abe 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -18,6 +18,7 @@ import '../main.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import '../models/redaction.dart'; import '../settings.dart'; import 'messagebubbledecorations.dart'; @@ -126,7 +127,7 @@ class FileBubbleState extends State { if (!fromMe) { ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); senderIsContact = true; } else { senderDisplayStr = Provider.of(context).senderHandle; diff --git a/lib/widgets/invitationbubble.dart b/lib/widgets/invitationbubble.dart index de10f11d..74e2af51 100644 --- a/lib/widgets/invitationbubble.dart +++ b/lib/widgets/invitationbubble.dart @@ -13,6 +13,7 @@ import '../main.dart'; import 'package:intl/intl.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import '../models/redaction.dart'; import '../settings.dart'; import 'messageBubbleWidgetHelpers.dart'; import 'messagebubbledecorations.dart'; @@ -50,7 +51,7 @@ class InvitationBubbleState extends State { if (!fromMe) { ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); } else { senderDisplayStr = Provider.of(context).senderHandle; } diff --git a/lib/widgets/messagebubble.dart b/lib/widgets/messagebubble.dart index 77515db5..f956025f 100644 --- a/lib/widgets/messagebubble.dart +++ b/lib/widgets/messagebubble.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:cwtch/controllers/open_link_modal.dart'; import 'package:cwtch/models/contact.dart'; import 'package:cwtch/models/message.dart'; +import 'package:cwtch/models/redaction.dart'; import 'package:cwtch/themes/opaque.dart'; import 'package:cwtch/third_party/linkify/flutter_linkify.dart'; import 'package:cwtch/models/profile.dart'; @@ -39,7 +40,7 @@ class MessageBubbleState extends State { if (!fromMe) { ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); } else { senderDisplayStr = Provider.of(context).senderHandle; } diff --git a/lib/widgets/messagerow.dart b/lib/widgets/messagerow.dart index d85dab25..8ec0023a 100644 --- a/lib/widgets/messagerow.dart +++ b/lib/widgets/messagerow.dart @@ -20,6 +20,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart'; import '../main.dart'; import '../models/messagecache.dart'; +import '../models/redaction.dart'; import '../settings.dart'; class MessageRow extends StatefulWidget { @@ -73,7 +74,7 @@ class MessageRowState extends State with SingleTickerProviderStateMi if (!fromMe) { ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); } else { senderDisplayStr = Provider.of(context).senderHandle; } diff --git a/lib/widgets/quotedmessage.dart b/lib/widgets/quotedmessage.dart index dadd0f1a..d50792fb 100644 --- a/lib/widgets/quotedmessage.dart +++ b/lib/widgets/quotedmessage.dart @@ -9,6 +9,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import '../models/redaction.dart'; import '../settings.dart'; import 'messageBubbleWidgetHelpers.dart'; import 'messagebubbledecorations.dart'; @@ -38,7 +39,7 @@ class QuotedMessageBubbleState extends State { if (!fromMe) { ContactInfoState? contact = Provider.of(context).contactList.findContact(Provider.of(context).senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); } else { senderDisplayStr = Provider.of(context).senderHandle; } diff --git a/lib/widgets/staticmessagebubble.dart b/lib/widgets/staticmessagebubble.dart index ad19bd56..f146c98c 100644 --- a/lib/widgets/staticmessagebubble.dart +++ b/lib/widgets/staticmessagebubble.dart @@ -5,6 +5,7 @@ import 'package:cwtch/widgets/malformedbubble.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../models/redaction.dart'; import '../settings.dart'; import 'messageBubbleWidgetHelpers.dart'; import 'messagebubbledecorations.dart'; @@ -33,7 +34,7 @@ class StaticMessageBubbleState extends State { if (!fromMe) { ContactInfoState? contact = widget.profile.contactList.findContact(widget.metadata.senderHandle); if (contact != null) { - senderDisplayStr = contact.nickname; + senderDisplayStr = redactedNick(context, contact.onion, contact.nickname); } else { senderDisplayStr = widget.metadata.senderHandle; }