feat: Prevent sending messages if other party has no encryption keys
This commit is contained in:
parent
8cb06d602b
commit
aa010767de
5 changed files with 60 additions and 1 deletions
|
|
@ -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!"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ChatPageWithRoom>
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<SendFileDialog> {
|
|||
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();
|
||||
|
|
|
|||
21
lib/utils/other_party_can_receive.dart
Normal file
21
lib/utils/other_party_can_receive.dart
Normal file
|
|
@ -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 {}
|
||||
Loading…
Add table
Reference in a new issue