add post deletion
This commit is contained in:
parent
6c1e8fca85
commit
eff72ee74e
|
@ -103,3 +103,21 @@ Future<int> makeFullInteraction(
|
||||||
}
|
}
|
||||||
return await makeInteractionFromUrl(id, posturl, type);
|
return await makeInteractionFromUrl(id, posturl, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> deletePost(PostModel model) async {
|
||||||
|
final identity = global.settings!.identities[model.identity]!;
|
||||||
|
final headers = {
|
||||||
|
...identity.getAuthHeaders(),
|
||||||
|
...global.defaultHeaders,
|
||||||
|
};
|
||||||
|
|
||||||
|
final uri = Uri(
|
||||||
|
scheme: "https",
|
||||||
|
host: identity.instanceUrl,
|
||||||
|
path: "/api/v1/statuses/${model.id}",
|
||||||
|
);
|
||||||
|
|
||||||
|
final response = await http.delete(uri, headers: headers);
|
||||||
|
|
||||||
|
return response.statusCode;
|
||||||
|
}
|
||||||
|
|
|
@ -89,6 +89,9 @@
|
||||||
"unread": "unread",
|
"unread": "unread",
|
||||||
"expand": "expand",
|
"expand": "expand",
|
||||||
"requested-to-follow": "has requested to follow:",
|
"requested-to-follow": "has requested to follow:",
|
||||||
"follow-requests": "follow requests"
|
"follow-requests": "follow requests",
|
||||||
|
"post-deleted": "post deleted",
|
||||||
|
"delete-this": "delete this",
|
||||||
|
"deletion-failed": "deletion failed"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:loris/dialogues/full_post_view.dart';
|
||||||
import 'package:loris/partials/interaction_button.dart';
|
import 'package:loris/partials/interaction_button.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:clipboard/clipboard.dart';
|
import 'package:clipboard/clipboard.dart';
|
||||||
|
import 'package:loris/global.dart' as global;
|
||||||
|
|
||||||
void popupPostOptions(context, PostModel model) {
|
void popupPostOptions(context, PostModel model) {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
|
@ -93,6 +94,7 @@ class _PostOptionsState extends State<PostOptions> {
|
||||||
"show-in-browser".i18n(),
|
"show-in-browser".i18n(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
widget.model.visibility.boostable
|
widget.model.visibility.boostable
|
||||||
? InteractionButton(
|
? InteractionButton(
|
||||||
model: widget.model,
|
model: widget.model,
|
||||||
|
@ -105,6 +107,24 @@ class _PostOptionsState extends State<PostOptions> {
|
||||||
type: InteractionType.favorite,
|
type: InteractionType.favorite,
|
||||||
extended: true,
|
extended: true,
|
||||||
),
|
),
|
||||||
|
if ("${widget.model.account.acct}@${global.settings!.identities[widget.model.identity]!.instanceUrl}" ==
|
||||||
|
widget.model.identity)
|
||||||
|
TextButton.icon(
|
||||||
|
onPressed: () async {
|
||||||
|
final result = await deletePost(widget.model);
|
||||||
|
if (result == 200) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("post-deleted".i18n())));
|
||||||
|
}
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("deletion-failed".i18n())));
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
label: Text("delete-this".i18n())),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 24,
|
height: 24,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue