Skip to content

Commit

Permalink
star in action sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Dec 4, 2023
1 parent c8b6c04 commit 79f03fd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
"@actionSheetOptionQuoteAndReply": {
"description": "Label for Quote and reply button on action sheet."
},
"actionSheetOptionStarMessage": "Star message",
"@actionSheetOptionStarMessage": {
"description": "Label for star button on action sheet."
},
"actionSheetOptionUnstarMessage": "Unstar message",
"@actionSheetOptionUnstarMessage": {
"description": "Label for unstar button on action sheet."
},
"errorCouldNotFetchMessageSource": "Could not fetch message source",
"@errorCouldNotFetchMessageSource": {
"description": "Error message when the source of a message could not be fetched."
Expand Down Expand Up @@ -128,6 +136,14 @@
"@errorSharingFailed": {
"description": "Error message when sharing a message failed."
},
"errorStarMessageFailedTitle": "Failed to star message",
"@errorStarMessageFailedTitle": {
"description": "Error title when starring a message failed."
},
"errorUnstarMessageFailedTitle": "Failed to unstar message",
"@errorUnstarMessageFailedTitle": {
"description": "Error title when unstarring a message failed."
},
"successLinkCopied": "Link copied",
"@successLinkCopied": {
"description": "Success message after copy link action completed."
Expand Down
48 changes: 48 additions & 0 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
messageListContext: context,
),
CopyButton(message: message, messageListContext: context),
StarButton(message: message, messageListContext: context),
]);
});
}
Expand Down Expand Up @@ -317,3 +318,50 @@ class CopyButton extends MessageActionSheetMenuItemButton {
data: ClipboardData(text: rawContent));
};
}

class StarButton extends MessageActionSheetMenuItemButton {
StarButton({
super.key,
required super.message,
required super.messageListContext,
});

@override get icon => Icons.star;

@override
String label(ZulipLocalizations zulipLocalizations) {
return message.flags.contains(MessageFlag.starred)
? zulipLocalizations.actionSheetOptionUnstarMessage
: zulipLocalizations.actionSheetOptionStarMessage;
}

@override get onPressed => (BuildContext context) async {
Navigator.of(context).pop();
String? errorMessage;
final op = (message.flags.contains(MessageFlag.starred))
? UpdateMessageFlagsOp.remove
: UpdateMessageFlagsOp.add;
try {
final connection = PerAccountStoreWidget.of(messageListContext).connection;
await updateMessageFlags(connection, messages: [message.id],
op: op, flag: MessageFlag.starred);
} catch (e) {
if (!messageListContext.mounted) return;
final zulipLocalizations = ZulipLocalizations.of(messageListContext);

switch (e) {
case ZulipApiException():
errorMessage = e.message;
// TODO specific messages for common errors, like network errors
// (support with reusable code)
default:
}

await showErrorDialog(context: messageListContext,
title: switch(op) {
UpdateMessageFlagsOp.add => zulipLocalizations.errorStarMessageFailedTitle,
UpdateMessageFlagsOp.remove => zulipLocalizations.errorUnstarMessageFailedTitle,
}, message: errorMessage);
}
};
}

0 comments on commit 79f03fd

Please sign in to comment.