Skip to content

Commit

Permalink
Merge pull request #71 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
0.12.0 PR
  • Loading branch information
NicolasConstant authored Jan 28, 2021
2 parents 951a470 + b942a52 commit f721f30
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 25 deletions.
10 changes: 10 additions & 0 deletions src/BirdsiteLive.ActivityPub/Models/ActivityRejectFollow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace BirdsiteLive.ActivityPub
{
public class ActivityRejectFollow : Activity
{
[JsonProperty("object")]
public ActivityFollow apObject { get; set; }
}
}
1 change: 1 addition & 0 deletions src/BirdsiteLive.ActivityPub/Models/Actor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Actor
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; }
Expand Down
66 changes: 47 additions & 19 deletions src/BirdsiteLive.Domain/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -36,8 +37,10 @@ public class UserService : IUserService
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;
Expand All @@ -46,7 +49,7 @@ public UserService(InstanceSettings instanceSettings, ICryptoService cryptoServi
_processUndoFollowUser = processUndoFollowUser;
_statusExtractor = statusExtractor;
_statisticsHandler = statisticsHandler;
//_host = $"https://{instanceSettings.Domain.Replace("https://",string.Empty).Replace("http://", string.Empty).TrimEnd('/')}";
_twitterUserService = twitterUserService;
}
#endregion

Expand Down Expand Up @@ -75,6 +78,7 @@ public Actor GetUser(TwitterUser twitterUser)
inbox = $"{actorUrl}/inbox",
summary = description,
url = actorUrl,
manuallyApprovesFollowers = twitterUser.Protected,
publicKey = new PublicKey()
{
id = $"{actorUrl}#main-key",
Expand Down Expand Up @@ -125,26 +129,50 @@ public async Task<bool> FollowRequestedAsync(string signature, string method, st
followerInbox = OnlyKeepRoute(followerInbox, followerHost);
followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost);

// Execute
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);
var user = _twitterUserService.GetUser(twitterUser);
if (!user.Protected)
{
// Execute
await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);

// Send Accept Activity
var acceptFollow = new ActivityAcceptFollow()
// Send Accept Activity
var acceptFollow = new ActivityAcceptFollow()
{
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
{
context = "https://www.w3.org/ns/activitystreams",
id = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}",
type = "Accept",
actor = activity.apObject,
apObject = new ActivityFollow()
// Send Reject Activity
var acceptFollow = new ActivityRejectFollow()
{
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}#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)
Expand Down
1 change: 1 addition & 0 deletions src/BirdsiteLive.Twitter/Models/TwitterUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class TwitterUser
public string ProfileBackgroundImageUrl { get; set; }
public string Acct { get; set; }
public string ProfileBannerURL { get; set; }
public bool Protected { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/BirdsiteLive.Twitter/TwitterTweetsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTw
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)
Expand Down
3 changes: 2 additions & 1 deletion src/BirdsiteLive.Twitter/TwitterUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public TwitterUser GetUser(string username)
Url = $"https://twitter.com/{username}",
ProfileImageUrl = user.ProfileImageUrlFullSize,
ProfileBackgroundImageUrl = user.ProfileBackgroundImageUrlHttps,
ProfileBannerURL = user.ProfileBannerURL
ProfileBannerURL = user.ProfileBannerURL,
Protected = user.Protected
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BirdsiteLive/BirdsiteLive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/BirdsiteLive/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public IActionResult Index(string id)
Acct = user.Acct.ToLowerInvariant(),
Url = user.Url,
ProfileImageUrl = user.ProfileImageUrl,
Protected = user.Protected,

InstanceHandle = $"@{user.Acct.ToLowerInvariant()}@{_instanceSettings.Domain}"
};
Expand Down
1 change: 1 addition & 0 deletions src/BirdsiteLive/Models/DisplayTwitterUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class DisplayTwitterUser
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; }
}
Expand Down
17 changes: 14 additions & 3 deletions src/BirdsiteLive/Views/Users/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

@*<h2>@@@ViewData.Model.Acct</h2>*@


<div class="description">
@ViewData.Model.Description
</div>
Expand All @@ -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>

0 comments on commit f721f30

Please sign in to comment.