Skip to content

Commit a22db60

Browse files
authored
feat: add push rule settings tab to settings dialog (#117)
* feat: add push rule settings tab to settings dialog * feat: enhance chat settings push rule tile layout and functionality * feat: enhance display of push rule JSON with improved styling
1 parent bda2935 commit a22db60

16 files changed

+1427
-26
lines changed

lib/events/view/chat_event_tile.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ class ChatEventTile extends StatelessWidget {
1515
required this.timeline,
1616
required this.onReplyOriginClick,
1717
required this.eventPosition,
18+
this.color,
1819
});
1920

2021
final Event event;
2122
final EventPosition eventPosition;
2223
final Timeline timeline;
2324
final Future<void> Function(Event) onReplyOriginClick;
25+
final Color? color;
2426

2527
@override
2628
Widget build(BuildContext context) {
@@ -55,6 +57,7 @@ class ChatEventTile extends StatelessWidget {
5557
timeline: timeline,
5658
onReplyOriginClick: onReplyOriginClick,
5759
eventPosition: eventPosition,
60+
color: color,
5861
);
5962
}
6063
}

lib/events/view/chat_message_bubble.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ChatMessageBubble extends StatelessWidget {
1212
required this.timeline,
1313
required this.onReplyOriginClick,
1414
required this.eventPosition,
15+
this.color,
1516
});
1617

