@@ -231,6 +231,14 @@ class _TopicItem extends StatelessWidget {
231231 final isTopicVisibleInStream = store.isTopicVisibleInStream (streamId, topic);
232232 final visibilityIcon = iconDataForTopicVisibilityPolicy (
233233 store.topicVisibilityPolicy (streamId, topic));
234+ // The message with `maxId` might not remain in `topic` since we last fetch
235+ // the list of topics. Make sure we check for that before passing `maxId`
236+ // to the topic action sheet.
237+ // See also: [ChannelStore.getStreamTopics]
238+ final message = store.messages[maxId];
239+ final isMaxIdInTopic = message is StreamMessage
240+ && message.streamId == streamId
241+ && message.topic.isSameAs (topic);
234242
235243 final trailingWidgets = [
236244 if (hasMention) const _IconMarker (icon: ZulipIcons .at_sign),
@@ -249,7 +257,7 @@ class _TopicItem extends StatelessWidget {
249257 onLongPress: () => showTopicActionSheet (context,
250258 channelId: streamId,
251259 topic: topic,
252- someMessageIdInTopic: maxId),
260+ someMessageIdInTopic: isMaxIdInTopic ? maxId : null ),
253261 splashFactory: NoSplash .splashFactory,
254262 child: Padding (padding: EdgeInsetsDirectional .fromSTEB (28 , 8 , 12 , 8 ),
255263 child: Row (
0 commit comments