diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index bd4238c96..d50e8f3fe 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -2821,5 +2821,6 @@ "invalidUrl": "Invalid url", "addLink": "Add link", "unableToJoinChat": "Unable to join chat. Maybe the other party has already closed the conversation.", - "previous": "Previous" + "previous": "Previous", + "otherPartyNotLoggedIn": "The other party is currently not logged in and therefore cannot receive messages!" } diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index fd32c26fa..941b9c02f 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -30,6 +30,7 @@ import 'package:fluffychat/utils/file_selector.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/filtered_timeline_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; +import 'package:fluffychat/utils/other_party_can_receive.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/show_scaffold_dialog.dart'; import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart'; @@ -237,6 +238,23 @@ class ChatController extends State void _shareItems([_]) { final shareItems = widget.shareItems; if (shareItems == null || shareItems.isEmpty) return; + if (!room.otherPartyCanReceiveMessages) { + final theme = Theme.of(context); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: theme.colorScheme.errorContainer, + closeIconColor: theme.colorScheme.onErrorContainer, + content: Text( + L10n.of(context).otherPartyNotLoggedIn, + style: TextStyle( + color: theme.colorScheme.onErrorContainer, + ), + ), + showCloseIcon: true, + ), + ); + return; + } for (final item in shareItems) { if (item is FileShareItem) continue; if (item is TextShareItem) room.sendTextEvent(item.value); diff --git a/lib/pages/chat/chat_input_row.dart b/lib/pages/chat/chat_input_row.dart index 9d4fe4602..1cdb283b1 100644 --- a/lib/pages/chat/chat_input_row.dart +++ b/lib/pages/chat/chat_input_row.dart @@ -5,6 +5,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/utils/other_party_can_receive.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -25,6 +26,20 @@ class ChatInputRow extends StatelessWidget { return const SizedBox.shrink(); } const height = 48.0; + + if (!controller.room.otherPartyCanReceiveMessages) { + return Center( + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Text( + L10n.of(context).otherPartyNotLoggedIn, + style: theme.textTheme.bodySmall, + textAlign: TextAlign.center, + ), + ), + ); + } + return Row( crossAxisAlignment: CrossAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.spaceBetween, diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index bb524b8d0..00ffae04b 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -12,6 +12,7 @@ import 'package:mime/mime.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; +import 'package:fluffychat/utils/other_party_can_receive.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/size_string.dart'; import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart'; @@ -44,6 +45,9 @@ class SendFileDialogState extends State { final l10n = L10n.of(context); try { + if (!widget.room.otherPartyCanReceiveMessages) { + throw OtherPartyCanNotReceiveMessages(); + } scaffoldMessenger.showLoadingSnackBar(l10n.prepareSendingAttachment); Navigator.of(context, rootNavigator: false).pop(); final clientConfig = await widget.room.client.getConfig(); diff --git a/lib/utils/other_party_can_receive.dart b/lib/utils/other_party_can_receive.dart new file mode 100644 index 000000000..1738785d2 --- /dev/null +++ b/lib/utils/other_party_can_receive.dart @@ -0,0 +1,21 @@ +import 'package:matrix/matrix.dart'; + +extension OtherPartyCanReceiveExtension on Room { + bool get otherPartyCanReceiveMessages { + if (!encrypted) return true; + final users = getParticipants() + .map((u) => u.id) + .where((userId) => userId != client.userID) + .toSet(); + if (users.isEmpty) return true; + + for (final userId in users) { + if (client.userDeviceKeys[userId]?.deviceKeys.values.isNotEmpty == true) { + return true; + } + } + return false; + } +} + +class OtherPartyCanNotReceiveMessages implements Exception {}