···
import 'package:flutter/foundation.dart';
import '../config/oauth_config.dart';
5
+
import '../models/comment.dart';
import '../models/post.dart';
import 'api_exceptions.dart';
···
/// rotates tokens automatically (~1 hour expiry), and caching tokens would
/// cause 401 errors after the first token expires.
18
-
CovesApiService({Future<String?> Function()? tokenGetter})
19
-
: _tokenGetter = tokenGetter {
22
-
baseUrl: OAuthConfig.apiUrl,
23
-
connectTimeout: const Duration(seconds: 30),
24
-
receiveTimeout: const Duration(seconds: 30),
25
-
headers: {'Content-Type': 'application/json'},
20
+
Future<String?> Function()? tokenGetter,
22
+
}) : _tokenGetter = tokenGetter {
26
+
baseUrl: OAuthConfig.apiUrl,
27
+
connectTimeout: const Duration(seconds: 30),
28
+
receiveTimeout: const Duration(seconds: 30),
29
+
headers: {'Content-Type': 'application/json'},
// Add auth interceptor FIRST to add bearer token
···
return TimelineResponse.fromJson(response.data as Map<String, dynamic>);
} on DioException catch (e) {
_handleDioException(e, 'discover feed');
184
+
/// Get comments for a post (authenticated)
186
+
/// Fetches threaded comments for a specific post.
187
+
/// Requires authentication.
190
+
/// - [postUri]: Post URI (required)
191
+
/// - [sort]: 'hot', 'top', or 'new' (default: 'hot')
192
+
/// - [timeframe]: 'hour', 'day', 'week', 'month', 'year', 'all'
193
+
/// - [depth]: Maximum nesting depth for replies (default: 10)
194
+
/// - [limit]: Number of comments per page (default: 50, max: 100)
195
+
/// - [cursor]: Pagination cursor from previous response
196
+
Future<CommentsResponse> getComments({
197
+
required String postUri,
198
+
String sort = 'hot',
206
+
debugPrint('📡 Fetching comments: postUri=$postUri, sort=$sort');
209
+
final queryParams = <String, dynamic>{
216
+
if (timeframe != null) {
217
+
queryParams['timeframe'] = timeframe;
220
+
if (cursor != null) {
221
+
queryParams['cursor'] = cursor;
224
+
final response = await _dio.get(
225
+
'/xrpc/social.coves.community.comment.getComments',
226
+
queryParameters: queryParams,
231
+
'✅ Comments fetched: '
232
+
'${response.data['comments']?.length ?? 0} comments',
236
+
return CommentsResponse.fromJson(response.data as Map<String, dynamic>);
237
+
} on DioException catch (e) {
238
+
_handleDioException(e, 'comments');