Skip to content

Commit

Permalink
Merge pull request #65 from NicolasConstant/topic_add-last-sync
Browse files Browse the repository at this point in the history
reply filtering PR
  • Loading branch information
NicolasConstant authored Jan 23, 2021
2 parents fee7810 + ffdd041 commit 32df020
Show file tree
Hide file tree
Showing 11 changed files with 923 additions and 18 deletions.
3 changes: 2 additions & 1 deletion VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ You can configure some of BirdsiteLIVE's settings via environment variables (tho
## Instance customization

* `Instance:Name` (default: BirdsiteLIVE) the name of the instance
* `Instance:ResolveMentionsInProfiles` (default: true) to enable or disable mentions parsing in profile's description. Resolving it will consume more User's API calls since newly discovered account can also contain references to others accounts as well. On a big instance it is recommended to disable it.
* `Instance:ResolveMentionsInProfiles` (default: true) to enable or disable mentions parsing in profile's description. Resolving it will consume more User's API calls since newly discovered account can also contain references to others accounts as well. On a big instance it is recommended to disable it.
* `Instance:PublishReplies` (default: false) to enable or disable replies publishing.
1 change: 1 addition & 0 deletions src/BirdsiteLive.Common/Settings/InstanceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class InstanceSettings
public string Domain { get; set; }
public string AdminEmail { get; set; }
public bool ResolveMentionsInProfiles { get; set; }
public bool PublishReplies { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Models;
using BirdsiteLive.Domain;
Expand All @@ -21,15 +22,17 @@ public class SendTweetsToInboxTask : ISendTweetsToInboxTask
private readonly IActivityPubService _activityPubService;
private readonly IStatusService _statusService;
private readonly IFollowersDal _followersDal;
private readonly InstanceSettings _settings;
private readonly ILogger<SendTweetsToInboxTask> _logger;


#region Ctor
public SendTweetsToInboxTask(IActivityPubService activityPubService, IStatusService statusService, IFollowersDal followersDal, ILogger<SendTweetsToInboxTask> logger)
public SendTweetsToInboxTask(IActivityPubService activityPubService, IStatusService statusService, IFollowersDal followersDal, InstanceSettings settings, ILogger<SendTweetsToInboxTask> logger)
{
_activityPubService = activityPubService;
_statusService = statusService;
_followersDal = followersDal;
_settings = settings;
_logger = logger;
}
#endregion
Expand All @@ -52,8 +55,13 @@ public async Task ExecuteAsync(IEnumerable<ExtractedTweet> tweets, Follower foll
{
try
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewNoteActivity(note, user.Acct, tweet.Id.ToString(), follower.Host, inbox);
if (!tweet.IsReply ||
tweet.IsReply && tweet.IsThread ||
_settings.PublishReplies)
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewNoteActivity(note, user.Acct, tweet.Id.ToString(), follower.Host, inbox);
}
}
catch (ArgumentException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Models;
using BirdsiteLive.Domain;
Expand All @@ -20,14 +21,16 @@ public class SendTweetsToSharedInboxTask : ISendTweetsToSharedInboxTask
private readonly IStatusService _statusService;
private readonly IActivityPubService _activityPubService;
private readonly IFollowersDal _followersDal;
private readonly InstanceSettings _settings;
private readonly ILogger<SendTweetsToSharedInboxTask> _logger;

#region Ctor
public SendTweetsToSharedInboxTask(IActivityPubService activityPubService, IStatusService statusService, IFollowersDal followersDal, ILogger<SendTweetsToSharedInboxTask> logger)
public SendTweetsToSharedInboxTask(IActivityPubService activityPubService, IStatusService statusService, IFollowersDal followersDal, InstanceSettings settings, ILogger<SendTweetsToSharedInboxTask> logger)
{
_activityPubService = activityPubService;
_statusService = statusService;
_followersDal = followersDal;
_settings = settings;
_logger = logger;
}
#endregion
Expand All @@ -52,8 +55,13 @@ public async Task ExecuteAsync(ExtractedTweet[] tweets, SyncTwitterUser user, st
{
try
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewNoteActivity(note, user.Acct, tweet.Id.ToString(), host, inbox);
if (!tweet.IsReply ||
tweet.IsReply && tweet.IsThread ||
_settings.PublishReplies)
{
var note = _statusService.GetStatus(user.Acct, tweet);
await _activityPubService.PostNewNoteActivity(note, user.Acct, tweet.Id.ToString(), host, inbox);
}
}
catch (ArgumentException e)
{
Expand All @@ -66,7 +74,7 @@ public async Task ExecuteAsync(ExtractedTweet[] tweets, SyncTwitterUser user, st
throw;
}
}

syncStatus = tweet.Id;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/BirdsiteLive.Twitter/Extractors/TweetExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public ExtractedTweet Extract(ITweet tweet)
InReplyToAccount = tweet.InReplyToScreenName,
MessageContent = ExtractMessage(tweet),
Media = ExtractMedia(tweet.Media),
CreatedAt = tweet.CreatedAt.ToUniversalTime()
CreatedAt = tweet.CreatedAt.ToUniversalTime(),
IsReply = tweet.InReplyToUserId != null,
IsThread = tweet.InReplyToUserId != null && tweet.InReplyToUserId == tweet.CreatedBy.Id
};
return extractedTweet;
}
Expand Down
2 changes: 2 additions & 0 deletions src/BirdsiteLive.Twitter/Models/ExtractedTweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class ExtractedTweet
public ExtractedMedia[] Media { get; set; }
public DateTime CreatedAt { get; set; }
public string InReplyToAccount { get; set; }
public bool IsReply { get; set; }
public bool IsThread { 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 @@ -40,7 +40,7 @@ public ExtractedTweet GetTweet(long statusId)
var tweet = Tweet.GetTweet(statusId);
_statisticsHandler.CalledTweetApi();
if (tweet == null) return null; //TODO: test this
return _tweetExtractor.Extract(tweet);
return _tweetExtractor.Extract(tweet);
}

public ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1)
Expand Down
3 changes: 2 additions & 1 deletion src/BirdsiteLive/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"Name": "BirdsiteLIVE",
"Domain": "domain.name",
"AdminEmail": "[email protected]",
"ResolveMentionsInProfiles": true
"ResolveMentionsInProfiles": true,
"PublishReplies": false
},
"Db": {
"Type": "postgres",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task GetTwitterUsersAsync_Multi_Test()
processor.WaitFactor = 2;
processor.GetTwitterUsersAsync(buffer, CancellationToken.None);

await Task.Delay(200);
await Task.Delay(300);

#region Validations
twitterUserDalMock.VerifyAll();
Expand Down
Loading

0 comments on commit 32df020

Please sign in to comment.