import '../../../core/api_gateway.dart'; import 'chat_sessions.dart'; /// The rows the chat list draws, top to bottom: the [query]'s matches in /// Starred, then Chats by directory, then Closed, leaving out every section /// [isOpen] reports folded. Ctrl+1…Ctrl+9 and Next chat both count these. List chatSessionsShown( List sessions, { required String query, required bool Function(String title) isOpen, }) => chatSessionsInListOrder( chatSessionSections(filterChatSessions(sessions, query)), isOpen: isOpen, ); /// The row after [currentId] in [shown], wrapping from the last row to the /// first. A chat not among [shown] (its section is folded) moves to the /// first row. Null when no other row is shown, so there is nothing to move to. JsonMap? chatSessionAfter(List shown, String currentId) { final index = shown.indexWhere((row) => '${row['id'] ?? ''}' == currentId); final others = index < 0 ? shown.length : shown.length - 1; if (others < 1) return null; return shown[(index + 1) % shown.length]; }