Skip to content

Commit

Permalink
Merge pull request #37 from NicolasConstant/topic_debug-pleroma
Browse files Browse the repository at this point in the history
Fixed case issue in ID/user
  • Loading branch information
NicolasConstant authored Jan 10, 2021
2 parents 9527faa + 6aef12e commit b8b2e10
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 35 deletions.
17 changes: 17 additions & 0 deletions src/BirdsiteLive.ActivityPub/Converters/UrlFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Runtime.CompilerServices;

namespace BirdsiteLive.ActivityPub.Converters
{
public class UrlFactory
{
public static string GetActorUrl(string domain, string username)
{
return $"https://{domain.ToLowerInvariant()}/users/{username.ToLowerInvariant()}";
}

public static string GetNoteUrl(string domain, string username, string noteId)
{
return $"https://{domain.ToLowerInvariant()}/users/{username.ToLowerInvariant()}/statuses/{noteId}";
}
}
}
15 changes: 3 additions & 12 deletions src/BirdsiteLive.Domain/ActivityPubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.ActivityPub.Models;
using BirdsiteLive.Common.Settings;
using Newtonsoft.Json;
Expand Down Expand Up @@ -47,18 +48,8 @@ public async Task<Actor> GetUser(string objectId)

public async Task<HttpStatusCode> PostNewNoteActivity(Note note, string username, string noteId, string targetHost, string targetInbox)
{
//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 noteUri = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{noteId}";

//var noteUrl = $"https://{_instanceSettings.Domain}/@{username}/{noteId}";
//var to = $"{actor}/followers";
//var apPublic = "https://www.w3.org/ns/activitystreams#Public";
var actor = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
var noteUri = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, noteId);

var now = DateTime.UtcNow;
var nowString = now.ToString("s") + "Z";
Expand Down
12 changes: 5 additions & 7 deletions src/BirdsiteLive.Domain/StatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text.RegularExpressions;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.ActivityPub.Models;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Domain.Tools;
Expand Down Expand Up @@ -33,9 +34,8 @@ public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusE

public Note GetStatus(string username, ExtractedTweet tweet)
{
var actorUrl = $"https://{_instanceSettings.Domain}/users/{username}";
var noteId = $"https://{_instanceSettings.Domain}/users/{username}/statuses/{tweet.Id}";
var noteUrl = $"https://{_instanceSettings.Domain}/@{username}/{tweet.Id}";
var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, username);
var noteUrl = UrlFactory.GetNoteUrl(_instanceSettings.Domain, username, tweet.Id.ToString());

var to = $"{actorUrl}/followers";
var apPublic = "https://www.w3.org/ns/activitystreams#Public";
Expand All @@ -44,12 +44,11 @@ public Note GetStatus(string username, ExtractedTweet tweet)

string inReplyTo = null;
if (tweet.InReplyToStatusId != default)
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount}/statuses/{tweet.InReplyToStatusId}";
inReplyTo = $"https://{_instanceSettings.Domain}/users/{tweet.InReplyToAccount.ToLowerInvariant()}/statuses/{tweet.InReplyToStatusId}";

var note = new Note
{
//id = $"{noteId}/activity",
id = $"{noteId}",
id = noteUrl,

published = tweet.CreatedAt.ToString("s") + "Z",
url = noteUrl,
Expand All @@ -68,7 +67,6 @@ public Note GetStatus(string username, ExtractedTweet tweet)
attachment = Convert(tweet.Media),
tag = extractedTags.tags
};


return note;
}
Expand Down
22 changes: 13 additions & 9 deletions src/BirdsiteLive.Domain/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Cryptography;
using BirdsiteLive.Domain.BusinessUseCases;
Expand Down Expand Up @@ -45,21 +46,24 @@ public UserService(InstanceSettings instanceSettings, ICryptoService cryptoServi

public Actor GetUser(TwitterUser twitterUser)
{
var actorUrl = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct);
var acct = twitterUser.Acct.ToLowerInvariant();

var user = new Actor
{
id = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}",
type = "Service", //Person Service
followers = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/followers",
preferredUsername = twitterUser.Acct,
id = actorUrl,
type = "Service",
followers = $"{actorUrl}/followers",
preferredUsername = acct,
name = twitterUser.Name,
inbox = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}/inbox",
inbox = $"{actorUrl}/inbox",
summary = twitterUser.Description,
url = $"https://{_instanceSettings.Domain}/@{twitterUser.Acct}",
url = actorUrl,
publicKey = new PublicKey()
{
id = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}#main-key",
owner = $"https://{_instanceSettings.Domain}/users/{twitterUser.Acct}",
publicKeyPem = _cryptoService.GetUserPem(twitterUser.Acct)
id = $"{actorUrl}#main-key",
owner = actorUrl,
publicKeyPem = _cryptoService.GetUserPem(acct)
},
icon = new Image
{
Expand Down
6 changes: 3 additions & 3 deletions src/BirdsiteLive/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IActionResult Index()
[Route("/users/{id}")]
public IActionResult Index(string id)
{
id = id.Trim(new[] {' ', '@'});
id = id.Trim(new[] {' ', '@'}).ToLowerInvariant();
var user = _twitterService.GetUser(id);

var r = Request.Headers["Accept"].First();
Expand All @@ -66,11 +66,11 @@ public IActionResult Index(string id)
{
Name = user.Name,
Description = user.Description,
Acct = user.Acct,
Acct = user.Acct.ToLowerInvariant(),
Url = user.Url,
ProfileImageUrl = user.ProfileImageUrl,

InstanceHandle = $"@{user.Acct}@{_instanceSettings.Domain}"
InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
};
return View(displayableUser);
}
Expand Down
13 changes: 9 additions & 4 deletions src/BirdsiteLive/Controllers/WellKnownController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Models;
Expand Down Expand Up @@ -156,34 +157,38 @@ public IActionResult Webfinger(string resource = null)
return BadRequest();
}

// Ensure lowercase
name = name.ToLowerInvariant();

if (!string.IsNullOrWhiteSpace(domain) && domain != _settings.Domain)
return NotFound();

var user = _twitterService.GetUser(name);
if (user == null)
return NotFound();

var actorUrl = UrlFactory.GetActorUrl(_settings.Domain, name);

var result = new WebFingerResult()
{
subject = $"acct:{name}@{_settings.Domain}",
aliases = new[]
{
$"https://{_settings.Domain}/@{name}",
$"https://{_settings.Domain}/users/{name}"
actorUrl
},
links = new List<WebFingerLink>
{
new WebFingerLink()
{
rel = "http://webfinger.net/rel/profile-page",
type = "text/html",
href = $"https://{_settings.Domain}/@{name}"
href = actorUrl
},
new WebFingerLink()
{
rel = "self",
type = "application/activity+json",
href = $"https://{_settings.Domain}/users/{name}"
href = actorUrl
}
}
};
Expand Down

0 comments on commit b8b2e10

Please sign in to comment.