2
0

ActivityManager.cs 2.2 KB

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