Merge pull request #71 from NicolasConstant/develop

0.12.0 PR
This commit is contained in:
Nicolas Constant 2021-01-29 00:51:26 +01:00 committed by GitHub
commit f721f30d95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 80 additions and 26 deletions

View file

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace BirdsiteLive.ActivityPub
{
public class ActivityRejectFollow : Activity
{
[JsonProperty("object")]
public ActivityFollow apObject { get; set; }
}
}

View file

@ -17,6 +17,7 @@ namespace BirdsiteLive.ActivityPub
public string name { get; set; } public string name { get; set; }
public string summary { get; set; } public string summary { get; set; }
public string url { get; set; } public string url { get; set; }
public bool manuallyApprovesFollowers { get; set; }
public string inbox { get; set; } public string inbox { get; set; }
public bool? discoverable { get; set; } = true; public bool? discoverable { get; set; } = true;
public PublicKey publicKey { get; set; } public PublicKey publicKey { get; set; }

View file

@ -12,6 +12,7 @@ using BirdsiteLive.Cryptography;
using BirdsiteLive.Domain.BusinessUseCases; using BirdsiteLive.Domain.BusinessUseCases;
using BirdsiteLive.Domain.Statistics; using BirdsiteLive.Domain.Statistics;
using BirdsiteLive.Domain.Tools; using BirdsiteLive.Domain.Tools;
using BirdsiteLive.Twitter;
using BirdsiteLive.Twitter.Models; using BirdsiteLive.Twitter.Models;
using Tweetinvi.Core.Exceptions; using Tweetinvi.Core.Exceptions;
using Tweetinvi.Models; using Tweetinvi.Models;
@ -36,8 +37,10 @@ namespace BirdsiteLive.Domain
private readonly IStatusExtractor _statusExtractor; private readonly IStatusExtractor _statusExtractor;
private readonly IExtractionStatisticsHandler _statisticsHandler; private readonly IExtractionStatisticsHandler _statisticsHandler;
private readonly ITwitterUserService _twitterUserService;
#region Ctor #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; _instanceSettings = instanceSettings;
_cryptoService = cryptoService; _cryptoService = cryptoService;
@ -46,7 +49,7 @@ namespace BirdsiteLive.Domain
_processUndoFollowUser = processUndoFollowUser; _processUndoFollowUser = processUndoFollowUser;
_statusExtractor = statusExtractor; _statusExtractor = statusExtractor;
_statisticsHandler = statisticsHandler; _statisticsHandler = statisticsHandler;
//_host = $"https://{instanceSettings.Domain.Replace("https://",string.Empty).Replace("http://", string.Empty).TrimEnd('/')}"; _twitterUserService = twitterUserService;
} }
#endregion #endregion
@ -75,6 +78,7 @@ namespace BirdsiteLive.Domain
inbox = $"{actorUrl}/inbox", inbox = $"{actorUrl}/inbox",
summary = description, summary = description,
url = actorUrl, url = actorUrl,
manuallyApprovesFollowers = twitterUser.Protected,
publicKey = new PublicKey() publicKey = new PublicKey()
{ {
id = $"{actorUrl}#main-key", id = $"{actorUrl}#main-key",
@ -125,26 +129,50 @@ namespace BirdsiteLive.Domain
followerInbox = OnlyKeepRoute(followerInbox, followerHost); followerInbox = OnlyKeepRoute(followerInbox, followerHost);
followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost); followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost);
// Execute var user = _twitterUserService.GetUser(twitterUser);
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox); if (!user.Protected)
// Send Accept Activity
var acceptFollow = new ActivityAcceptFollow()
{ {
context = "https://www.w3.org/ns/activitystreams", // Execute
id = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}", await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);
type = "Accept",
actor = activity.apObject, // Send Accept Activity
apObject = new ActivityFollow() var acceptFollow = new ActivityAcceptFollow()
{ {
id = activity.id, context = "https://www.w3.org/ns/activitystreams",
type = activity.type, id = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}",
actor = activity.actor, type = "Accept",
apObject = activity.apObject actor = activity.apObject,
} apObject = new ActivityFollow()
}; {
var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject); id = activity.id,
return result == HttpStatusCode.Accepted || result == HttpStatusCode.OK; //TODO: revamp this for better error handling 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) private string OnlyKeepRoute(string inbox, string host)

View file

@ -10,5 +10,6 @@
public string ProfileBackgroundImageUrl { get; set; } public string ProfileBackgroundImageUrl { get; set; }
public string Acct { get; set; } public string Acct { get; set; }
public string ProfileBannerURL { get; set; } public string ProfileBannerURL { get; set; }
public bool Protected { get; set; }
} }
} }

View file

@ -61,9 +61,9 @@ namespace BirdsiteLive.Twitter
TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended; TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
var user = _twitterUserService.GetUser(username); var user = _twitterUserService.GetUser(username);
if (user.Protected) return new ExtractedTweet[0];
var tweets = new List<ITweet>(); var tweets = new List<ITweet>();
try try
{ {
if (fromTweetId == -1) if (fromTweetId == -1)

View file

@ -60,7 +60,8 @@ namespace BirdsiteLive.Twitter
Url = $"https://twitter.com/{username}", Url = $"https://twitter.com/{username}",
ProfileImageUrl = user.ProfileImageUrlFullSize, ProfileImageUrl = user.ProfileImageUrlFullSize,
ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps, ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps,
ProfileBannerURL = user.ProfileBannerURL ProfileBannerURL = user.ProfileBannerURL,
Protected = user.Protected
}; };
} }
} }

View file

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId> <UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>0.11.2</Version> <Version>0.12.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -79,6 +79,7 @@ namespace BirdsiteLive.Controllers
Acct = user.Acct.ToLowerInvariant(), Acct = user.Acct.ToLowerInvariant(),
Url = user.Url, Url = user.Url,
ProfileImageUrl = user.ProfileImageUrl, ProfileImageUrl = user.ProfileImageUrl,
Protected = user.Protected,
InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}" InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
}; };

View file

@ -7,6 +7,7 @@
public string Acct { get; set; } public string Acct { get; set; }
public string Url { get; set; } public string Url { get; set; }
public string ProfileImageUrl { get; set; } public string ProfileImageUrl { get; set; }
public bool Protected { get; set; }
public string InstanceHandle { get; set; } public string InstanceHandle { get; set; }
} }

View file

@ -21,7 +21,6 @@
@*<h2>@@@ViewData.Model.Acct</h2>*@ @*<h2>@@@ViewData.Model.Acct</h2>*@
<div class="description"> <div class="description">
@ViewData.Model.Description @ViewData.Model.Description
</div> </div>
@ -31,7 +30,19 @@
</a> </a>
<br /> <br />
<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> </div>