2021-01-22 21:23:27 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2020-07-22 19:27:25 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using BirdsiteLive.DAL.Contracts;
|
|
|
|
|
using BirdsiteLive.Pipeline.Contracts;
|
|
|
|
|
using BirdsiteLive.Pipeline.Models;
|
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Pipeline.Processors
|
|
|
|
|
{
|
|
|
|
|
public class SaveProgressionProcessor : ISaveProgressionProcessor
|
|
|
|
|
{
|
|
|
|
|
private readonly ITwitterUserDal _twitterUserDal;
|
|
|
|
|
|
|
|
|
|
#region Ctor
|
|
|
|
|
public SaveProgressionProcessor(ITwitterUserDal twitterUserDal)
|
|
|
|
|
{
|
|
|
|
|
_twitterUserDal = twitterUserDal;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public async Task ProcessAsync(UserWithTweetsToSync userWithTweetsToSync, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var userId = userWithTweetsToSync.User.Id;
|
|
|
|
|
var lastPostedTweet = userWithTweetsToSync.Tweets.Select(x => x.Id).Max();
|
|
|
|
|
var minimumSync = userWithTweetsToSync.Followers.Select(x => x.FollowingsSyncStatus[userId]).Min();
|
2021-01-22 21:23:27 -05:00
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
await _twitterUserDal.UpdateTwitterUserAsync(userId, lastPostedTweet, minimumSync, now);
|
2020-07-22 19:27:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|