-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julian KOUNE
committed
Sep 29, 2023
1 parent
2d4c8b7
commit 017e924
Showing
6 changed files
with
158 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import 'package:fluffychat/pages/bootstrap/bootstrap_dialog.dart'; | ||
import 'package:fluffychat/pages/chat/events/encrypted_content_style.dart'; | ||
import 'package:fluffychat/pages/chat/events/message_content_style.dart'; | ||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; | ||
import 'package:fluffychat/utils/date_time_extension.dart'; | ||
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; | ||
import 'package:fluffychat/widgets/avatar/avatar.dart'; | ||
import 'package:fluffychat/widgets/matrix.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:matrix/matrix.dart'; | ||
import 'package:flutter_gen/gen_l10n/l10n.dart'; | ||
|
||
class EncryptedContent extends StatelessWidget { | ||
final Event event; | ||
|
||
const EncryptedContent({Key? key, required this.event}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: EncryptedContentStyle.parentPadding, | ||
child: InkWell( | ||
onTap: () => _verifyOrRequestKey(context), | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
Container( | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).colorScheme.onError, | ||
shape: BoxShape.circle, | ||
), | ||
padding: EncryptedContentStyle.leadingIconPadding, | ||
child: Icon( | ||
Icons.delete_outline, | ||
color: Theme.of(context).colorScheme.primary, | ||
size: EncryptedContentStyle.leadingIconSize, | ||
), | ||
), | ||
const SizedBox(width: EncryptedContentStyle.leadingAndTextGap), | ||
Container( | ||
constraints: const BoxConstraints( | ||
maxWidth: EncryptedContentStyle.containerTextMaxWidth, | ||
), | ||
child: Text( | ||
maxLines: 2, | ||
L10n.of(context)!.thisMessageHasBeenEncrypted, | ||
style: Theme.of(context).textTheme.bodyMedium!.copyWith( | ||
color: Theme.of(context).colorScheme.onSurface, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(width: EncryptedContentStyle.textAndTrailingGap), | ||
Icon( | ||
Icons.lock, | ||
color: Theme.of(context).colorScheme.tertiary, | ||
size: EncryptedContentStyle.trailingIconSize, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
void _verifyOrRequestKey(BuildContext context) async { | ||
final l10n = L10n.of(context)!; | ||
if (event.content['can_request_session'] != true) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text( | ||
event.type == EventTypes.Encrypted | ||
? l10n.needPantalaimonWarning | ||
: event.calcLocalizedBodyFallback( | ||
MatrixLocals(l10n), | ||
), | ||
), | ||
), | ||
); | ||
return; | ||
} | ||
final client = Matrix.of(context).client; | ||
if (client.isUnknownSession && client.encryption!.crossSigning.enabled) { | ||
final success = await BootstrapDialog( | ||
client: Matrix.of(context).client, | ||
).show(context); | ||
if (success != true) return; | ||
} | ||
event.requestKey(); | ||
final sender = event.senderFromMemoryOrFallback; | ||
await showAdaptiveBottomSheet( | ||
context: context, | ||
builder: (context) => Scaffold( | ||
appBar: AppBar( | ||
leading: CloseButton(onPressed: Navigator.of(context).pop), | ||
title: Text( | ||
l10n.whyIsThisMessageEncrypted, | ||
style: | ||
const TextStyle(fontSize: MessageContentStyle.appBarFontSize), | ||
), | ||
), | ||
body: SafeArea( | ||
child: ListView( | ||
padding: const EdgeInsets.all(16), | ||
children: [ | ||
ListTile( | ||
contentPadding: EdgeInsets.zero, | ||
leading: Avatar( | ||
mxContent: sender.avatarUrl, | ||
name: sender.calcDisplayname(), | ||
), | ||
title: Text(sender.calcDisplayname()), | ||
subtitle: Text(event.originServerTs.localizedTime(context)), | ||
trailing: const Icon(Icons.lock_outlined), | ||
), | ||
const Divider(), | ||
Text( | ||
event.calcLocalizedBodyFallback( | ||
MatrixLocals(l10n), | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class EncryptedContentStyle { | ||
static const EdgeInsets parentPadding = EdgeInsets.symmetric( | ||
horizontal: 8, | ||
); | ||
static const EdgeInsets leadingIconPadding = EdgeInsets.all(5); | ||
static const double leadingIconSize = 20; | ||
static const double leadingAndTextGap = 8; | ||
static const double textAndTrailingGap = 40; | ||
static const double containerTextMaxWidth = 165.0; | ||
static const double trailingIconSize = 16; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters