-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from NicolasConstant/develop
0.19.0 PR
- Loading branch information
Showing
41 changed files
with
1,149 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/BirdsiteLive.Pipeline/Contracts/IRefreshTwitterUserStatusProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BirdsiteLive.DAL.Models; | ||
using BirdsiteLive.Pipeline.Models; | ||
|
||
namespace BirdsiteLive.Pipeline.Contracts | ||
{ | ||
public interface IRefreshTwitterUserStatusProcessor | ||
{ | ||
Task<UserWithDataToSync[]> ProcessAsync(SyncTwitterUser[] syncTwitterUsers, CancellationToken ct); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/BirdsiteLive.Pipeline/Processors/RefreshTwitterUserStatusProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BirdsiteLive.Common.Settings; | ||
using BirdsiteLive.DAL.Contracts; | ||
using BirdsiteLive.DAL.Models; | ||
using BirdsiteLive.Moderation.Actions; | ||
using BirdsiteLive.Pipeline.Contracts; | ||
using BirdsiteLive.Pipeline.Models; | ||
using BirdsiteLive.Twitter; | ||
|
||
namespace BirdsiteLive.Pipeline.Processors | ||
{ | ||
public class RefreshTwitterUserStatusProcessor : IRefreshTwitterUserStatusProcessor | ||
{ | ||
private readonly ICachedTwitterUserService _twitterUserService; | ||
private readonly ITwitterUserDal _twitterUserDal; | ||
private readonly IRemoveTwitterAccountAction _removeTwitterAccountAction; | ||
private readonly InstanceSettings _instanceSettings; | ||
|
||
#region Ctor | ||
public RefreshTwitterUserStatusProcessor(ICachedTwitterUserService twitterUserService, ITwitterUserDal twitterUserDal, IRemoveTwitterAccountAction removeTwitterAccountAction, InstanceSettings instanceSettings) | ||
{ | ||
_twitterUserService = twitterUserService; | ||
_twitterUserDal = twitterUserDal; | ||
_removeTwitterAccountAction = removeTwitterAccountAction; | ||
_instanceSettings = instanceSettings; | ||
} | ||
#endregion | ||
|
||
public async Task<UserWithDataToSync[]> ProcessAsync(SyncTwitterUser[] syncTwitterUsers, CancellationToken ct) | ||
{ | ||
var usersWtData = new List<UserWithDataToSync>(); | ||
|
||
foreach (var user in syncTwitterUsers) | ||
{ | ||
var userView = _twitterUserService.GetUser(user.Acct); | ||
if (userView == null) | ||
{ | ||
await AnalyseFailingUserAsync(user); | ||
} | ||
else if (!userView.Protected) | ||
{ | ||
user.FetchingErrorCount = 0; | ||
var userWtData = new UserWithDataToSync | ||
{ | ||
User = user | ||
}; | ||
usersWtData.Add(userWtData); | ||
} | ||
} | ||
|
||
return usersWtData.ToArray(); | ||
} | ||
|
||
private async Task AnalyseFailingUserAsync(SyncTwitterUser user) | ||
{ | ||
var dbUser = await _twitterUserDal.GetTwitterUserAsync(user.Acct); | ||
dbUser.FetchingErrorCount++; | ||
|
||
if (dbUser.FetchingErrorCount > _instanceSettings.FailingTwitterUserCleanUpThreshold) | ||
{ | ||
await _removeTwitterAccountAction.ProcessAsync(user); | ||
} | ||
else | ||
{ | ||
await _twitterUserDal.UpdateTwitterUserAsync(dbUser); | ||
} | ||
|
||
// Purge | ||
_twitterUserService.PurgeUser(user.Acct); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.