ActivityManager.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Activity;
  4. using MediaBrowser.Model.Events;
  5. using MediaBrowser.Model.Querying;
  6. namespace Emby.Server.Implementations.Activity
  7. {
  8. /// <inheritdoc />
  9. public class ActivityManager : IActivityManager
  10. {
  11. /// <inheritdoc />
  12. public event EventHandler<GenericEventArgs<ActivityLogEntry>> EntryCreated;
  13. private readonly IActivityRepository _repo;
  14. private readonly IUserManager _userManager;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="ActivityManager"/> class.
  17. /// </summary>
  18. /// <param name="repo">The activity repository.</param>
  19. /// <param name="userManager">The user manager.</param>
  20. public ActivityManager(
  21. IActivityRepository repo,
  22. IUserManager userManager)
  23. {
  24. _repo = repo;
  25. _userManager = userManager;
  26. }
  27. /// <inheritdoc />
  28. public void Create(ActivityLogEntry entry)
  29. {
  30. entry.Date = DateTime.UtcNow;
  31. _repo.Create(entry);
  32. EntryCreated?.Invoke(this, new GenericEventArgs<ActivityLogEntry>(entry));
  33. }
  34. /// <inheritdoc />
  35. public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
  36. {
  37. var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
  38. foreach (var item in result.Items)
  39. {
  40. if (item.UserId == Guid.Empty)
  41. {
  42. continue;
  43. }
  44. var user = _userManager.GetUserById(item.UserId);
  45. if (user != null)
  46. {
  47. var dto = _userManager.GetUserDto(user);
  48. item.UserPrimaryImageTag = dto.PrimaryImageTag;
  49. }
  50. }
  51. return result;
  52. }
  53. /// <inheritdoc />
  54. public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
  55. {
  56. return GetActivityLogEntries(minDate, null, startIndex, limit);
  57. }
  58. }
  59. }