import 'dart:io'; import 'package:http/http.dart' as http; import '../nextcloud_ocs.dart'; import 'search_chat_messages_response.dart'; /// Wraps Talk's `talk-message-current` search provider, which searches the /// whole server-side history of one conversation. The conversation is picked /// via `from`, the route the provider would be opened from in the web UI. class SearchChatMessages { Future run({ required String chatToken, required String term, int limit = 25, Object? cursor, }) async { final endpoint = NextcloudOcs.uri( 'search/providers/talk-message-current/search', queryParameters: { 'term': term, 'from': '/call/$chatToken', 'limit': limit.toString(), if (cursor != null) 'cursor': cursor.toString(), }, ); final response = await http.get(endpoint, headers: NextcloudOcs.headers()); if (response.statusCode != HttpStatus.ok) { throw Exception( 'Chat search failed with ${response.statusCode}: ${response.body}', ); } final data = NextcloudOcs.decode(response.body)['data'] as Map; return SearchChatMessagesResponse.fromJson(data, term: term); } }