Skip to content

Commit d71bba2

Browse files
committed
action_sheet: Hide resolve/unresolve button for empty topic
Signed-off-by: Zixuan James Li <[email protected]>
1 parent a9566bf commit d71bba2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/widgets/action_sheet.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,13 @@ void showTopicActionSheet(BuildContext context, {
249249
pageContext: pageContext);
250250
}));
251251

252-
if (someMessageIdInTopic != null) {
252+
final message = store.messages[someMessageIdInTopic] as StreamMessage?;
253+
// TODO: check for other cases that may disallow this action (e.g.: time
254+
// limit for editing topics).
255+
final allowResolveUnresolve =
256+
// ignore: unnecessary_null_comparison // null topic names soon to be enabled
257+
message == null || message.topic.displayName != null;
258+
if (someMessageIdInTopic != null && allowResolveUnresolve) {
253259
optionButtons.add(ResolveUnresolveButton(pageContext: pageContext,
254260
topic: topic,
255261
someMessageIdInTopic: someMessageIdInTopic));

test/widgets/action_sheet_test.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,21 @@ void main() {
177177
}) async {
178178
final effectiveChannel = channel ?? someChannel;
179179
final effectiveMessages = messages ?? [someMessage];
180-
assert(effectiveMessages.every((m) => m.topic.apiName == topic));
180+
final topicName = TopicName(topic);
181+
assert(effectiveMessages.every((m) => m.topic.apiName == topicName.apiName));
181182

182183
connection.prepare(json: eg.newestGetMessagesResult(
183184
foundOldest: true, messages: effectiveMessages).toJson());
184185
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
185186
child: MessageListPage(
186-
initNarrow: eg.topicNarrow(effectiveChannel.streamId, topic))));
187+
initNarrow: eg.topicNarrow(effectiveChannel.streamId, topicName.apiName))));
187188
// global store, per-account store, and message list get loaded
188189
await tester.pumpAndSettle();
189190

190191
final topicRow = find.descendant(
191192
of: find.byType(ZulipAppBar),
192-
matching: find.text(topic));
193+
// ignore: dead_null_aware_expression // null topic names soon to be enabled
194+
matching: find.text(topicName.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
193195
await tester.longPress(topicRow);
194196
// sheet appears onscreen; default duration of bottom-sheet enter animation
195197
await tester.pump(const Duration(milliseconds: 250));
@@ -265,6 +267,16 @@ void main() {
265267
check(findButtonForLabel('Mark as unresolved')).findsNothing();
266268
});
267269

270+
testWidgets('show from app bar: resolve/unresolve not offered when topic is empty', (tester) async {
271+
await prepare();
272+
final message = eg.streamMessage(stream: someChannel, topic: '');
273+
await showFromAppBar(tester,
274+
topic: '',
275+
messages: [message]);
276+
check(findButtonForLabel('Mark as resolved')).findsNothing();
277+
check(findButtonForLabel('Mark as unresolved')).findsNothing();
278+
}, skip: true); // null topic names soon to be enabled
279+
268280
testWidgets('show from recipient header', (tester) async {
269281
await prepare();
270282
await showFromRecipientHeader(tester);

0 commit comments

Comments
 (0)