45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:loris/business_logic/timeline/timeline.dart';
|
|
import 'package:loris/global.dart' as global;
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class PostContext {
|
|
final List<PostModel> ancestors;
|
|
final List<PostModel> descendants;
|
|
|
|
PostContext({required this.ancestors, required this.descendants});
|
|
}
|
|
|
|
// first returns ancestors, then decendants
|
|
Future<MapEntry<int, PostContext?>> getContextForPost(PostModel model) async {
|
|
final identity = global.settings!.identities[model.identity]!;
|
|
var headers = identity.getAuthHeaders();
|
|
headers.addAll(global.defaultHeaders);
|
|
String id = model.reblogId ?? model.id;
|
|
final uri = Uri(
|
|
scheme: "https",
|
|
host: identity.instanceUrl,
|
|
path: "/api/v1/statuses/$id/context");
|
|
|
|
final r = await http.get(uri, headers: headers);
|
|
if (r.statusCode != 200) {
|
|
return MapEntry(r.statusCode, null);
|
|
}
|
|
|
|
final json = jsonDecode(r.body);
|
|
List<dynamic> ancestors = json["ancestors"]!;
|
|
List<dynamic> descendants = json["descendants"]!;
|
|
|
|
return MapEntry(
|
|
r.statusCode,
|
|
PostContext(
|
|
ancestors: ancestors
|
|
.map((e) => PostModel.fromJson(e, model.identity))
|
|
.toList(),
|
|
descendants: descendants
|
|
.map((e) => PostModel.fromJson(e, model.identity))
|
|
.toList(),
|
|
));
|
|
}
|