1718
final Event event;
@@ -22,6 +23,8 @@ class ChatMessageBubble extends StatelessWidget {
2223
static const maxWidth = 450.0;
2324
static const minWidth = 205.0;
2425

26+
final Color? color;
27+
2528
@override
2629
Widget build(BuildContext context) => Align(
2730
alignment: event.isUserEvent ? Alignment.centerRight : Alignment.centerLeft,
@@ -43,6 +46,7 @@ class ChatMessageBubble extends StatelessWidget {
4346
bottom: kSmallPadding,
4447
),
4548
child: ChatMessageBubbleContent(
49+
color: color,
4650
eventPosition: eventPosition,
4751
event: event,
4852
timeline: timeline,

lib/events/view/chat_message_bubble_content.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ class ChatMessageBubbleContent extends StatelessWidget with PlayerControlMixin {
3333
required this.timeline,
3434
required this.onReplyOriginClick,
3535
required this.eventPosition,
36+
this.color,
3637
});
3738

3839
final Event event;
3940
final Timeline timeline;
4041
final Future<void> Function(Event event) onReplyOriginClick;
4142
final EventPosition eventPosition;
43+
final Color? color;
4244

4345
@override
4446
Widget build(BuildContext context) {
@@ -93,10 +95,12 @@ class ChatMessageBubbleContent extends StatelessWidget with PlayerControlMixin {
9395
horizontal: kMediumPadding,
9496
),
9597
decoration: BoxDecoration(
96-
color: getTileColor(
97-
event.isUserEvent,
98-
context.theme,
99-
),
98+
color:
99+
color ??
100+
getTileColor(
101+
event.isUserEvent,
102+
context.theme,
103+
),
100104
borderRadius: switch (eventPosition) {
101105
EventPosition.middle => BorderRadius.circular(
102106
kBubbleRadiusValue,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ignore_for_file: use_build_context_synchronously
2+
3+
import 'package:matrix/matrix.dart';
4+
5+
import '../l10n/app_localizations.dart';
6+
7+
extension PushRuleExtension on PushRule {
8+
String getPushRuleName(AppLocalizations l10n) => switch (ruleId) {
9+
'.m.rule.contains_user_name' => l10n.notificationRuleContainsUserName,
10+
'.m.rule.master' => l10n.notificationRuleMaster,
11+
'.m.rule.suppress_notices' => l10n.notificationRuleSuppressNotices,
12+
'.m.rule.invite_for_me' => l10n.notificationRuleInviteForMe,
13+
'.m.rule.member_event' => l10n.notificationRuleMemberEvent,
14+
'.m.rule.is_user_mention' => l10n.notificationRuleIsUserMention,
15+
'.m.rule.contains_display_name' => l10n.notificationRuleContainsDisplayName,
16+
'.m.rule.is_room_mention' => l10n.notificationRuleIsRoomMention,
17+
'.m.rule.roomnotif' => l10n.notificationRuleRoomnotif,
18+
'.m.rule.tombstone' => l10n.notificationRuleTombstone,
19+
'.m.rule.reaction' => l10n.notificationRuleReaction,
20+
'.m.rule.room_server_acl' => l10n.notificationRuleRoomServerAcl,
21+
'.m.rule.suppress_edits' => l10n.notificationRuleSuppressEdits,
22+
'.m.rule.call' => l10n.notificationRuleCall,
23+
'.m.rule.encrypted_room_one_to_one' =>
24+
l10n.notificationRuleEncryptedRoomOneToOne,
25+
'.m.rule.room_one_to_one' => l10n.notificationRuleRoomOneToOne,
26+
'.m.rule.message' => l10n.notificationRuleMessage,
27+
'.m.rule.encrypted' => l10n.notificationRuleEncrypted,
28+
'.m.rule.room.server_acl' => l10n.notificationRuleServerAcl,
29+
'.im.vector.jitsi' => l10n.notificationRuleJitsi,
30+
_ => ruleId.split('.').last.replaceAll('_', ' ').capitalize(),
31+
};
32+
33+
String getPushRuleDescription(AppLocalizations l10n) => switch (ruleId) {
34+
'.m.rule.contains_user_name' =>
35+
l10n.notificationRuleContainsUserNameDescription,
36+
'.m.rule.master' => l10n.notificationRuleMasterDescription,
37+
'.m.rule.suppress_notices' =>
38+
l10n.notificationRuleSuppressNoticesDescription,
39+
'.m.rule.invite_for_me' => l10n.notificationRuleInviteForMeDescription,
40+
'.m.rule.member_event' => l10n.notificationRuleMemberEventDescription,
41+
'.m.rule.is_user_mention' => l10n.notificationRuleIsUserMentionDescription,
42+
'.m.rule.contains_display_name' =>
43+
l10n.notificationRuleContainsDisplayNameDescription,
44+
'.m.rule.is_room_mention' => l10n.notificationRuleIsRoomMentionDescription,
45+
'.m.rule.roomnotif' => l10n.notificationRuleRoomnotifDescription,
46+
'.m.rule.tombstone' => l10n.notificationRuleTombstoneDescription,
47+
'.m.rule.reaction' => l10n.notificationRuleReactionDescription,
48+
'.m.rule.room_server_acl' => l10n.notificationRuleRoomServerAclDescription,
49+
'.m.rule.suppress_edits' => l10n.notificationRuleSuppressEditsDescription,
50+
'.m.rule.call' => l10n.notificationRuleCallDescription,
51+
'.m.rule.encrypted_room_one_to_one' =>
52+
l10n.notificationRuleEncryptedRoomOneToOneDescription,
53+
'.m.rule.room_one_to_one' => l10n.notificationRuleRoomOneToOneDescription,
54+
'.m.rule.message' => l10n.notificationRuleMessageDescription,
55+
'.m.rule.encrypted' => l10n.notificationRuleEncryptedDescription,
56+
'.m.rule.room.server_acl' => l10n.notificationRuleServerAclDescription,
57+
'.im.vector.jitsi' => l10n.notificationRuleJitsiDescription,
58+
_ => l10n.unknownPushRule(ruleId),
59+
};
60+
}
61+
62+
extension PushRuleKindLocal on PushRuleKind {
63+
String localized(AppLocalizations l10n) => switch (this) {
64+
PushRuleKind.content => l10n.contentNotificationSettings,
65+
PushRuleKind.override => l10n.generalNotificationSettings,
66+
PushRuleKind.room => l10n.roomNotificationSettings,
67+
PushRuleKind.sender => l10n.userSpecificNotificationSettings,
68+
PushRuleKind.underride => l10n.otherNotificationSettings,
69+
};
70+
}
71+
72+
extension on String {
73+
String capitalize() =>
74+
'${this[0].toUpperCase()}${substring(1).toLowerCase()}';
75+
}

lib/l10n/app_en.arb

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3187,5 +3187,72 @@
31873187
"appendMediaToQueueButton": "Append to queue",
31883188
"clipboardNotAvailable": "Clipboard not available",
31893189
"noSupportedFormatFoundInClipboard": "No supported format found in clipboard",
3190-
"fileIsTooLarge": "File is too large"
3190+
"fileIsTooLarge": "File is too large",
3191+
"notificationRuleContainsUserName": "Contains User Name",
3192+
"notificationRuleMaster": "Master",
3193+
"notificationRuleSuppressNotices": "Suppress Notices",
3194+
"notificationRuleInviteForMe": "Invitation for me",
3195+
"notificationRuleMemberEvent": "Member Event",
3196+
"notificationRuleIsUserMention": "User Mention",
3197+
"notificationRuleContainsDisplayName": "Contains Display Name",
3198+
"notificationRuleIsRoomMention": "Room Mention",
3199+
"notificationRuleRoomnotif": "Room Notification",
3200+
"notificationRuleTombstone": "Tombstone",
3201+
"notificationRuleReaction": "Reaction",
3202+
"notificationRuleRoomServerAcl": "Room Server ACL",
3203+
"notificationRuleSuppressEdits": "Suppress Edits",
3204+
"notificationRuleCall": "Call",
3205+
"notificationRuleEncryptedRoomOneToOne": "Encrypted Room (One-to-One)",
3206+
"notificationRuleRoomOneToOne": "Room (One-to-One)",
3207+
"notificationRuleMessage": "Message",
3208+
"notificationRuleEncrypted": "Encrypted",
3209+
"notificationRuleServerAcl": "Server ACL",
3210+
"notificationRuleJitsi": "Jitsi",
3211+
"notificationRuleContainsUserNameDescription": "Username is contained in the content",
3212+
"notificationRuleMasterDescription": "Master notification",
3213+
"notificationRuleSuppressNoticesDescription": "Suppress notices",
3214+
"notificationRuleInviteForMeDescription": "Invitation for me",
3215+
"notificationRuleMemberEventDescription": "Member event",
3216+
"notificationRuleIsUserMentionDescription": "User mention",
3217+
"notificationRuleContainsDisplayNameDescription": "Contains display name",
3218+
"notificationRuleIsRoomMentionDescription": "Room mention",
3219+
"notificationRuleRoomnotifDescription": "Room notification",
3220+
"notificationRuleTombstoneDescription": "Tombstone",
3221+
"notificationRuleReactionDescription": "Reaction",
3222+
"notificationRuleRoomServerAclDescription": "Room server ACL",
3223+
"notificationRuleSuppressEditsDescription": "Suppress edits",
3224+
"notificationRuleCallDescription": "Call",
3225+
"notificationRuleEncryptedRoomOneToOneDescription": "Encrypted Room (One-to-One)",
3226+
"notificationRuleRoomOneToOneDescription": "Room (One-to-One)",
3227+
"notificationRuleMessageDescription": "Message",
3228+
"notificationRuleEncryptedDescription": "Encrypted",
3229+
"notificationRuleServerAclDescription": "Server ACL",
3230+
"notificationRuleJitsiDescription": "Jitsi",
3231+
"unknownPushRule": "Custom push rule {ruleId}",
3232+
"@unknownPushRule": {
3233+
"type": "text",
3234+
"placeholders": {
3235+
"ruleId": {}
3236+
}
3237+
},
3238+
"contentNotificationSettings": "Content notification settings",
3239+
"generalNotificationSettings": "General notification settings",
3240+
"roomNotificationSettings": "Room notification settings",
3241+
"userSpecificNotificationSettings": "User-specific notification settings",
3242+
"otherNotificationSettings": "Other notification settings",
3243+
"deletePushRuleTitle": "Delete push rule {ruleName}?",
3244+
"@deletePushRuleTitle": {
3245+
"type": "text",
3246+
"placeholders": {
3247+
"ruleName": {}
3248+
}
3249+
},
3250+
"deletePushRuleDescription": "Do you really want to delete the push rule {ruleName}? This action cannot be undone.",
3251+
"@deletePushRuleDescription": {
3252+
"type": "text",
3253+
"placeholders": {
3254+
"ruleName": {}
3255+
}
3256+
},
3257+
"pusherDevices": "Pusher Devices"
31913258
}

0 commit comments

Comments
 (0)