2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2019-01-06 08:00:30 -07:00
|
|
|
using System.Collections.Generic;
|
2019-01-13 12:20:16 -07:00
|
|
|
using System.Linq;
|
2019-01-06 08:00:30 -07:00
|
|
|
using System.Threading.Tasks;
|
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-13 12:20:16 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
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
|
|
|
{
|
|
|
|
public class ActivityManager : IActivityManager
|
|
|
|
{
|
|
|
|
public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
|
2017-08-26 17:32:33 -07:00
|
|
|
|
2014-08-10 15:13:17 -07:00
|
|
|
private readonly IActivityRepository _repo;
|
|
|
|
private readonly ILogger _logger;
|
2014-10-01 17:28:16 -07:00
|
|
|
private readonly IUserManager _userManager;
|
2014-08-10 15:13:17 -07:00
|
|
|
|
2019-01-17 15:55:05 -07:00
|
|
|
public ActivityManager(
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
IActivityRepository repo,
|
|
|
|
IUserManager userManager)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
2019-01-17 15:55:05 -07:00
|
|
|
_logger = loggerFactory.CreateLogger(nameof(ActivityManager));
|
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
|
|
|
}
|
|
|
|
|
2019-01-23 11:09:34 -07:00
|
|
|
public async Task CreateAsync(ActivityLogEntry entry)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
|
|
|
entry.Date = DateTime.UtcNow;
|
|
|
|
|
2019-01-06 08:00:30 -07:00
|
|
|
await _repo.CreateAsync(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
|
|
|
}
|
|
|
|
|
2019-01-06 08:00:30 -07:00
|
|
|
public IEnumerable<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
2014-08-10 15:13:17 -07:00
|
|
|
{
|
2019-01-06 08:00:30 -07:00
|
|
|
var result = _repo.GetActivityLogEntries();
|
2014-10-01 17:28:16 -07:00
|
|
|
|
2019-01-06 08:00:30 -07:00
|
|
|
if (minDate.HasValue)
|
|
|
|
{
|
|
|
|
result = result.Where(x => x.Date >= minDate.Value);
|
|
|
|
}
|
|
|
|
if (hasUserId.HasValue)
|
|
|
|
{
|
|
|
|
result = result.Where(x => x.UserId != null && x.UserId != Guid.Empty);
|
|
|
|
}
|
|
|
|
if (startIndex.HasValue)
|
|
|
|
{
|
|
|
|
result = result.Where(x => x.Id >= startIndex.Value);
|
|
|
|
}
|
|
|
|
if (limit.HasValue)
|
|
|
|
{
|
|
|
|
result = result.Take(limit.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add images for each user
|
|
|
|
foreach (var item in result)
|
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-16 07:16:19 -07:00
|
|
|
return result.AsEnumerable();
|
2014-08-10 15:13:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|