@@ -17,15 +17,26 @@ import 'store.dart';
17
17
///
18
18
/// Must have a [MessageListPage] ancestor.
19
19
void showMessageActionSheet ({required BuildContext context, required Message message}) {
20
+ final store = PerAccountStoreWidget .of (context);
21
+
20
22
// The UI that's conditioned on this won't live-update during this appearance
21
23
// of the action sheet (we avoid calling composeBoxControllerOf in a build
22
24
// method; see its doc). But currently it will be constant through the life of
23
25
// any message list, so that's fine.
24
26
final isComposeBoxOffered = MessageListPage .composeBoxControllerOf (context) != null ;
27
+
28
+ final selfUserId = store.account.userId;
29
+ final hasThumbsUpReactionVote = message.reactions
30
+ ? .aggregated.any ((reactionWithVotes) =>
31
+ reactionWithVotes.emojiCode == '1f44d'
32
+ && reactionWithVotes.userIds.contains (selfUserId))
33
+ ?? false ;
34
+
25
35
showDraggableScrollableModalBottomSheet (
26
36
context: context,
27
37
builder: (BuildContext _) {
28
38
return Column (children: [
39
+ if (! hasThumbsUpReactionVote) AddThumbsUpButton (message: message, messageListContext: context),
29
40
ShareButton (message: message, messageListContext: context),
30
41
if (isComposeBoxOffered) QuoteAndReplyButton (
31
42
message: message,
@@ -60,6 +71,49 @@ abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
60
71
}
61
72
}
62
73
74
+ // This button is very temporary, to complete #125 before we have a way to
75
+ // choose an arbitrary reaction (#388). So, skipping tests and i18n.
76
+ class AddThumbsUpButton extends MessageActionSheetMenuItemButton {
77
+ AddThumbsUpButton ({
78
+ super .key,
79
+ required super .message,
80
+ required super .messageListContext,
81
+ });
82
+
83
+ @override get icon => Icons .add_reaction_outlined;
84
+
85
+ @override
86
+ String label (ZulipLocalizations zulipLocalizations) {
87
+ return 'React with 👍' ; // skip translation for now
88
+ }
89
+
90
+ @override get onPressed => (BuildContext context) async {
91
+ Navigator .of (context).pop ();
92
+ String ? errorMessage;
93
+ try {
94
+ await addReaction (PerAccountStoreWidget .of (messageListContext).connection,
95
+ messageId: message.id,
96
+ reactionType: ReactionType .unicodeEmoji,
97
+ emojiCode: '1f44d' ,
98
+ emojiName: '+1' ,
99
+ );
100
+ } catch (e) {
101
+ if (! messageListContext.mounted) return ;
102
+
103
+ switch (e) {
104
+ case ZulipApiException ():
105
+ errorMessage = e.message;
106
+ // TODO specific messages for common errors, like network errors
107
+ // (support with reusable code)
108
+ default :
109
+ }
110
+
111
+ await showErrorDialog (context: context,
112
+ title: 'Adding reaction failed' , message: errorMessage);
113
+ }
114
+ };
115
+ }
116
+
63
117
class ShareButton extends MessageActionSheetMenuItemButton {
64
118
ShareButton ({
65
119
super .key,
0 commit comments