2022-08-29 21:16:13 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:loris/business_logic/timeline/timeline.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:loris/global.dart' as global;
|
|
|
|
|
|
|
|
class MakePostModel {
|
|
|
|
final String identity;
|
|
|
|
final String status;
|
2022-09-02 21:19:25 +00:00
|
|
|
final String spoilerText;
|
2022-08-29 21:16:13 +00:00
|
|
|
final Visibility visibility;
|
|
|
|
final String? scheduledAt;
|
|
|
|
final String? inReplyToId;
|
|
|
|
|
|
|
|
MakePostModel({
|
|
|
|
required this.identity,
|
|
|
|
required this.status,
|
2022-09-02 21:19:25 +00:00
|
|
|
required this.spoilerText,
|
2022-08-29 21:16:13 +00:00
|
|
|
required this.visibility,
|
|
|
|
this.scheduledAt,
|
|
|
|
this.inReplyToId,
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<int> sendPost() async {
|
|
|
|
final headers = global.settings!.identities[identity]!.getAuthHeaders();
|
|
|
|
headers.addAll(global.defaultHeaders);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
"status": status,
|
|
|
|
"sensitive": false,
|
|
|
|
"visibility": visibility.queryParam,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (inReplyToId != null) {
|
|
|
|
params.addAll({
|
|
|
|
"in_reply_to_id": inReplyToId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-09-02 21:19:25 +00:00
|
|
|
if (spoilerText.isNotEmpty) {
|
|
|
|
params.addAll({
|
|
|
|
"spoiler_text": spoilerText,
|
|
|
|
"sensitive": true,
|
|
|
|
});
|
2022-08-29 21:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final url = Uri(
|
|
|
|
scheme: "https",
|
|
|
|
host: global.settings!.identities[identity]!.instanceUrl,
|
|
|
|
path: "/api/v1/statuses",
|
|
|
|
);
|
|
|
|
|
|
|
|
final response = await http.post(
|
|
|
|
url,
|
|
|
|
headers: headers,
|
|
|
|
body: jsonEncode(params),
|
|
|
|
);
|
|
|
|
return response.statusCode;
|
|
|
|
}
|
|
|
|
}
|