Merge pull request #95 from NicolasConstant/topic_post-unlisted

Topic post unlisted
This commit is contained in:
Nicolas Constant 2021-02-28 04:23:37 +01:00 committed by GitHub
commit fcdb73d391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 24 deletions

View File

@ -46,6 +46,7 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
* `Instance:Name` (default: BirdsiteLIVE) the name of the instance * `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. * `Instance:PublishReplies` (default: false) to enable or disable replies publishing.
* `Instance:UnlistedTwitterAccounts` (default: null) to enable unlisted publication for selected twitter accounts, separated by `;` (please limit this to brands and other public profiles).
# Docker Compose full example # Docker Compose full example
@ -76,6 +77,7 @@ services:
+ - Instance:Name=MyTwitterRelay + - Instance:Name=MyTwitterRelay
+ - Instance:ResolveMentionsInProfiles=false + - Instance:ResolveMentionsInProfiles=false
+ - Instance:PublishReplies=true + - Instance:PublishReplies=true
+ - Instance:UnlistedTwitterAccounts=cocacola;twitter
networks: networks:
[...] [...]

View File

@ -8,5 +8,7 @@
public bool ResolveMentionsInProfiles { get; set; } public bool ResolveMentionsInProfiles { get; set; }
public bool PublishReplies { get; set; } public bool PublishReplies { get; set; }
public int MaxUsersCapacity { get; set; } public int MaxUsersCapacity { get; set; }
public string UnlistedTwitterAccounts { get; set; }
} }
} }

View File

@ -26,10 +26,10 @@ namespace BirdsiteLive.Domain.Repository
#region Ctor #region Ctor
public ModerationRepository(ModerationSettings settings) public ModerationRepository(ModerationSettings settings)
{ {
var parsedFollowersWhiteListing = ModerationParser.Parse(settings.FollowersWhiteListing); var parsedFollowersWhiteListing = PatternsParser.Parse(settings.FollowersWhiteListing);
var parsedFollowersBlackListing = ModerationParser.Parse(settings.FollowersBlackListing); var parsedFollowersBlackListing = PatternsParser.Parse(settings.FollowersBlackListing);
var parsedTwitterAccountsWhiteListing = ModerationParser.Parse(settings.TwitterAccountsWhiteListing); var parsedTwitterAccountsWhiteListing = PatternsParser.Parse(settings.TwitterAccountsWhiteListing);
var parsedTwitterAccountsBlackListing = ModerationParser.Parse(settings.TwitterAccountsBlackListing); var parsedTwitterAccountsBlackListing = PatternsParser.Parse(settings.TwitterAccountsBlackListing);
_followersWhiteListing = parsedFollowersWhiteListing _followersWhiteListing = parsedFollowersWhiteListing
.Select(x => ModerationRegexParser.Parse(ModerationEntityTypeEnum.Follower, x)) .Select(x => ModerationRegexParser.Parse(ModerationEntityTypeEnum.Follower, x))

View File

@ -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());
}
}
}

View File

@ -7,6 +7,7 @@ using BirdsiteLive.ActivityPub;
using BirdsiteLive.ActivityPub.Converters; using BirdsiteLive.ActivityPub.Converters;
using BirdsiteLive.ActivityPub.Models; using BirdsiteLive.ActivityPub.Models;
using BirdsiteLive.Common.Settings; using BirdsiteLive.Common.Settings;
using BirdsiteLive.Domain.Repository;
using BirdsiteLive.Domain.Statistics; using BirdsiteLive.Domain.Statistics;
using BirdsiteLive.Domain.Tools; using BirdsiteLive.Domain.Tools;
using BirdsiteLive.Twitter.Models; using BirdsiteLive.Twitter.Models;
@ -25,13 +26,15 @@ namespace BirdsiteLive.Domain
private readonly InstanceSettings _instanceSettings; private readonly InstanceSettings _instanceSettings;
private readonly IStatusExtractor _statusExtractor; private readonly IStatusExtractor _statusExtractor;
private readonly IExtractionStatisticsHandler _statisticsHandler; private readonly IExtractionStatisticsHandler _statisticsHandler;
private readonly IPublicationRepository _publicationRepository;
#region Ctor #region Ctor
public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler) public StatusService(InstanceSettings instanceSettings, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, IPublicationRepository publicationRepository)
{ {
_instanceSettings = instanceSettings; _instanceSettings = instanceSettings;
_statusExtractor = statusExtractor; _statusExtractor = statusExtractor;
_statisticsHandler = statisticsHandler; _statisticsHandler = statisticsHandler;
_publicationRepository = publicationRepository;
} }
#endregion #endregion
@ -42,6 +45,11 @@ namespace BirdsiteLive.Domain
var to = $"{actorUrl}/followers"; 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); var extractedTags = _statusExtractor.Extract(tweet.MessageContent);
_statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention")); _statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention"));
@ -71,8 +79,7 @@ namespace BirdsiteLive.Domain
inReplyTo = inReplyTo, inReplyTo = inReplyTo,
to = new[] { to }, to = new[] { to },
//cc = new[] { "https://www.w3.org/ns/activitystreams#Public" }, cc = cc,
cc = new string[0],
sensitive = false, sensitive = false,
content = $"<p>{content}</p>", content = $"<p>{content}</p>",

View File

@ -3,7 +3,7 @@ using System.Linq;
namespace BirdsiteLive.Domain.Tools namespace BirdsiteLive.Domain.Tools
{ {
public class ModerationParser public class PatternsParser
{ {
public static string[] Parse(string entry) public static string[] Parse(string entry)
{ {

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.15.0</Version> <Version>0.16.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -90,10 +90,17 @@ namespace BirdsiteLive.Controllers
published = nowString, published = nowString,
url = noteUrl, url = noteUrl,
attributedTo = actor, attributedTo = actor,
// Unlisted
to = new[] { to }, to = new[] { to },
//cc = new [] { "https://www.w3.org/ns/activitystreams#Public" }, cc = new [] { "https://www.w3.org/ns/activitystreams#Public" },
//// Public
//to = new[] { "https://www.w3.org/ns/activitystreams#Public" },
//cc = new[] { to },
sensitive = false, sensitive = false,
content = "<p>Woooot</p>", content = "<p>TEST PUBLIC</p>",
attachment = new Attachment[0], attachment = new Attachment[0],
tag = new Tag[0] tag = new Tag[0]
} }

View File

@ -20,7 +20,8 @@
"AdminEmail": "me@domain.name", "AdminEmail": "me@domain.name",
"ResolveMentionsInProfiles": true, "ResolveMentionsInProfiles": true,
"PublishReplies": false, "PublishReplies": false,
"MaxUsersCapacity": 800 "MaxUsersCapacity": 800,
"UnlistedTwitterAccounts": null
}, },
"Db": { "Db": {
"Type": "postgres", "Type": "postgres",

View File

@ -5,7 +5,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BirdsiteLive.Domain.Tests.Tools namespace BirdsiteLive.Domain.Tests.Tools
{ {
[TestClass] [TestClass]
public class ModerationParserTests public class PatternsParserTests
{ {
[TestMethod] [TestMethod]
public void Parse_Simple_Test() public void Parse_Simple_Test()
@ -14,7 +14,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test"; var entry = "test";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(1, result.Length); Assert.AreEqual(1, result.Length);
@ -29,7 +29,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
string entry = null; string entry = null;
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(0, result.Length); Assert.AreEqual(0, result.Length);
@ -43,7 +43,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = " "; var entry = " ";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(0, result.Length); Assert.AreEqual(0, result.Length);
@ -57,7 +57,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test|test2"; var entry = "test|test2";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);
@ -73,7 +73,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test;test2"; var entry = "test;test2";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);
@ -89,7 +89,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test,test2"; var entry = "test,test2";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);
@ -105,7 +105,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test;test2;"; var entry = "test;test2;";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);
@ -121,7 +121,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test; test2"; var entry = "test; test2";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);
@ -137,7 +137,7 @@ namespace BirdsiteLive.Domain.Tests.Tools
var entry = "test; test2; "; var entry = "test; test2; ";
#endregion #endregion
var result = ModerationParser.Parse(entry); var result = PatternsParser.Parse(entry);
#region Validations #region Validations
Assert.AreEqual(2, result.Length); Assert.AreEqual(2, result.Length);