@@ -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,28 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
55
63
});
56
64
}
57
65
66
+ void _handleDmSelect (DmNarrow narrow) {
67
+ if (widget.onDmSelect case final onDmSelect? ) {
68
+ onDmSelect (narrow);
69
+ } else {
70
+ Navigator .push (context,
71
+ MessageListPage .buildRoute (context: context,
72
+ narrow: narrow));
73
+ }
74
+ }
75
+
76
+ void _handleDmSelectForNewDms (DmNarrow narrow) {
77
+ if (widget.onDmSelect case final onDmSelect? ) {
78
+ // Pop the new-DMs action sheet.
79
+ Navigator .pop (context);
80
+ onDmSelect (narrow);
81
+ } else {
82
+ Navigator .pushReplacement (context,
83
+ MessageListPage .buildRoute (context: context,
84
+ narrow: narrow));
85
+ }
86
+ }
87
+
58
88
@override
59
89
Widget build (BuildContext context) {
60
90
final store = PerAccountStoreWidget .of (context);
@@ -92,11 +122,12 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
92
122
}
93
123
return RecentDmConversationsItem (
94
124
narrow: narrow,
95
- unreadCount: unreadsModel! .countInDmNarrow (narrow));
125
+ unreadCount: unreadsModel! .countInDmNarrow (narrow),
126
+ onDmSelect: _handleDmSelect);
96
127
})),
97
128
Positioned (
98
129
bottom: 21 ,
99
- child: _NewDmButton ()),
130
+ child: _NewDmButton (onDmSelect : _handleDmSelectForNewDms )),
100
131
]);
101
132
}
102
133
}
@@ -106,10 +137,12 @@ class RecentDmConversationsItem extends StatelessWidget {
106
137
super .key,
107
138
required this .narrow,
108
139
required this .unreadCount,
140
+ required this .onDmSelect,
109
141
});
110
142
111
143
final DmNarrow narrow;
112
144
final int unreadCount;
145
+ final OnDmSelectCallback onDmSelect;
113
146
114
147
static const double _avatarSize = 32 ;
115
148
@@ -152,10 +185,7 @@ class RecentDmConversationsItem extends StatelessWidget {
152
185
return Material (
153
186
color: backgroundColor,
154
187
child: InkWell (
155
- onTap: () {
156
- Navigator .push (context,
157
- MessageListPage .buildRoute (context: context, narrow: narrow));
158
- },
188
+ onTap: () => onDmSelect (narrow),
159
189
child: ConstrainedBox (constraints: const BoxConstraints (minHeight: 48 ),
160
190
child: Row (crossAxisAlignment: CrossAxisAlignment .center, children: [
161
191
Padding (padding: const EdgeInsetsDirectional .fromSTEB (12 , 8 , 0 , 8 ),
@@ -189,7 +219,11 @@ class RecentDmConversationsItem extends StatelessWidget {
189
219
}
190
220
191
221
class _NewDmButton extends StatefulWidget {
192
- const _NewDmButton ();
222
+ const _NewDmButton ({
223
+ required this .onDmSelect,
224
+ });
225
+
226
+ final OnDmSelectCallback onDmSelect;
193
227
194
228
@override
195
229
State <_NewDmButton > createState () => _NewDmButtonState ();
@@ -211,7 +245,7 @@ class _NewDmButtonState extends State<_NewDmButton> {
211
245
: designVariables.fabLabel;
212
246
213
247
return GestureDetector (
214
- onTap: () => showNewDmSheet (context),
248
+ onTap: () => showNewDmSheet (context, widget.onDmSelect ),
215
249
onTapDown: (_) => setState (() => _pressed = true ),
216
250
onTapUp: (_) => setState (() => _pressed = false ),
217
251
onTapCancel: () => setState (() => _pressed = false ),
0 commit comments