added delete action
This commit is contained in:
parent
7658438741
commit
d543a1d4f9
4 changed files with 44 additions and 0 deletions
|
@ -4,6 +4,7 @@ namespace BirdsiteLive.ActivityPub.Models
|
|||
{
|
||||
public class ActivityDelete : Activity
|
||||
{
|
||||
public string[] to { get; set; }
|
||||
[JsonProperty("object")]
|
||||
public object apObject { get; set; }
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace BirdsiteLive.Domain
|
|||
Task<HttpStatusCode> PostDataAsync<T>(T data, string targetHost, string actorUrl, string inbox = null);
|
||||
Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost,
|
||||
string targetInbox);
|
||||
Task DeleteUserAsync(string username, string targetHost, string targetInbox);
|
||||
}
|
||||
|
||||
public class WebFinger
|
||||
|
@ -82,6 +83,31 @@ namespace BirdsiteLive.Domain
|
|||
return actor;
|
||||
}
|
||||
|
||||
public async Task DeleteUserAsync(string username, string targetHost, string targetInbox)
|
||||
{
|
||||
try
|
||||
{
|
||||
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
|
||||
|
||||
var deleteUser = new ActivityDelete
|
||||
{
|
||||
context = "https://www.w3.org/ns/activitystreams",
|
||||
id = $"{actor}#delete",
|
||||
type = "Delete",
|
||||
actor = actor,
|
||||
to = new [] { "https://www.w3.org/ns/activitystreams#Public" },
|
||||
apObject = actor
|
||||
};
|
||||
|
||||
await PostDataAsync(deleteUser, targetHost, actor, targetInbox);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error deleting {Username} to {Host}{Inbox}", username, targetHost, targetInbox);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -125,6 +125,17 @@ namespace BirdsiteLive.Controllers
|
|||
await _userService.SendRejectFollowAsync(activityFollow, "mastodon.technology");
|
||||
return View("Index");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostDeleteUser()
|
||||
{
|
||||
var userName = "mastodon";
|
||||
var host = "ioc.exchange";
|
||||
var inbox = "/inbox";
|
||||
|
||||
await _activityPubService.DeleteUserAsync(userName, host, inbox);
|
||||
return View("Index");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,4 +23,10 @@
|
|||
<!-- Input and Submit elements -->
|
||||
|
||||
<button type="submit" value="Submit">Reject Follow</button>
|
||||
</form>
|
||||
|
||||
<form asp-controller="Debuging" asp-action="PostDeleteUser" method="post">
|
||||
<!-- Input and Submit elements -->
|
||||
|
||||
<button type="submit" value="Submit">Delete User</button>
|
||||
</form>
|
Reference in a new issue