Skip to content

Commit d709da1

Browse files
sm-sayediPIG208
andcommitted
topics: Pass maxId to topic sheet if the related message is still in topic
Co-authored-by: Zixuan James Li <[email protected]>
1 parent 57c4727 commit d709da1

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

lib/widgets/topic_list.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ class _TopicItem extends StatelessWidget {
235235

236236
final store = PerAccountStoreWidget.of(context);
237237
final designVariables = DesignVariables.of(context);
238+
// `maxId` might be incorrect (see [ChannelStore.getChannelTopics]).
239+
// Check if it refers to a message that's currently in the topic;
240+
// if not, we just won't have `someMessageIdInTopic` for the action sheet.
241+
final maxIdMessage = store.messages[maxId];
242+
final someMessageIdInTopic =
243+
(maxIdMessage != null && TopicNarrow(streamId, topic).containsMessage(maxIdMessage))
244+
? maxIdMessage.id
245+
: null;
238246

239247
final visibilityPolicy = store.topicVisibilityPolicy(streamId, topic);
240248
final double opacity;
@@ -263,7 +271,7 @@ class _TopicItem extends StatelessWidget {
263271
onLongPress: () => showTopicActionSheet(context,
264272
channelId: streamId,
265273
topic: topic,
266-
someMessageIdInTopic: maxId),
274+
someMessageIdInTopic: someMessageIdInTopic),
267275
splashFactory: NoSplash.splashFactory,
268276
child: ConstrainedBox(
269277
constraints: BoxConstraints(minHeight: 40),

test/widgets/topic_list_test.dart

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ void main() {
169169
of: topicItemFinder.at(index),
170170
matching: finder);
171171

172+
testWidgets('sort topics by maxId', (tester) async {
173+
await prepare(tester, topics: [
174+
eg.getChannelTopicsEntry(name: 'A', maxId: 3),
175+
eg.getChannelTopicsEntry(name: 'B', maxId: 2),
176+
eg.getChannelTopicsEntry(name: 'C', maxId: 4),
177+
]);
178+
179+
check(findInTopicItemAt(0, find.text('C'))).findsOne();
180+
check(findInTopicItemAt(1, find.text('A'))).findsOne();
181+
check(findInTopicItemAt(2, find.text('B'))).findsOne();
182+
});
183+
172184
testWidgets('show topic action sheet', (tester) async {
173185
final channel = eg.stream();
174186
await prepare(tester, channel: channel,
@@ -190,16 +202,36 @@ void main() {
190202
});
191203
});
192204

193-
testWidgets('sort topics by maxId', (tester) async {
194-
await prepare(tester, topics: [
195-
eg.getChannelTopicsEntry(name: 'A', maxId: 3),
196-
eg.getChannelTopicsEntry(name: 'B', maxId: 2),
197-
eg.getChannelTopicsEntry(name: 'C', maxId: 4),
198-
]);
205+
testWidgets('topic action sheet before and after moves', (tester) async {
206+
final channel = eg.stream();
207+
final message = eg.streamMessage(id: 100, stream: channel, topic: 'foo');
208+
await prepare(tester, channel: channel,
209+
topics: [eg.getChannelTopicsEntry(name: 'foo', maxId: 100)],
210+
messages: [message]);
211+
check(topicItemFinder).findsOne();
199212

200-
check(findInTopicItemAt(0, find.text('C'))).findsOne();
201-
check(findInTopicItemAt(1, find.text('A'))).findsOne();
202-
check(findInTopicItemAt(2, find.text('B'))).findsOne();
213+
// Before the move, "foo"'s maxId is known to be accurate. This makes
214+
// topic actions that require `someMessageIdInTopic` available.
215+
await tester.longPress(find.text('foo'));
216+
await tester.pump(Duration(milliseconds: 150)); // bottom-sheet animation
217+
check(find.text('Mark as resolved')).findsOne();
218+
await tester.tap(find.text('Cancel'));
219+
220+
await store.handleEvent(eg.updateMessageEventMoveFrom(
221+
origMessages: [message],
222+
newTopicStr: 'bar'));
223+
await tester.pump();
224+
// There's still one topic item ("foo") even though the new message is in
225+
// topic "bar", but the topic list doesn't get updated.
226+
check(topicItemFinder).findsOne();
227+
228+
// After the move, the message with maxId moved away from "foo". The topic
229+
// actions that require `someMessageIdInTopic` are no longer available.
230+
await tester.longPress(find.text('foo'));
231+
await tester.pump(Duration(milliseconds: 150)); // bottom-sheet animation
232+
check(find.text('Mark as resolved')).findsNothing();
233+
await tester.tap(find.text('Cancel'));
234+
await tester.pump();
203235
});
204236

205237
testWidgets('resolved and unresolved topics', (tester) async {

0 commit comments

Comments
 (0)