Add Instance:SensitiveTwitterAccounts variable

Adds the Instance:SensitiveTwitterAccounts variable, which emulates
Instance:UnlistedTwitterAccounts but will automatically mark all listed
accounts as sensitive.
This commit is contained in:
nytpu 2021-07-16 11:47:52 -06:00
parent 07dc912624
commit 894f98b0f2
5 changed files with 25 additions and 5 deletions

View File

@ -47,6 +47,7 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
* `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:UnlistedTwitterAccounts` (default: null) to enable unlisted publication for selected twitter accounts, separated by `;` (please limit this to brands and other public profiles).
* `Instance:SensitiveTwitterAccounts` (default: null) mark all media from given accounts as sensitive by default, separated by `;`.
# Docker Compose full example
@ -78,6 +79,7 @@ services:
+ - Instance:ResolveMentionsInProfiles=false
+ - Instance:PublishReplies=true
+ - Instance:UnlistedTwitterAccounts=cocacola;twitter
+ - Instance:SensitiveTwitterAccounts=archillect
networks:
[...]

View File

@ -10,5 +10,6 @@
public int MaxUsersCapacity { get; set; }
public string UnlistedTwitterAccounts { get; set; }
public string SensitiveTwitterAccounts { get; set; }
}
}
}

View File

@ -7,16 +7,19 @@ namespace BirdsiteLive.Domain.Repository
public interface IPublicationRepository
{
bool IsUnlisted(string twitterAcct);
bool IsSensitive(string twitterAcct);
}
public class PublicationRepository : IPublicationRepository
{
private readonly string[] _unlistedAccounts;
private readonly string[] _sensitiveAccounts;
#region Ctor
public PublicationRepository(InstanceSettings settings)
{
_unlistedAccounts = PatternsParser.Parse(settings.UnlistedTwitterAccounts);
_sensitiveAccounts = PatternsParser.Parse(settings.SensitiveTwitterAccounts);
}
#endregion
@ -26,5 +29,12 @@ namespace BirdsiteLive.Domain.Repository
return _unlistedAccounts.Contains(twitterAcct.ToLowerInvariant());
}
public bool IsSensitive(string twitterAcct)
{
if (_sensitiveAccounts == null || !_sensitiveAccounts.Any()) return false;
return _sensitiveAccounts.Contains(twitterAcct.ToLowerInvariant());
}
}
}
}

View File

@ -50,6 +50,11 @@ namespace BirdsiteLive.Domain
if (isUnlisted)
cc = new[] {"https://www.w3.org/ns/activitystreams#Public"};
string summary = null;
var sensitive = _publicationRepository.IsSensitive(username);
if (sensitive)
summary = "Potential Content Warning";
var extractedTags = _statusExtractor.Extract(tweet.MessageContent);
_statisticsHandler.ExtractedStatus(extractedTags.tags.Count(x => x.type == "Mention"));
@ -81,7 +86,8 @@ namespace BirdsiteLive.Domain
to = new[] { to },
cc = cc,
sensitive = false,
sensitive = sensitive,
summary = summary,
content = $"<p>{content}</p>",
attachment = Convert(tweet.Media),
tag = extractedTags.tags
@ -104,4 +110,4 @@ namespace BirdsiteLive.Domain
}).ToArray();
}
}
}
}

View File

@ -21,7 +21,8 @@
"ResolveMentionsInProfiles": true,
"PublishReplies": false,
"MaxUsersCapacity": 1500,
"UnlistedTwitterAccounts": null
"UnlistedTwitterAccounts": null,
"SensitiveTwitterAccounts": null
},
"Db": {
"Type": "postgres",