diff --git a/src/BirdsiteLive.Common/Settings/InstanceSettings.cs b/src/BirdsiteLive.Common/Settings/InstanceSettings.cs index 1214002..678c45d 100644 --- a/src/BirdsiteLive.Common/Settings/InstanceSettings.cs +++ b/src/BirdsiteLive.Common/Settings/InstanceSettings.cs @@ -8,5 +8,7 @@ public bool ResolveMentionsInProfiles { get; set; } public bool PublishReplies { get; set; } public int MaxUsersCapacity { get; set; } + + public string UnlistedTwitterAccounts { get; set; } } } \ No newline at end of file diff --git a/src/BirdsiteLive.Domain/Repository/ModerationRepository.cs b/src/BirdsiteLive.Domain/Repository/ModerationRepository.cs index f3e23f5..6afc05d 100644 --- a/src/BirdsiteLive.Domain/Repository/ModerationRepository.cs +++ b/src/BirdsiteLive.Domain/Repository/ModerationRepository.cs @@ -26,10 +26,10 @@ namespace BirdsiteLive.Domain.Repository #region Ctor public ModerationRepository(ModerationSettings settings) { - var parsedFollowersWhiteListing = ModerationParser.Parse(settings.FollowersWhiteListing); - var parsedFollowersBlackListing = ModerationParser.Parse(settings.FollowersBlackListing); - var parsedTwitterAccountsWhiteListing = ModerationParser.Parse(settings.TwitterAccountsWhiteListing); - var parsedTwitterAccountsBlackListing = ModerationParser.Parse(settings.TwitterAccountsBlackListing); + var parsedFollowersWhiteListing = PatternsParser.Parse(settings.FollowersWhiteListing); + var parsedFollowersBlackListing = PatternsParser.Parse(settings.FollowersBlackListing); + var parsedTwitterAccountsWhiteListing = PatternsParser.Parse(settings.TwitterAccountsWhiteListing); + var parsedTwitterAccountsBlackListing = PatternsParser.Parse(settings.TwitterAccountsBlackListing); _followersWhiteListing = parsedFollowersWhiteListing .Select(x => ModerationRegexParser.Parse(ModerationEntityTypeEnum.Follower, x)) diff --git a/src/BirdsiteLive.Domain/Repository/PublicationRepository.cs b/src/BirdsiteLive.Domain/Repository/PublicationRepository.cs new file mode 100644 index 0000000..31e94ef --- /dev/null +++ b/src/BirdsiteLive.Domain/Repository/PublicationRepository.cs @@ -0,0 +1,30 @@ +using System.Linq; +using BirdsiteLive.Common.Settings; +using BirdsiteLive.Domain.Tools; + +namespace BirdsiteLive.Domain.Repository +{ + public interface IPublicationRepository + { + bool IsUnlisted(string twitterAcct); + } + + public class PublicationRepository : IPublicationRepository + { + private readonly string[] _unlistedAccounts; + + #region Ctor + public PublicationRepository(InstanceSettings settings) + { + _unlistedAccounts = PatternsParser.Parse(settings.UnlistedTwitterAccounts); + } + #endregion + + public bool IsUnlisted(string twitterAcct) + { + if (_unlistedAccounts == null || !_unlistedAccounts.Any()) return false; + + return _unlistedAccounts.Contains(twitterAcct.ToLowerInvariant()); + } + } +} \ No newline at end of file diff --git a/src/BirdsiteLive.Domain/StatusService.cs b/src/BirdsiteLive.Domain/StatusService.cs index e25d52b..e901db8 100644 --- a/src/BirdsiteLive.Domain/StatusService.cs +++ b/src/BirdsiteLive.Domain/StatusService.cs @@ -7,6 +7,7 @@ using BirdsiteLive.ActivityPub; using BirdsiteLive.ActivityPub.Converters; using BirdsiteLive.ActivityPub.Models; using BirdsiteLive.Common.Settings; +using BirdsiteLive.Domain.Repository; using BirdsiteLive.Domain.Statistics; using BirdsiteLive.Domain.Tools; using BirdsiteLive.Twitter.Models; @@ -25,13 +26,15 @@ namespace BirdsiteLive.Domain private readonly InstanceSettings _instanceSettings; private readonly IStatusExtractor _statusExtractor; private readonly IExtractionStatisticsHandler _statisticsHandler; - + private readonly IPublicationRepository _publicationRepository; + #region Ctor - public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler) + public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, IPublicationRepository publicationRepository) { _instanceSettings = instanceSettings; _statusExtractor = statusExtractor; _statisticsHandler = statisticsHandler; + _publicationRepository = publicationRepository; } #endregion @@ -42,6 +45,11 @@ namespace BirdsiteLive.Domain var to = $"{actorUrl}/followers"; + var isUnlisted = _publicationRepository.IsUnlisted(username); + var cc = new string[0]; + if (isUnlisted) + cc = new[] {"https://www.w3.org/ns/activitystreams#Public"}; + var extractedTags = _statusExtractor.Extract(tweet.MessageContent); _statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention")); @@ -71,8 +79,7 @@ namespace BirdsiteLive.Domain inReplyTo = inReplyTo, to = new[] { to }, - //cc = new[] { "https://www.w3.org/ns/activitystreams#Public" }, - cc = new string[0], + cc = cc, sensitive = false, content = $"
{content}
", diff --git a/src/BirdsiteLive.Domain/Tools/ModerationParser.cs b/src/BirdsiteLive.Domain/Tools/PatternsParser.cs similarity index 95% rename from src/BirdsiteLive.Domain/Tools/ModerationParser.cs rename to src/BirdsiteLive.Domain/Tools/PatternsParser.cs index a338b20..bd77c62 100644 --- a/src/BirdsiteLive.Domain/Tools/ModerationParser.cs +++ b/src/BirdsiteLive.Domain/Tools/PatternsParser.cs @@ -3,7 +3,7 @@ using System.Linq; namespace BirdsiteLive.Domain.Tools { - public class ModerationParser + public class PatternsParser { public static string[] Parse(string entry) { diff --git a/src/BirdsiteLive/appsettings.json b/src/BirdsiteLive/appsettings.json index e5b4c7c..e25c7ca 100644 --- a/src/BirdsiteLive/appsettings.json +++ b/src/BirdsiteLive/appsettings.json @@ -19,8 +19,9 @@ "Domain": "domain.name", "AdminEmail": "me@domain.name", "ResolveMentionsInProfiles": true, - "PublishReplies": false, - "MaxUsersCapacity": 800 + "PublishReplies": false, + "MaxUsersCapacity": 800, + "UnlistedTwitterAccounts": null }, "Db": { "Type": "postgres", diff --git a/src/Tests/BirdsiteLive.Domain.Tests/Tools/ModerationParserTests.cs b/src/Tests/BirdsiteLive.Domain.Tests/Tools/PatternsParserTests.cs similarity index 86% rename from src/Tests/BirdsiteLive.Domain.Tests/Tools/ModerationParserTests.cs rename to src/Tests/BirdsiteLive.Domain.Tests/Tools/PatternsParserTests.cs index 59030fa..848be99 100644 --- a/src/Tests/BirdsiteLive.Domain.Tests/Tools/ModerationParserTests.cs +++ b/src/Tests/BirdsiteLive.Domain.Tests/Tools/PatternsParserTests.cs @@ -5,7 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace BirdsiteLive.Domain.Tests.Tools { [TestClass] - public class ModerationParserTests + public class PatternsParserTests { [TestMethod] public void Parse_Simple_Test() @@ -14,7 +14,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(1, result.Length); @@ -29,7 +29,7 @@ namespace BirdsiteLive.Domain.Tests.Tools string entry = null; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(0, result.Length); @@ -43,7 +43,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = " "; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(0, result.Length); @@ -57,7 +57,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test|test2"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length); @@ -73,7 +73,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test;test2"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length); @@ -89,7 +89,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test,test2"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length); @@ -105,7 +105,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test;test2;"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length); @@ -121,7 +121,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test; test2"; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length); @@ -137,7 +137,7 @@ namespace BirdsiteLive.Domain.Tests.Tools var entry = "test; test2; "; #endregion - var result = ModerationParser.Parse(entry); + var result = PatternsParser.Parse(entry); #region Validations Assert.AreEqual(2, result.Length);