2020-07-01 01:44:41 +00:00
|
|
|
using System;
|
|
|
|
using Jellyfin.Data.Entities;
|
|
|
|
using Jellyfin.Data.Enums;
|
|
|
|
using MediaBrowser.Controller;
|
2019-11-17 22:05:39 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2019-01-13 19:24:58 +00:00
|
|
|
using MediaBrowser.Controller.Net;
|
2013-04-05 17:10:55 +00:00
|
|
|
using MediaBrowser.Model.Entities;
|
2016-10-25 19:02:04 +00:00
|
|
|
using MediaBrowser.Model.Services;
|
2019-11-17 22:05:39 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-04-05 17:10:55 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Class UpdateDisplayPreferences.
|
2013-04-05 17:10:55 +00:00
|
|
|
/// </summary>
|
2014-03-28 19:58:18 +00:00
|
|
|
[Route("/DisplayPreferences/{DisplayPreferencesId}", "POST", Summary = "Updates a user's display preferences for an item")]
|
2020-07-01 01:44:41 +00:00
|
|
|
public class UpdateDisplayPreferences : DisplayPreferencesDto, IReturnVoid
|
2013-04-05 17:10:55 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The id.</value>
|
2013-04-05 19:02:48 +00:00
|
|
|
[ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-09-06 05:13:43 +00:00
|
|
|
public string DisplayPreferencesId { get; set; }
|
2013-07-27 01:15:55 +00:00
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
2015-05-29 23:51:33 +00:00
|
|
|
public string UserId { get; set; }
|
2013-04-05 17:10:55 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 19:58:18 +00:00
|
|
|
[Route("/DisplayPreferences/{Id}", "GET", Summary = "Gets a user's display preferences for an item")]
|
2020-07-01 01:44:41 +00:00
|
|
|
public class GetDisplayPreferences : IReturn<DisplayPreferencesDto>
|
2013-04-05 17:10:55 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the id.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The id.</value>
|
2013-04-05 19:34:33 +00:00
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-09-06 05:13:43 +00:00
|
|
|
public string Id { get; set; }
|
2013-07-27 01:15:55 +00:00
|
|
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
2015-05-29 23:51:33 +00:00
|
|
|
public string UserId { get; set; }
|
2013-07-27 01:15:55 +00:00
|
|
|
|
|
|
|
[ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
|
|
public string Client { get; set; }
|
2013-04-05 17:10:55 +00:00
|
|
|
}
|
2019-01-07 23:27:46 +00:00
|
|
|
|
2013-04-05 17:10:55 +00:00
|
|
|
/// <summary>
|
2020-06-15 22:37:52 +00:00
|
|
|
/// Class DisplayPreferencesService.
|
2013-04-05 17:10:55 +00:00
|
|
|
/// </summary>
|
2014-07-02 04:57:18 +00:00
|
|
|
[Authenticated]
|
2013-04-05 17:10:55 +00:00
|
|
|
public class DisplayPreferencesService : BaseApiService
|
|
|
|
{
|
|
|
|
/// <summary>
|
2020-07-01 01:44:41 +00:00
|
|
|
/// The user manager.
|
2013-04-05 17:10:55 +00:00
|
|
|
/// </summary>
|
2020-07-01 01:44:41 +00:00
|
|
|
private readonly IDisplayPreferencesManager _displayPreferencesManager;
|
2013-04-05 17:10:55 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2013-04-05 19:34:33 +00:00
|
|
|
/// Initializes a new instance of the <see cref="DisplayPreferencesService" /> class.
|
2013-04-05 17:10:55 +00:00
|
|
|
/// </summary>
|
2013-04-05 19:34:33 +00:00
|
|
|
/// <param name="displayPreferencesManager">The display preferences manager.</param>
|
2019-11-17 22:05:39 +00:00
|
|
|
public DisplayPreferencesService(
|
|
|
|
ILogger<DisplayPreferencesService> logger,
|
|
|
|
IServerConfigurationManager serverConfigurationManager,
|
|
|
|
IHttpResultFactory httpResultFactory,
|
2020-07-01 01:44:41 +00:00
|
|
|
IDisplayPreferencesManager displayPreferencesManager)
|
2019-11-17 22:05:39 +00:00
|
|
|
: base(logger, serverConfigurationManager, httpResultFactory)
|
2013-04-05 17:10:55 +00:00
|
|
|
{
|
2013-04-05 19:34:33 +00:00
|
|
|
_displayPreferencesManager = displayPreferencesManager;
|
2013-04-05 17:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
public object Get(GetDisplayPreferences request)
|
|
|
|
{
|
2020-07-01 01:44:41 +00:00
|
|
|
var result = _displayPreferencesManager.GetDisplayPreferences(Guid.Parse(request.UserId), request.Client);
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dto = new DisplayPreferencesDto
|
|
|
|
{
|
|
|
|
Client = result.Client,
|
|
|
|
Id = result.UserId.ToString(),
|
|
|
|
ViewType = result.ViewType?.ToString(),
|
|
|
|
SortBy = result.SortBy,
|
|
|
|
SortOrder = result.SortOrder,
|
|
|
|
IndexBy = result.IndexBy?.ToString(),
|
|
|
|
RememberIndexing = result.RememberIndexing,
|
|
|
|
RememberSorting = result.RememberSorting,
|
|
|
|
ScrollDirection = result.ScrollDirection,
|
|
|
|
ShowBackdrop = result.ShowBackdrop,
|
|
|
|
ShowSidebar = result.ShowSidebar
|
|
|
|
};
|
2013-09-06 05:13:43 +00:00
|
|
|
|
2020-07-01 01:44:41 +00:00
|
|
|
foreach (var homeSection in result.HomeSections)
|
|
|
|
{
|
|
|
|
dto.CustomPrefs["homesection" + homeSection.Order] = homeSection.Type.ToString().ToLowerInvariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ToOptimizedResult(dto);
|
2013-04-05 17:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Posts the specified request.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
public void Post(UpdateDisplayPreferences request)
|
|
|
|
{
|
2020-07-01 01:44:41 +00:00
|
|
|
HomeSectionType[] defaults =
|
|
|
|
{
|
|
|
|
HomeSectionType.SmallLibraryTiles,
|
|
|
|
HomeSectionType.Resume,
|
|
|
|
HomeSectionType.ResumeAudio,
|
|
|
|
HomeSectionType.LiveTv,
|
|
|
|
HomeSectionType.NextUp,
|
|
|
|
HomeSectionType.LatestMedia,
|
|
|
|
HomeSectionType.None,
|
|
|
|
};
|
|
|
|
|
|
|
|
var prefs = _displayPreferencesManager.GetDisplayPreferences(Guid.Parse(request.UserId), request.Client);
|
|
|
|
|
|
|
|
prefs.ViewType = Enum.TryParse<ViewType>(request.ViewType, true, out var viewType) ? viewType : (ViewType?)null;
|
|
|
|
prefs.IndexBy = Enum.TryParse<IndexingKind>(request.IndexBy, true, out var indexBy) ? indexBy : (IndexingKind?)null;
|
|
|
|
prefs.ShowBackdrop = request.ShowBackdrop;
|
|
|
|
prefs.ShowSidebar = request.ShowSidebar;
|
|
|
|
prefs.SortBy = request.SortBy;
|
|
|
|
prefs.SortOrder = request.SortOrder;
|
|
|
|
prefs.RememberIndexing = request.RememberIndexing;
|
|
|
|
prefs.RememberSorting = request.RememberSorting;
|
|
|
|
prefs.ScrollDirection = request.ScrollDirection;
|
|
|
|
prefs.HomeSections.Clear();
|
|
|
|
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
if (request.CustomPrefs.TryGetValue("homesection" + i, out var homeSection))
|
|
|
|
{
|
|
|
|
prefs.HomeSections.Add(new HomeSection
|
|
|
|
{
|
|
|
|
Order = i,
|
|
|
|
Type = Enum.TryParse<HomeSectionType>(homeSection, true, out var type) ? type : defaults[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2013-04-05 17:10:55 +00:00
|
|
|
|
2020-07-01 01:44:41 +00:00
|
|
|
_displayPreferencesManager.SaveChanges(prefs);
|
2013-04-05 17:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|