2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2019-01-13 12:20:16 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
2014-08-10 15:13:17 -07:00
|
|
|
using MediaBrowser.Model.Activity;
|
|
|
|
using MediaBrowser.Model.Events;
|
2019-01-25 13:33:58 -07:00
|
|
|
using MediaBrowser.Model.Querying;
|
2014-08-10 15:13:17 -07:00
|
|
|
|
2016-11-02 23:37:52 -07:00
|
|
|
namespace Emby.Server.Implementations.Activity
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
2020-04-15 12:00:45 -07:00
|
|
|
/// <summary>
|
|
|
|
/// The activity log manager.
|
|
|
|
/// </summary>
|
2014-08-10 15:13:17 -07:00
|
|
|
public class ActivityManager : IActivityManager
|
|
|
|
{
|
|
|
|
private readonly IActivityRepository _repo;
|
2014-10-01 17:28:16 -07:00
|
|
|
private readonly IUserManager _userManager;
|
2014-08-10 15:13:17 -07:00
|
|
|
|
2020-04-14 11:50:19 -07: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>
|
2020-04-11 03:03:10 -07:00
|
|
|
public ActivityManager(IActivityRepository repo, IUserManager userManager)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
|
|
|
_repo = repo;
|
2014-10-01 17:28:16 -07:00
|
|
|
_userManager = userManager;
|
2014-08-10 15:13:17 -07:00
|
|
|
}
|
|
|
|
|
2020-04-14 11:50:19 -07:00
|
|
|
/// <inheritdoc />
|
2020-04-11 03:03:10 -07:00
|
|
|
public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
|
|
|
|
|
2019-01-25 13:33:58 -07:00
|
|
|
public void Create(ActivityLogEntry entry)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
|
|
|
entry.Date = DateTime.UtcNow;
|
|
|
|
|
2019-01-25 13:33:58 -07:00
|
|
|
_repo.Create(entry);
|
2014-08-10 15:13:17 -07:00
|
|
|
|
2018-12-28 07:21:02 -07:00
|
|
|
EntryCreated?.Invoke(this, new GenericEventArgs<ActivityLogEntry>(entry));
|
2014-08-10 15:13:17 -07:00
|
|
|
}
|
|
|
|
|
2020-04-14 11:50:19 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-25 13:33:58 -07:00
|
|
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
2019-01-25 13:33:58 -07:00
|
|
|
var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
|
2014-10-01 17:28:16 -07:00
|
|
|
|
2019-03-01 09:12:22 -07:00
|
|
|
foreach (var item in result.Items)
|
2014-10-01 17:28:16 -07:00
|
|
|
{
|
2019-03-01 09:12:22 -07:00
|
|
|
if (item.UserId == Guid.Empty)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-01 17:28:16 -07:00
|
|
|
var user = _userManager.GetUserById(item.UserId);
|
|
|
|
|
|
|
|
if (user != null)
|
|
|
|
{
|
|
|
|
var dto = _userManager.GetUserDto(user);
|
|
|
|
item.UserPrimaryImageTag = dto.PrimaryImageTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:33:58 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-04-14 11:50:19 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-25 13:33:58 -07:00
|
|
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
|
|
|
{
|
|
|
|
return GetActivityLogEntries(minDate, null, startIndex, limit);
|
2014-08-10 15:13:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|