Skip to content

Commit

Permalink
fixup! feat: new encrypted message design
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Oct 3, 2023
1 parent ca5a553 commit 33ff801
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 72 deletions.
75 changes: 3 additions & 72 deletions lib/pages/chat/events/encrypted_content.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
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:fluffychat/pages/chat/events/encrypted_mixin.dart';
import 'package:flutter/material.dart';
import 'package:matrix/matrix.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

class EncryptedContent extends StatelessWidget {
class EncryptedContent extends StatelessWidget with EncryptedMixin {
final Event event;

const EncryptedContent({Key? key, required this.event}) : super(key: key);
Expand All @@ -20,7 +14,7 @@ class EncryptedContent extends StatelessWidget {
return Padding(
padding: EncryptedContentStyle.parentPadding,
child: InkWell(
onTap: () => _verifyOrRequestKey(context),
onTap: () => verifyOrRequestKey(context, event),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -54,67 +48,4 @@ class EncryptedContent extends StatelessWidget {
),
);
}

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),
),
)
],
),
),
),
);
}
}
75 changes: 75 additions & 0 deletions lib/pages/chat/events/encrypted_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:fluffychat/pages/bootstrap/bootstrap_dialog.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';

mixin EncryptedMixin {
void verifyOrRequestKey(BuildContext context, Event event) 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),
),
)
],
),
),
),
);
}
}

0 comments on commit 33ff801

Please sign in to comment.