2019-11-01 17:38:54 +00:00
|
|
|
#pragma warning disable CS1591
|
2019-12-10 23:13:57 +00:00
|
|
|
#pragma warning disable SA1600
|
2019-11-01 17:38:54 +00:00
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2019-01-13 19:20:16 +00:00
|
|
|
using System.Linq;
|
|
|
|
using MediaBrowser.Controller.Library;
|
2014-08-10 22:13:17 +00:00
|
|
|
using MediaBrowser.Model.Activity;
|
|
|
|
using MediaBrowser.Model.Events;
|
2019-01-25 20:33:58 +00:00
|
|
|
using MediaBrowser.Model.Querying;
|
2019-01-13 19:20:16 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2016-11-03 06:37:52 +00:00
|
|
|
namespace Emby.Server.Implementations.Activity
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
public class ActivityManager : IActivityManager
|
|
|
|
{
|
|
|
|
public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
|
2017-08-27 00:32:33 +00:00
|
|
|
|
2014-08-10 22:13:17 +00:00
|
|
|
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
|
|
|
|
2019-01-17 22:55:05 +00:00
|
|
|
public ActivityManager(
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
IActivityRepository repo,
|
|
|
|
IUserManager userManager)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-01-17 22:55:05 +00:00
|
|
|
_logger = loggerFactory.CreateLogger(nameof(ActivityManager));
|
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
|
|
|
}
|
|
|
|
|
2019-01-25 20:33:58 +00:00
|
|
|
public void Create(ActivityLogEntry entry)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
|
|
|
entry.Date = DateTime.UtcNow;
|
|
|
|
|
2019-01-25 20:33:58 +00:00
|
|
|
_repo.Create(entry);
|
2014-08-10 22:13:17 +00:00
|
|
|
|
2018-12-28 14:21:02 +00:00
|
|
|
EntryCreated?.Invoke(this, new GenericEventArgs<ActivityLogEntry>(entry));
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 20:33:58 +00:00
|
|
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
2014-08-10 22:13:17 +00:00
|
|
|
{
|
2019-01-25 20:33:58 +00:00
|
|
|
var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
|
2014-10-02 00:28:16 +00:00
|
|
|
|
2019-03-01 16:12:22 +00:00
|
|
|
foreach (var item in result.Items)
|
2014-10-02 00:28:16 +00:00
|
|
|
{
|
2019-03-01 16:12:22 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 20:33:58 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
|
|
|
{
|
|
|
|
return GetActivityLogEntries(minDate, null, startIndex, limit);
|
2014-08-10 22:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|