Skip to content

Commit 0f44e10

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

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
@@ -172,19 +172,21 @@ void main() {
172172
}) async {
173173
final effectiveChannel = channel ?? someChannel;
174174
final effectiveMessages = messages ?? [someMessage];
175-
assert(effectiveMessages.every((m) => m.topic.apiName == topic));
175+
final topicName = TopicName(topic);
176+
assert(effectiveMessages.every((m) => m.topic.apiName == topicName.apiName));
176177

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

185186
final topicRow = find.descendant(
186187
of: find.byType(ZulipAppBar),
187-
matching: find.text(topic));
188+
// ignore: dead_null_aware_expression // null topic names soon to be enabled
189+
matching: find.text(topicName.displayName ?? eg.defaultRealmEmptyTopicDisplayName));
188190
await tester.longPress(topicRow);
189191
// sheet appears onscreen; default duration of bottom-sheet enter animation
190192
await tester.pump(const Duration(milliseconds: 250));
@@ -260,6 +262,16 @@ void main() {
260262
check(findButtonForLabel('Mark as unresolved')).findsNothing();
261263
});
262264

265+
testWidgets('show from app bar: resolve/unresolve not offered when topic is empty', (tester) async {
266+
await prepare();
267+
final message = eg.streamMessage(stream: someChannel, topic: '');
268+
await showFromAppBar(tester,
269+
topic: '',
270+
messages: [message]);
271+
check(findButtonForLabel('Mark as resolved')).findsNothing();
272+
check(findButtonForLabel('Mark as unresolved')).findsNothing();
273+
}, skip: true); // null topic names soon to be enabled
274+
263275
testWidgets('show from recipient header', (tester) async {
264276
await prepare();
265277
await showFromRecipientHeader(tester);

0 commit comments

Comments
 (0)