2020-06-28 20:27:03 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BirdsiteLive.ActivityPub;
|
2020-07-31 22:13:52 -04:00
|
|
|
|
using BirdsiteLive.ActivityPub.Models;
|
2020-06-28 20:27:03 -04:00
|
|
|
|
using BirdsiteLive.Common.Settings;
|
|
|
|
|
using BirdsiteLive.Domain;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Controllers
|
|
|
|
|
{
|
2020-07-01 19:25:00 -04:00
|
|
|
|
public class DebugingController : Controller
|
2020-06-28 20:27:03 -04:00
|
|
|
|
{
|
|
|
|
|
private readonly InstanceSettings _instanceSettings;
|
|
|
|
|
private readonly ICryptoService _cryptoService;
|
2020-06-28 23:42:23 -04:00
|
|
|
|
private readonly IActivityPubService _activityPubService;
|
2021-02-11 23:02:06 -05:00
|
|
|
|
private readonly IUserService _userService;
|
2020-06-28 20:27:03 -04:00
|
|
|
|
|
|
|
|
|
#region Ctor
|
2021-02-11 23:02:06 -05:00
|
|
|
|
public DebugingController(InstanceSettings instanceSettings, ICryptoService cryptoService, IActivityPubService activityPubService, IUserService userService)
|
2020-06-28 20:27:03 -04:00
|
|
|
|
{
|
|
|
|
|
_instanceSettings = instanceSettings;
|
|
|
|
|
_cryptoService = cryptoService;
|
2020-06-28 23:42:23 -04:00
|
|
|
|
_activityPubService = activityPubService;
|
2021-02-11 23:02:06 -05:00
|
|
|
|
_userService = userService;
|
2020-06-28 20:27:03 -04:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Follow()
|
|
|
|
|
{
|
|
|
|
|
var actor = $"https://{_instanceSettings.Domain}/users/gra";
|
2020-06-28 23:42:23 -04:00
|
|
|
|
var targethost = "mastodon.technology";
|
2020-06-28 20:27:03 -04:00
|
|
|
|
var followActivity = new ActivityFollow()
|
|
|
|
|
{
|
|
|
|
|
context = "https://www.w3.org/ns/activitystreams",
|
|
|
|
|
id = $"https://{_instanceSettings.Domain}/{Guid.NewGuid()}",
|
|
|
|
|
type = "Follow",
|
|
|
|
|
actor = actor,
|
|
|
|
|
apObject = $"https://{targethost}/users/testtest"
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-28 23:42:23 -04:00
|
|
|
|
await _activityPubService.PostDataAsync(followActivity, targethost, actor);
|
|
|
|
|
|
|
|
|
|
return View("Index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> PostNote()
|
|
|
|
|
{
|
|
|
|
|
var username = "gra";
|
|
|
|
|
var actor = $"https://{_instanceSettings.Domain}/users/{username}";
|
|
|
|
|
var targetHost = "mastodon.technology";
|
|
|
|
|
var target = $"{targetHost}/users/testtest";
|
|
|
|
|
var inbox = $"/users/testtest/inbox";
|
|
|
|
|
|
|
|
|
|
var noteGuid = Guid.NewGuid();
|
|
|
|
|
var noteId = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{noteGuid}";
|
|
|
|
|
var noteUrl = $"https://{_instanceSettings.Domain}/@{username}/{noteGuid}";
|
2020-06-28 20:27:03 -04:00
|
|
|
|
|
2020-06-28 23:42:23 -04:00
|
|
|
|
var to = $"{actor}/followers";
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
var nowString = now.ToString("s") + "Z";
|
2020-06-28 20:27:03 -04:00
|
|
|
|
|
2020-06-28 23:42:23 -04:00
|
|
|
|
var noteActivity = new ActivityCreateNote()
|
2020-06-28 20:27:03 -04:00
|
|
|
|
{
|
2020-06-28 23:42:23 -04:00
|
|
|
|
context = "https://www.w3.org/ns/activitystreams",
|
|
|
|
|
id = $"{noteId}/activity",
|
|
|
|
|
type = "Create",
|
|
|
|
|
actor = actor,
|
|
|
|
|
published = nowString,
|
|
|
|
|
to = new []{ to },
|
2021-02-14 12:28:38 -05:00
|
|
|
|
//cc = new [] { "https://www.w3.org/ns/activitystreams#Public" },
|
2020-06-28 23:42:23 -04:00
|
|
|
|
apObject = new Note()
|
2020-06-28 20:27:03 -04:00
|
|
|
|
{
|
2020-06-28 23:42:23 -04:00
|
|
|
|
id = noteId,
|
|
|
|
|
summary = null,
|
|
|
|
|
inReplyTo = null,
|
|
|
|
|
published = nowString,
|
|
|
|
|
url = noteUrl,
|
|
|
|
|
attributedTo = actor,
|
|
|
|
|
to = new[] { to },
|
2021-02-14 12:28:38 -05:00
|
|
|
|
//cc = new [] { "https://www.w3.org/ns/activitystreams#Public" },
|
2020-06-28 23:42:23 -04:00
|
|
|
|
sensitive = false,
|
|
|
|
|
content = "<p>Woooot</p>",
|
2020-07-22 19:27:25 -04:00
|
|
|
|
attachment = new Attachment[0],
|
2020-07-31 22:52:40 -04:00
|
|
|
|
tag = new Tag[0]
|
2020-06-28 23:42:23 -04:00
|
|
|
|
}
|
2020-06-28 20:27:03 -04:00
|
|
|
|
};
|
|
|
|
|
|
2020-06-28 23:42:23 -04:00
|
|
|
|
await _activityPubService.PostDataAsync(noteActivity, targetHost, actor, inbox);
|
2020-06-28 20:27:03 -04:00
|
|
|
|
|
|
|
|
|
return View("Index");
|
|
|
|
|
}
|
2021-02-11 23:02:06 -05:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> PostRejectFollow()
|
|
|
|
|
{
|
|
|
|
|
var activityFollow = new ActivityFollow
|
|
|
|
|
{
|
|
|
|
|
type = "Follow",
|
|
|
|
|
actor = "https://mastodon.technology/users/testtest",
|
|
|
|
|
apObject = $"https://{_instanceSettings.Domain}/users/afp"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await _userService.SendRejectFollowAsync(activityFollow, "mastodon.technology");
|
|
|
|
|
return View("Index");
|
|
|
|
|
}
|
2020-06-28 20:27:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class HtmlHelperExtensions
|
|
|
|
|
{
|
|
|
|
|
public static bool IsDebug()
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|