jellyfin/MediaBrowser.Server.Implementations/Activity/ActivityManager.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2014-08-10 22:13:17 +00:00
using MediaBrowser.Common.Events;
using MediaBrowser.Controller.Activity;
2014-10-02 00:28:16 +00:00
using MediaBrowser.Controller.Library;
2014-08-10 22:13:17 +00:00
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Querying;
using System;
2014-10-02 00:28:16 +00:00
using System.Linq;
2014-08-10 22:13:17 +00:00
using System.Threading.Tasks;
namespace MediaBrowser.Server.Implementations.Activity
{
public class ActivityManager : IActivityManager
{
public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
private readonly IActivityRepository _repo;
private readonly ILogger _logger;
2014-10-02 00:28:16 +00:00
private readonly IUserManager _userManager;
2014-08-10 22:13:17 +00:00
2014-10-02 00:28:16 +00:00
public ActivityManager(ILogger logger, IActivityRepository repo, IUserManager userManager)
2014-08-10 22:13:17 +00:00
{
_logger = logger;
_repo = repo;
2014-10-02 00:28:16 +00:00
_userManager = userManager;
2014-08-10 22:13:17 +00:00
}
public async Task Create(ActivityLogEntry entry)
{
entry.Id = Guid.NewGuid().ToString("N");
entry.Date = DateTime.UtcNow;
await _repo.Create(entry).ConfigureAwait(false);
EventHelper.FireEventIfNotNull(EntryCreated, this, new GenericEventArgs<ActivityLogEntry>(entry), _logger);
}
2014-08-14 13:24:30 +00:00
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
2014-08-10 22:13:17 +00:00
{
2014-10-02 00:28:16 +00:00
var result = _repo.GetActivityLogEntries(minDate, startIndex, limit);
foreach (var item in result.Items.Where(i => !string.IsNullOrWhiteSpace(i.UserId)))
{
var user = _userManager.GetUserById(item.UserId);
if (user != null)
{
var dto = _userManager.GetUserDto(user);
item.UserPrimaryImageTag = dto.PrimaryImageTag;
}
}
return result;
2014-08-10 22:13:17 +00:00
}
}
}