@@ -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);
@@ -91,11 +121,12 @@ class _RecentDmConversationsPageBodyState extends State<RecentDmConversationsPag
91
121
}
92
122
return RecentDmConversationsItem (
93
123
narrow: narrow,
94
- unreadCount: unreadsModel! .countInDmNarrow (narrow));
124
+ unreadCount: unreadsModel! .countInDmNarrow (narrow),
125
+ onDmSelect: _handleDmSelect);
95
126
})),
96
127
Positioned (
97
128
bottom: 21 ,
98
- child: _NewDmButton ()),
129
+ child: _NewDmButton (onDmSelect : _handleDmSelectForNewDms )),
99
130
]);
100
131
}
101
132
}
@@ -105,10 +136,12 @@ class RecentDmConversationsItem extends StatelessWidget {
105
136
super .key,
106
137
required this .narrow,
107
138
required this .unreadCount,
139
+ required this .onDmSelect,
108
140
});
109
141
110
142
final DmNarrow narrow;
111
143
final int unreadCount;
144
+ final OnDmSelectCallback onDmSelect;
112
145
113
146
static const double _avatarSize = 32 ;
114
147
@@ -151,10 +184,7 @@ class RecentDmConversationsItem extends StatelessWidget {
151
184
return Material (
152
185
color: backgroundColor,
153
186
child: InkWell (
154
- onTap: () {
155
- Navigator .push (context,
156
- MessageListPage .buildRoute (context: context, narrow: narrow));
157
- },
187
+ onTap: () => onDmSelect (narrow),
158
188
child: ConstrainedBox (constraints: const BoxConstraints (minHeight: 48 ),
159
189
child: Row (crossAxisAlignment: CrossAxisAlignment .center, children: [
160
190
Padding (padding: const EdgeInsetsDirectional .fromSTEB (12 , 8 , 0 , 8 ),
@@ -188,7 +218,11 @@ class RecentDmConversationsItem extends StatelessWidget {
188
218
}
189
219
190
220
class _NewDmButton extends StatefulWidget {
191
- const _NewDmButton ();
221
+ const _NewDmButton ({
222
+ required this .onDmSelect,
223
+ });
224
+
225
+ final OnDmSelectCallback onDmSelect;
192
226
193
227
@override
194
228
State <_NewDmButton > createState () => _NewDmButtonState ();
@@ -210,7 +244,7 @@ class _NewDmButtonState extends State<_NewDmButton> {
210
244
: designVariables.fabLabel;
211
245
212
246
return GestureDetector (
213
- onTap: () => showNewDmSheet (context),
247
+ onTap: () => showNewDmSheet (context, widget.onDmSelect ),
214
248
onTapDown: (_) => setState (() => _pressed = true ),
215
249
onTapUp: (_) => setState (() => _pressed = false ),
216
250
onTapCancel: () => setState (() => _pressed = false ),
0 commit comments