commit
f721f30d95
10 changed files with 80 additions and 26 deletions
10
src/BirdsiteLive.ActivityPub/Models/ActivityRejectFollow.cs
Normal file
10
src/BirdsiteLive.ActivityPub/Models/ActivityRejectFollow.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace BirdsiteLive.ActivityPub
|
||||
{
|
||||
public class ActivityRejectFollow : Activity
|
||||
{
|
||||
[JsonProperty("object")]
|
||||
public ActivityFollow apObject { get; set; }
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ namespace BirdsiteLive.ActivityPub
|
|||
public string name { get; set; }
|
||||
public string summary { get; set; }
|
||||
public string url { get; set; }
|
||||
public bool manuallyApprovesFollowers { get; set; }
|
||||
public string inbox { get; set; }
|
||||
public bool? discoverable { get; set; } = true;
|
||||
public PublicKey publicKey { get; set; }
|
||||
|
|
|
@ -12,6 +12,7 @@ using BirdsiteLive.Cryptography;
|
|||
using BirdsiteLive.Domain.BusinessUseCases;
|
||||
using BirdsiteLive.Domain.Statistics;
|
||||
using BirdsiteLive.Domain.Tools;
|
||||
using BirdsiteLive.Twitter;
|
||||
using BirdsiteLive.Twitter.Models;
|
||||
using Tweetinvi.Core.Exceptions;
|
||||
using Tweetinvi.Models;
|
||||
|
@ -36,8 +37,10 @@ namespace BirdsiteLive.Domain
|
|||
private readonly IStatusExtractor _statusExtractor;
|
||||
private readonly IExtractionStatisticsHandler _statisticsHandler;
|
||||
|
||||
private readonly ITwitterUserService _twitterUserService;
|
||||
|
||||
#region Ctor
|
||||
public UserService(InstanceSettings instanceSettings, ICryptoService cryptoService, IActivityPubService activityPubService, IProcessFollowUser processFollowUser, IProcessUndoFollowUser processUndoFollowUser, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler)
|
||||
public UserService(InstanceSettings instanceSettings, ICryptoService cryptoService, IActivityPubService activityPubService, IProcessFollowUser processFollowUser, IProcessUndoFollowUser processUndoFollowUser, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, ITwitterUserService twitterUserService)
|
||||
{
|
||||
_instanceSettings = instanceSettings;
|
||||
_cryptoService = cryptoService;
|
||||
|
@ -46,7 +49,7 @@ namespace BirdsiteLive.Domain
|
|||
_processUndoFollowUser = processUndoFollowUser;
|
||||
_statusExtractor = statusExtractor;
|
||||
_statisticsHandler = statisticsHandler;
|
||||
//_host = $"https://{instanceSettings.Domain.Replace("https://",string.Empty).Replace("http://", string.Empty).TrimEnd('/')}";
|
||||
_twitterUserService = twitterUserService;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -75,6 +78,7 @@ namespace BirdsiteLive.Domain
|
|||
inbox = $"{actorUrl}/inbox",
|
||||
summary = description,
|
||||
url = actorUrl,
|
||||
manuallyApprovesFollowers = twitterUser.Protected,
|
||||
publicKey = new PublicKey()
|
||||
{
|
||||
id = $"{actorUrl}#main-key",
|
||||
|
@ -125,26 +129,50 @@ namespace BirdsiteLive.Domain
|
|||
followerInbox = OnlyKeepRoute(followerInbox, followerHost);
|
||||
followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost);
|
||||
|
||||
// Execute
|
||||
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);
|
||||
|
||||
// Send Accept Activity
|
||||
var acceptFollow = new ActivityAcceptFollow()
|
||||
var user = _twitterUserService.GetUser(twitterUser);
|
||||
if (!user.Protected)
|
||||
{
|
||||
context = "https://www.w3.org/ns/activitystreams",
|
||||
id = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}",
|
||||
type = "Accept",
|
||||
actor = activity.apObject,
|
||||
apObject = new ActivityFollow()
|
||||
// Execute
|
||||
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);
|
||||
|
||||
// Send Accept Activity
|
||||
var acceptFollow = new ActivityAcceptFollow()
|
||||
{
|
||||
id = activity.id,
|
||||
type = activity.type,
|
||||
actor = activity.actor,
|
||||
apObject = activity.apObject
|
||||
}
|
||||
};
|
||||
var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);
|
||||
return result == HttpStatusCode.Accepted || result == HttpStatusCode.OK; //TODO: revamp this for better error handling
|
||||
context = "https://www.w3.org/ns/activitystreams",
|
||||
id = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}",
|
||||
type = "Accept",
|
||||
actor = activity.apObject,
|
||||
apObject = new ActivityFollow()
|
||||
{
|
||||
id = activity.id,
|
||||
type = activity.type,
|
||||
actor = activity.actor,
|
||||
apObject = activity.apObject
|
||||
}
|
||||
};
|
||||
var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);
|
||||
return result == HttpStatusCode.Accepted || result == HttpStatusCode.OK; //TODO: revamp this for better error handling
|
||||
}
|
||||
else
|
||||
{
|
||||
// Send Reject Activity
|
||||
var acceptFollow = new ActivityRejectFollow()
|
||||
{
|
||||
context = "https://www.w3.org/ns/activitystreams",
|
||||
id = $"{activity.apObject}#rejects/follows/{Guid.NewGuid()}",
|
||||
type = "Reject",
|
||||
actor = activity.apObject,
|
||||
apObject = new ActivityFollow()
|
||||
{
|
||||
id = activity.id,
|
||||
type = activity.type,
|
||||
actor = activity.actor,
|
||||
apObject = activity.apObject
|
||||
}
|
||||
};
|
||||
var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);
|
||||
return result == HttpStatusCode.Accepted || result == HttpStatusCode.OK; //TODO: revamp this for better error handling
|
||||
}
|
||||
}
|
||||
|
||||
private string OnlyKeepRoute(string inbox, string host)
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
public string ProfileBackgroundImageUrl { get; set; }
|
||||
public string Acct { get; set; }
|
||||
public string ProfileBannerURL { get; set; }
|
||||
public bool Protected { get; set; }
|
||||
}
|
||||
}
|
|
@ -61,9 +61,9 @@ namespace BirdsiteLive.Twitter
|
|||
TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
|
||||
|
||||
var user = _twitterUserService.GetUser(username);
|
||||
if (user.Protected) return new ExtractedTweet[0];
|
||||
|
||||
var tweets = new List<ITweet>();
|
||||
|
||||
try
|
||||
{
|
||||
if (fromTweetId == -1)
|
||||
|
|
|
@ -60,7 +60,8 @@ namespace BirdsiteLive.Twitter
|
|||
Url = $"https://twitter.com/{username}",
|
||||
ProfileImageUrl = user.ProfileImageUrlFullSize,
|
||||
ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps,
|
||||
ProfileBannerURL = user.ProfileBannerURL
|
||||
ProfileBannerURL = user.ProfileBannerURL,
|
||||
Protected = user.Protected
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<Version>0.11.2</Version>
|
||||
<Version>0.12.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -79,6 +79,7 @@ namespace BirdsiteLive.Controllers
|
|||
Acct = user.Acct.ToLowerInvariant(),
|
||||
Url = user.Url,
|
||||
ProfileImageUrl = user.ProfileImageUrl,
|
||||
Protected = user.Protected,
|
||||
|
||||
InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
|
||||
};
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
public string Acct { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string ProfileImageUrl { get; set; }
|
||||
public bool Protected { get; set; }
|
||||
|
||||
public string InstanceHandle { get; set; }
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
@*<h2>@@@ViewData.Model.Acct</h2>*@
|
||||
|
||||
|
||||
<div class="description">
|
||||
@ViewData.Model.Description
|
||||
</div>
|
||||
|
@ -31,7 +30,19 @@
|
|||
</a>
|
||||
<br />
|
||||
<br />
|
||||
<p>Search this handle to find it in your instance:</p>
|
||||
|
||||
<input type="text" name="textbox" value="@ViewData.Model.InstanceHandle" onclick="this.select()" class="form-control" readonly/>
|
||||
@if (ViewData.Model.Protected)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
This account is protected, BirdsiteLIVE cannot fetch their tweets and will not provide follow support until it is unprotected again.
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div>
|
||||
<p>Search this handle to find it in your instance:</p>
|
||||
|
||||
<input type="text" name="textbox" value="@ViewData.Model.InstanceHandle" onclick="this.select()" class="form-control" readonly />
|
||||
</div>
|
||||
}
|
||||
</div>
|
Reference in a new issue