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

74 lines
2.2 KiB
C#
Raw Normal View History

using System;
using MediaBrowser.Controller.Library;
2014-08-10 22:13:17 +00:00
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Querying;
2014-08-10 22:13:17 +00:00
namespace Emby.Server.Implementations.Activity
2014-08-10 22:13:17 +00:00
{
/// <summary>
/// The activity log manager.
/// </summary>
2014-08-10 22:13:17 +00:00
public class ActivityManager : IActivityManager
{
/// <inheritdoc />
2014-08-10 22:13:17 +00:00
public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
2014-08-10 22:13:17 +00:00
private readonly IActivityRepository _repo;
2014-10-02 00:28:16 +00:00
private readonly IUserManager _userManager;
2014-08-10 22:13:17 +00:00
/// <summary>
/// Initializes a new instance of the <see cref="ActivityManager"/> class.
/// </summary>
/// <param name="repo">The activity repository.</param>
/// <param name="userManager">The user manager.</param>
public ActivityManager(
IActivityRepository repo,
IUserManager userManager)
2014-08-10 22:13:17 +00:00
{
_repo = repo;
2014-10-02 00:28:16 +00:00
_userManager = userManager;
2014-08-10 22:13:17 +00:00
}
/// <inheritdoc />
public void Create(ActivityLogEntry entry)
2014-08-10 22:13:17 +00:00
{
entry.Date = DateTime.UtcNow;
_repo.Create(entry);
2014-08-10 22:13:17 +00:00
EntryCreated?.Invoke(this, new GenericEventArgs<ActivityLogEntry>(entry));
2014-08-10 22:13:17 +00:00
}
/// <inheritdoc />
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
2014-08-10 22:13:17 +00:00
{
var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
2014-10-02 00:28:16 +00:00
foreach (var item in result.Items)
2014-10-02 00:28:16 +00:00
{
if (item.UserId == Guid.Empty)
{
continue;
}
2014-10-02 00:28:16 +00:00
var user = _userManager.GetUserById(item.UserId);
if (user != null)
{
var dto = _userManager.GetUserDto(user);
item.UserPrimaryImageTag = dto.PrimaryImageTag;
}
}
return result;
}
/// <inheritdoc />
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
{
return GetActivityLogEntries(minDate, null, startIndex, limit);
2014-08-10 22:13:17 +00:00
}
}
}