@@ -14,14 +14,22 @@ import 'theme.dart';
14
14
import 'unread_count_badge.dart' ;
15
15
import 'user.dart' ;
16
16
17
+ typedef OnDmSelectCallback = void Function (DmNarrow narrow);
18
+
17
19
class RecentDmConversationsPageBody extends StatefulWidget {
18
20
const RecentDmConversationsPageBody ({
19
21
super .key,
20
22
this .hideDmsIfUserCantPost = false ,
23
+ this .onDmSelect,
21
24
});
22
25
23
26
final bool hideDmsIfUserCantPost;
24
27
28
+ /// Callback to invoke when the user selects a DM conversation from the list.
29
+ ///
30
+ /// If null, the default behavior is to navigate to the DM conversation.
31
+ final OnDmSelectCallback ? onDmSelect;
32
+
25
33
@override
26
34
State <RecentDmConversationsPageBody > createState () => _RecentDmConversationsPageBodyState ();
27
35
}
@@ -55,6 +63,18 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
55
63
});
56
64
}
57
65
66
+ void _handleDmSelect (DmNarrow narrow) {
67
+ Navigator .push (context,
68
+ MessageListPage .buildRoute (context: context,
69
+ narrow: narrow));
70
+ }
71
+
72
+ void _handleDmSelectForNewDms (DmNarrow narrow) {
73
+ Navigator .pushReplacement (context,
74
+ MessageListPage .buildRoute (context: context,
75
+ narrow: narrow));
76
+ }
77
+
58
78
@override
59
79
Widget build (BuildContext context) {
60
80
final store = PerAccountStoreWidget .of (context);
@@ -91,11 +111,20 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
91
111
}
92
112
return RecentDmConversationsItem (
93
113
narrow: narrow,
94
- unreadCount: unreadsModel! .countInDmNarrow (narrow));
114
+ unreadCount: unreadsModel! .countInDmNarrow (narrow),
115
+ onDmSelect: widget.onDmSelect ?? _handleDmSelect);
95
116
})),
96
117
Positioned (
97
118
bottom: 21 ,
98
- child: _NewDmButton ()),
119
+ child: _NewDmButton (onDmSelect: (narrow) {
120
+ if (widget.onDmSelect case final onDmSelect? ) {
121
+ // Pop the new DMs action sheet.
122
+ Navigator .pop (context);
123
+ onDmSelect (narrow);
124
+ } else {
125
+ _handleDmSelectForNewDms (narrow);
126
+ }
127
+ })),
99
128
]);
100
129
}
101
130
}
@@ -105,10 +134,12 @@ class RecentDmConversationsItem extends StatelessWidget {
105
134
super .key,
106
135
required this .narrow,
107
136
required this .unreadCount,
137
+ required this .onDmSelect,
108
138
});
109
139
110
140
final DmNarrow narrow;
111
141
final int unreadCount;
142
+ final OnDmSelectCallback onDmSelect;
112
143
113
144
static const double _avatarSize = 32 ;
114
145
@@ -151,10 +182,7 @@ class RecentDmConversationsItem extends StatelessWidget {
151
182
return Material (
152
183
color: backgroundColor,
153
184
child: InkWell (
154
- onTap: () {
155
- Navigator .push (context,
156
- MessageListPage .buildRoute (context: context, narrow: narrow));
157
- },
185
+ onTap: () => onDmSelect (narrow),
158
186
child: ConstrainedBox (constraints: const BoxConstraints (minHeight: 48 ),
159
187
child: Row (crossAxisAlignment: CrossAxisAlignment .center, children: [
160
188
Padding (padding: const EdgeInsetsDirectional .fromSTEB (12 , 8 , 0 , 8 ),
@@ -188,7 +216,11 @@ class RecentDmConversationsItem extends StatelessWidget {
188
216
}
189
217
190
218
class _NewDmButton extends StatefulWidget {
191
- const _NewDmButton ();
219
+ const _NewDmButton ({
220
+ required this .onDmSelect,
221
+ });
222
+
223
+ final OnDmSelectCallback onDmSelect;
192
224
193
225
@override
194
226
State <_NewDmButton > createState () => _NewDmButtonState ();
@@ -210,7 +242,7 @@ class _NewDmButtonState extends State<_NewDmButton> {
210
242
: designVariables.fabLabel;
211
243
212
244
return GestureDetector (
213
- onTap: () => showNewDmSheet (context),
245
+ onTap: () => showNewDmSheet (context, widget.onDmSelect ),
214
246
onTapDown: (_) => setState (() => _pressed = true ),
215
247
onTapUp: (_) => setState (() => _pressed = false ),
216
248
onTapCancel: () => setState (() => _pressed = false ),
0 commit comments