From 22390f31ff18a1c65f1ee92f2352821f0dc415dc Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sun, 4 Aug 2024 07:27:25 -0500 Subject: [PATCH] log fix for ios and ability to delete orphaned chats --- assets/i18n/en.json | 1 + lib/chat_list/views/chat_list_widget.dart | 8 ++--- .../chat_single_contact_item_widget.dart | 33 +++++++++++-------- lib/tools/loggy.dart | 10 +++--- lib/tools/state_logger.dart | 6 ++-- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index cb95eaf..552da6f 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -233,6 +233,7 @@ "password_does_not_match": "Password does not match" }, "chat_list": { + "deleted_contact": "Deleted Contact", "search": "Search chats", "start_a_conversation": "Start A Conversation", "chats": "Chats", diff --git a/lib/chat_list/views/chat_list_widget.dart b/lib/chat_list/views/chat_list_widget.dart index 8fc57cf..f9a6ad3 100644 --- a/lib/chat_list/views/chat_list_widget.dart +++ b/lib/chat_list/views/chat_list_widget.dart @@ -18,10 +18,10 @@ class ChatListWidget extends StatelessWidget { Widget _itemBuilderDirect( proto.DirectChat direct, IMap contactMap) { final contact = contactMap[direct.localConversationRecordKey]; - if (contact == null) { - return const Text('...'); - } - return ChatSingleContactItemWidget(contact: contact) + return ChatSingleContactItemWidget( + localConversationRecordKey: + direct.localConversationRecordKey.toVeilid(), + contact: contact) .paddingLTRB(0, 4, 0, 0); } diff --git a/lib/chat_list/views/chat_single_contact_item_widget.dart b/lib/chat_list/views/chat_single_contact_item_widget.dart index 1bd5f64..4ac992f 100644 --- a/lib/chat_list/views/chat_single_contact_item_widget.dart +++ b/lib/chat_list/views/chat_single_contact_item_widget.dart @@ -2,6 +2,7 @@ import 'package:async_tools/async_tools.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_translate/flutter_translate.dart'; +import 'package:veilid_support/veilid_support.dart'; import '../../chat/cubits/active_chat_cubit.dart'; import '../../contacts/contacts.dart'; import '../../proto/proto.dart' as proto; @@ -10,13 +11,16 @@ import '../chat_list.dart'; class ChatSingleContactItemWidget extends StatelessWidget { const ChatSingleContactItemWidget({ - required proto.Contact contact, + required TypedKey localConversationRecordKey, + required proto.Contact? contact, bool disabled = false, super.key, - }) : _contact = contact, + }) : _localConversationRecordKey = localConversationRecordKey, + _contact = contact, _disabled = disabled; - final proto.Contact _contact; + final TypedKey _localConversationRecordKey; + final proto.Contact? _contact; final bool _disabled; @override @@ -29,13 +33,16 @@ class ChatSingleContactItemWidget extends StatelessWidget { final scaleConfig = theme.extension()!; final activeChatCubit = context.watch(); - final localConversationRecordKey = - _contact.localConversationRecordKey.toVeilid(); - final selected = activeChatCubit.state == localConversationRecordKey; + final selected = activeChatCubit.state == _localConversationRecordKey; - final name = _contact.nameOrNickname; - final title = _contact.displayName; - final subtitle = _contact.profile.status; + final name = _contact == null ? '?' : _contact.nameOrNickname; + final title = _contact == null + ? translate('chat_list.deleted_contact') + : _contact.displayName; + final subtitle = _contact == null ? '' : _contact.profile.status; + final availability = _contact == null + ? proto.Availability.AVAILABILITY_UNSPECIFIED + : _contact.profile.availability; final avatar = AvatarWidget( name: name, @@ -53,17 +60,17 @@ class ChatSingleContactItemWidget extends StatelessWidget { ); return SliderTile( - key: ObjectKey(_contact), + key: ValueKey(_localConversationRecordKey), disabled: _disabled, selected: selected, tileScale: ScaleKind.secondary, title: title, subtitle: subtitle, leading: avatar, - trailing: AvailabilityWidget(availability: _contact.profile.availability), + trailing: AvailabilityWidget(availability: availability), onTap: () { singleFuture(activeChatCubit, () async { - activeChatCubit.setActiveChat(localConversationRecordKey); + activeChatCubit.setActiveChat(_localConversationRecordKey); }); }, endActions: [ @@ -74,7 +81,7 @@ class ChatSingleContactItemWidget extends StatelessWidget { onPressed: (context) async { final chatListCubit = context.read(); await chatListCubit.deleteChat( - localConversationRecordKey: localConversationRecordKey); + localConversationRecordKey: _localConversationRecordKey); }) ], ); diff --git a/lib/tools/loggy.dart b/lib/tools/loggy.dart index 1df4c82..b22025e 100644 --- a/lib/tools/loggy.dart +++ b/lib/tools/loggy.dart @@ -9,7 +9,6 @@ import 'package:loggy/loggy.dart'; import 'package:veilid_support/veilid_support.dart'; import '../veilid_processor/views/developer.dart'; -import '../theme/views/responsive.dart'; import 'state_logger.dart'; String wrapWithLogColor(LogLevel? level, String text) { @@ -112,13 +111,16 @@ class CallbackPrinter extends LoggyPrinter { @override void onLog(LogRecord record) { final out = record.pretty(); - //if (isDesktop) { - debugPrintSynchronously(out); - //} + if (Platform.isAndroid) { + debugPrint(out); + } else { + debugPrintSynchronously(out); + } globalDebugTerminal.write('$out\n'.replaceAll('\n', '\r\n')); callback?.call(record); } + // ignore: use_setters_to_change_properties void setCallback(void Function(LogRecord)? cb) { callback = cb; } diff --git a/lib/tools/state_logger.dart b/lib/tools/state_logger.dart index 6baacae..08e32b3 100644 --- a/lib/tools/state_logger.dart +++ b/lib/tools/state_logger.dart @@ -4,12 +4,12 @@ import 'loggy.dart'; const Map _blocChangeLogLevels = { 'ConnectionStateCubit': LogLevel.off, - //'ActiveSingleContactChatBlocMapCubit': LogLevel.off, - //'ActiveConversationsBlocMapCubit': LogLevel.off, + 'ActiveSingleContactChatBlocMapCubit': LogLevel.off, + 'ActiveConversationsBlocMapCubit': LogLevel.off, 'PersistentQueueCubit': LogLevel.off, 'TableDBArrayProtobufCubit': LogLevel.off, 'DHTLogCubit': LogLevel.off, - //'SingleContactMessagesCubit': LogLevel.off, + 'SingleContactMessagesCubit': LogLevel.off, 'ChatComponentCubit': LogLevel.off, };