Set a maximum number of follows per user
This commit is contained in:
parent
f99d5fdc09
commit
fd1b3ab983
4 changed files with 21 additions and 3 deletions
|
@ -51,6 +51,7 @@ If both whitelisting and blacklisting are set, only the whitelisting will be act
|
|||
* `Instance:TwitterDomainLabel` (default: "") if TwitterDomain is set, use this label on profile pages instead of the domain itself (i.e. you can set this to "Nitter" to show that on profiles instead of "twiiit.com")
|
||||
* `Instance:InfoBanner` (default: "") text to show in a banner on the front page
|
||||
* `Instance:ShowAboutInstanceOnProfiles` (default: true) show "About [instance name]" on profiles with a link to /About
|
||||
* `Instance:MaxFollowsPerUser` (default: 0 - no limit) limit the number of follows per user - any follow count above this number will be Rejected
|
||||
|
||||
# Docker Compose full example
|
||||
|
||||
|
|
|
@ -19,5 +19,7 @@
|
|||
|
||||
public bool ShowAboutInstanceOnProfiles { get; set; }
|
||||
|
||||
public int MaxFollowsPerUser { get; set; }
|
||||
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ using BirdsiteLive.ActivityPub.Converters;
|
|||
using BirdsiteLive.Common.Regexes;
|
||||
using BirdsiteLive.Common.Settings;
|
||||
using BirdsiteLive.Cryptography;
|
||||
using BirdsiteLive.DAL.Contracts;
|
||||
using BirdsiteLive.Domain.BusinessUseCases;
|
||||
using BirdsiteLive.Domain.Repository;
|
||||
using BirdsiteLive.Domain.Statistics;
|
||||
|
@ -45,8 +46,10 @@ namespace BirdsiteLive.Domain
|
|||
|
||||
private readonly IModerationRepository _moderationRepository;
|
||||
|
||||
private readonly IFollowersDal _followerDal;
|
||||
|
||||
#region Ctor
|
||||
public UserService(InstanceSettings instanceSettings, ICryptoService cryptoService, IActivityPubService activityPubService, IProcessFollowUser processFollowUser, IProcessUndoFollowUser processUndoFollowUser, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, ITwitterUserService twitterUserService, IModerationRepository moderationRepository)
|
||||
public UserService(InstanceSettings instanceSettings, ICryptoService cryptoService, IActivityPubService activityPubService, IProcessFollowUser processFollowUser, IProcessUndoFollowUser processUndoFollowUser, IStatusExtractor statusExtractor, IExtractionStatisticsHandler statisticsHandler, ITwitterUserService twitterUserService, IModerationRepository moderationRepository, IFollowersDal followerDal)
|
||||
{
|
||||
_instanceSettings = instanceSettings;
|
||||
_cryptoService = cryptoService;
|
||||
|
@ -57,6 +60,7 @@ namespace BirdsiteLive.Domain
|
|||
_statisticsHandler = statisticsHandler;
|
||||
_twitterUserService = twitterUserService;
|
||||
_moderationRepository = moderationRepository;
|
||||
_followerDal = followerDal;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -177,6 +181,16 @@ namespace BirdsiteLive.Domain
|
|||
return await SendRejectFollowAsync(activity, followerHost);
|
||||
}
|
||||
|
||||
// Validate follower count < MaxFollowsPerUser
|
||||
if (_instanceSettings.MaxFollowsPerUser > 0) {
|
||||
var follower = await _followerDal.GetFollowerAsync(followerUserName, followerHost);
|
||||
|
||||
if (follower != null && follower.Followings.Count + 1 > _instanceSettings.MaxFollowsPerUser)
|
||||
{
|
||||
return await SendRejectFollowAsync(activity, followerHost);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate User Protected
|
||||
var user = _twitterUserService.GetUser(twitterUser);
|
||||
if (!user.Protected)
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
"TwitterDomain": "twitter.com",
|
||||
"TwitterDomainLabel": "",
|
||||
"InfoBanner": "",
|
||||
"ShowAboutInstanceOnProfiles": true
|
||||
"ShowAboutInstanceOnProfiles": true,
|
||||
"MaxFollowsPerUser": 0
|
||||
},
|
||||
"Db": {
|
||||
"Type": "postgres",
|
||||
|
@ -44,4 +45,4 @@
|
|||
"TwitterAccountsWhiteListing": null,
|
||||
"TwitterAccountsBlackListing": null
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue