Skip to content

Commit

Permalink
feat: Write and display reason for redacting a message
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Aug 12, 2023
1 parent b27af74 commit 5e3c621
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
17 changes: 17 additions & 0 deletions assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,8 @@
"type": "text",
"placeholders": {}
},
"redactMessageDescription": "The message will be redacted for all participants in this conversation. This cannot be undone.",
"optionalRedactReason": "(Optional) Reason for redacting this message...",
"invitedUser": "📩 {username} invited {targetName}",
"@invitedUser": {
"type": "text",
Expand Down Expand Up @@ -1568,6 +1570,21 @@
"type": "text",
"placeholders": {}
},
"redactedBy": "Redacted by {username}",
"@redactedBy": {
"type": "text",
"placeholders": {
"username": {}
}
},
"redactedByBecause": "Redacted by {username} because: \"{reason}\"",
"@redactedByBecause": {
"type": "text",
"placeholders": {
"username": {},
"reason": {}
}
},
"redactedAnEvent": "{username} redacted an event",
"@redactedAnEvent": {
"type": "text",
Expand Down
30 changes: 19 additions & 11 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -734,22 +734,28 @@ class ChatController extends State<ChatPageWithRoom> {
}

void redactEventsAction() async {
final confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
context: context,
title: L10n.of(context)!.messageWillBeRemovedWarning,
okLabel: L10n.of(context)!.remove,
cancelLabel: L10n.of(context)!.cancel,
) ==
OkCancelResult.ok;
if (!confirmed) return;
final reasonInput = await showTextInputDialog(
context: context,
title: L10n.of(context)!.redactMessage,
message: L10n.of(context)!.redactMessageDescription,
isDestructiveAction: true,
textFields: [
DialogTextField(
hintText: L10n.of(context)!.optionalRedactReason,
),
],
okLabel: L10n.of(context)!.remove,
cancelLabel: L10n.of(context)!.cancel,
);
if (reasonInput == null) return;
final reason = reasonInput.single.isEmpty ? null : reasonInput.single;
for (final event in selectedEvents) {
await showFutureLoadingDialog(
context: context,
future: () async {
if (event.status.isSent) {
if (event.canRedact) {
await event.redactEvent();
await event.redactEvent(reason: reason);
} else {
final client = currentRoomBundle.firstWhere(
(cl) => selectedEvents.first.senderId == cl!.userID,
Expand All @@ -759,7 +765,9 @@ class ChatController extends State<ChatPageWithRoom> {
return;
}
final room = client.getRoomById(roomId)!;
await Event.fromJson(event.toJson(), room).redactEvent();
await Event.fromJson(event.toJson(), room).redactEvent(
reason: reason,
);
}
} else {
await event.remove();
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/chat/events/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ class Message extends StatelessWidget {
container = row;
}

if (event.messageType == MessageTypes.BadEncrypted || event.redacted) {
container = Opacity(opacity: 0.33, child: container);
if (event.messageType == MessageTypes.BadEncrypted) {
container = Opacity(opacity: 0.4, child: container);
}

return Swipeable(
Expand Down
45 changes: 22 additions & 23 deletions lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class MessageContent extends StatelessWidget {
return _ButtonContent(
textColor: buttonTextColor,
onPressed: () => _verifyOrRequestKey(context),
icon: const Icon(Icons.lock_outline),
icon: '🔒',
label: L10n.of(context)!.encrypted,
fontSize: fontSize,
);
Expand Down Expand Up @@ -208,12 +208,19 @@ class MessageContent extends StatelessWidget {
return FutureBuilder<User?>(
future: event.redactedBecause?.fetchSenderUser(),
builder: (context, snapshot) {
final reason =
event.redactedBecause?.content.tryGet<String>('reason');
final redactedBy = snapshot.data?.calcDisplayname() ??
event.redactedBecause?.senderId.localpart ??
L10n.of(context)!.user;
return _ButtonContent(
label: L10n.of(context)!.redactedAnEvent(
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
),
icon: const Icon(Icons.delete_outlined),
label: reason == null
? L10n.of(context)!.redactedBy(redactedBy)
: L10n.of(context)!.redactedByBecause(
redactedBy,
reason,
),
icon: '🗑️',
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
fontSize: fontSize,
Expand Down Expand Up @@ -263,7 +270,7 @@ class MessageContent extends StatelessWidget {
snapshot.data?.calcDisplayname() ??
event.senderFromMemoryOrFallback.calcDisplayname(),
),
icon: const Icon(Icons.phone_outlined),
icon: '📞',
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
fontSize: fontSize,
Expand All @@ -280,7 +287,7 @@ class MessageContent extends StatelessWidget {
event.senderFromMemoryOrFallback.calcDisplayname(),
event.type,
),
icon: const Icon(Icons.info_outlined),
icon: 'ℹ️',
textColor: buttonTextColor,
onPressed: () => onInfoTab!(event),
fontSize: fontSize,
Expand All @@ -294,7 +301,7 @@ class MessageContent extends StatelessWidget {
class _ButtonContent extends StatelessWidget {
final void Function() onPressed;
final String label;
final Icon icon;
final String icon;
final Color? textColor;
final double fontSize;

Expand All @@ -311,20 +318,12 @@ class _ButtonContent extends StatelessWidget {
Widget build(BuildContext context) {
return InkWell(
onTap: onPressed,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
icon,
const SizedBox(width: 8),
Text(
label,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: textColor,
fontSize: fontSize,
),
),
],
child: Text(
'$icon $label',
style: TextStyle(
color: textColor,
fontSize: fontSize,
),
),
);
}
Expand Down

0 comments on commit 5e3c621

Please sign in to comment.