aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jellyfin.Api/Controllers/DisplayPreferencesController.cs133
-rw-r--r--Jellyfin.Api/Controllers/MoviesController.cs1
-rw-r--r--Jellyfin.Api/Controllers/SubtitleController.cs15
-rw-r--r--Jellyfin.Api/Controllers/SuggestionsController.cs2
-rw-r--r--Jellyfin.Api/Controllers/TvShowsController.cs2
-rw-r--r--Jellyfin.Api/Controllers/UserController.cs2
-rw-r--r--Jellyfin.Api/Models/DisplayPreferencesDtos/DisplayPreferencesDto.cs106
-rw-r--r--MediaBrowser.Api/DisplayPreferencesService.cs189
8 files changed, 236 insertions, 214 deletions
diff --git a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
index 1255e6dab..62f6097f3 100644
--- a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
+++ b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
@@ -1,8 +1,12 @@
+using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
-using System.Threading;
+using System.Globalization;
+using System.Linq;
using Jellyfin.Api.Constants;
-using MediaBrowser.Controller.Persistence;
+using Jellyfin.Data.Entities;
+using Jellyfin.Data.Enums;
+using MediaBrowser.Controller;
using MediaBrowser.Model.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -17,15 +21,15 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)]
public class DisplayPreferencesController : BaseJellyfinApiController
{
- private readonly IDisplayPreferencesRepository _displayPreferencesRepository;
+ private readonly IDisplayPreferencesManager _displayPreferencesManager;
/// <summary>
/// Initializes a new instance of the <see cref="DisplayPreferencesController"/> class.
/// </summary>
- /// <param name="displayPreferencesRepository">Instance of <see cref="IDisplayPreferencesRepository"/> interface.</param>
- public DisplayPreferencesController(IDisplayPreferencesRepository displayPreferencesRepository)
+ /// <param name="displayPreferencesManager">Instance of <see cref="IDisplayPreferencesManager"/> interface.</param>
+ public DisplayPreferencesController(IDisplayPreferencesManager displayPreferencesManager)
{
- _displayPreferencesRepository = displayPreferencesRepository;
+ _displayPreferencesManager = displayPreferencesManager;
}
/// <summary>
@@ -38,12 +42,47 @@ namespace Jellyfin.Api.Controllers
/// <returns>An <see cref="OkResult"/> containing the display preferences on success, or a <see cref="NotFoundResult"/> if the display preferences could not be found.</returns>
[HttpGet("{displayPreferencesId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
- public ActionResult<DisplayPreferences> GetDisplayPreferences(
+ [SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "displayPreferencesId", Justification = "Imported from ServiceStack")]
+ public ActionResult<DisplayPreferencesDto> GetDisplayPreferences(
[FromRoute] string? displayPreferencesId,
- [FromQuery] [Required] string? userId,
+ [FromQuery] [Required] Guid userId,
[FromQuery] [Required] string? client)
{
- return _displayPreferencesRepository.GetDisplayPreferences(displayPreferencesId, userId, client);
+ var displayPreferences = _displayPreferencesManager.GetDisplayPreferences(userId, client);
+ var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(displayPreferences.UserId, Guid.Empty, displayPreferences.Client);
+
+ var dto = new DisplayPreferencesDto
+ {
+ Client = displayPreferences.Client,
+ Id = displayPreferences.UserId.ToString(),
+ ViewType = itemPreferences.ViewType.ToString(),
+ SortBy = itemPreferences.SortBy,
+ SortOrder = itemPreferences.SortOrder,
+ IndexBy = displayPreferences.IndexBy?.ToString(),
+ RememberIndexing = itemPreferences.RememberIndexing,
+ RememberSorting = itemPreferences.RememberSorting,
+ ScrollDirection = displayPreferences.ScrollDirection,
+ ShowBackdrop = displayPreferences.ShowBackdrop,
+ ShowSidebar = displayPreferences.ShowSidebar
+ };
+
+ foreach (var homeSection in displayPreferences.HomeSections)
+ {
+ dto.CustomPrefs["homesection" + homeSection.Order] = homeSection.Type.ToString().ToLowerInvariant();
+ }
+
+ foreach (var itemDisplayPreferences in _displayPreferencesManager.ListItemDisplayPreferences(displayPreferences.UserId, displayPreferences.Client))
+ {
+ dto.CustomPrefs["landing-" + itemDisplayPreferences.ItemId] = itemDisplayPreferences.ViewType.ToString().ToLowerInvariant();
+ }
+
+ dto.CustomPrefs["chromecastVersion"] = displayPreferences.ChromecastVersion.ToString().ToLowerInvariant();
+ dto.CustomPrefs["skipForwardLength"] = displayPreferences.SkipForwardLength.ToString(CultureInfo.InvariantCulture);
+ dto.CustomPrefs["skipBackLength"] = displayPreferences.SkipBackwardLength.ToString(CultureInfo.InvariantCulture);
+ dto.CustomPrefs["enableNextVideoInfoOverlay"] = displayPreferences.EnableNextVideoInfoOverlay.ToString(CultureInfo.InvariantCulture);
+ dto.CustomPrefs["tvhome"] = displayPreferences.TvHome;
+
+ return dto;
}
/// <summary>
@@ -60,15 +99,77 @@ namespace Jellyfin.Api.Controllers
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "displayPreferencesId", Justification = "Imported from ServiceStack")]
public ActionResult UpdateDisplayPreferences(
[FromRoute] string? displayPreferencesId,
- [FromQuery, BindRequired] string? userId,
+ [FromQuery, BindRequired] Guid userId,
[FromQuery, BindRequired] string? client,
- [FromBody, BindRequired] DisplayPreferences displayPreferences)
+ [FromBody, BindRequired] DisplayPreferencesDto displayPreferences)
{
- _displayPreferencesRepository.SaveDisplayPreferences(
- displayPreferences,
- userId,
- client,
- CancellationToken.None);
+ HomeSectionType[] defaults =
+ {
+ HomeSectionType.SmallLibraryTiles,
+ HomeSectionType.Resume,
+ HomeSectionType.ResumeAudio,
+ HomeSectionType.LiveTv,
+ HomeSectionType.NextUp,
+ HomeSectionType.LatestMedia, HomeSectionType.None,
+ };
+
+ var existingDisplayPreferences = _displayPreferencesManager.GetDisplayPreferences(userId, client);
+ existingDisplayPreferences.IndexBy = Enum.TryParse<IndexingKind>(displayPreferences.IndexBy, true, out var indexBy) ? indexBy : (IndexingKind?)null;
+ existingDisplayPreferences.ShowBackdrop = displayPreferences.ShowBackdrop;
+ existingDisplayPreferences.ShowSidebar = displayPreferences.ShowSidebar;
+
+ existingDisplayPreferences.ScrollDirection = displayPreferences.ScrollDirection;
+ existingDisplayPreferences.ChromecastVersion = displayPreferences.CustomPrefs.TryGetValue("chromecastVersion", out var chromecastVersion)
+ ? Enum.Parse<ChromecastVersion>(chromecastVersion, true)
+ : ChromecastVersion.Stable;
+ existingDisplayPreferences.EnableNextVideoInfoOverlay = displayPreferences.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enableNextVideoInfoOverlay)
+ ? bool.Parse(enableNextVideoInfoOverlay)
+ : true;
+ existingDisplayPreferences.SkipBackwardLength = displayPreferences.CustomPrefs.TryGetValue("skipBackLength", out var skipBackLength)
+ ? int.Parse(skipBackLength, CultureInfo.InvariantCulture)
+ : 10000;
+ existingDisplayPreferences.SkipForwardLength = displayPreferences.CustomPrefs.TryGetValue("skipForwardLength", out var skipForwardLength)
+ ? int.Parse(skipForwardLength, CultureInfo.InvariantCulture)
+ : 30000;
+ existingDisplayPreferences.DashboardTheme = displayPreferences.CustomPrefs.TryGetValue("dashboardTheme", out var theme)
+ ? theme
+ : string.Empty;
+ existingDisplayPreferences.TvHome = displayPreferences.CustomPrefs.TryGetValue("tvhome", out var home)
+ ? home
+ : string.Empty;
+ existingDisplayPreferences.HomeSections.Clear();
+
+ foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("homesection", StringComparison.OrdinalIgnoreCase)))
+ {
+ var order = int.Parse(key.AsSpan().Slice("homesection".Length));
+ if (!Enum.TryParse<HomeSectionType>(displayPreferences.CustomPrefs[key], true, out var type))
+ {
+ type = order < 7 ? defaults[order] : HomeSectionType.None;
+ }
+
+ existingDisplayPreferences.HomeSections.Add(new HomeSection { Order = order, Type = type });
+ }
+
+ foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("landing-", StringComparison.OrdinalIgnoreCase)))
+ {
+ var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, Guid.Parse(key.Substring("landing-".Length)), existingDisplayPreferences.Client);
+ itemPreferences.ViewType = Enum.Parse<ViewType>(displayPreferences.ViewType);
+ _displayPreferencesManager.SaveChanges(itemPreferences);
+ }
+
+ var itemPrefs = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, Guid.Empty, existingDisplayPreferences.Client);
+ itemPrefs.SortBy = displayPreferences.SortBy;
+ itemPrefs.SortOrder = displayPreferences.SortOrder;
+ itemPrefs.RememberIndexing = displayPreferences.RememberIndexing;
+ itemPrefs.RememberSorting = displayPreferences.RememberSorting;
+
+ if (Enum.TryParse<ViewType>(displayPreferences.ViewType, true, out var viewType))
+ {
+ itemPrefs.ViewType = viewType;
+ }
+
+ _displayPreferencesManager.SaveChanges(existingDisplayPreferences);
+ _displayPreferencesManager.SaveChanges(itemPrefs);
return NoContent();
}
diff --git a/Jellyfin.Api/Controllers/MoviesController.cs b/Jellyfin.Api/Controllers/MoviesController.cs
index a9af1a2c3..148d8a18e 100644
--- a/Jellyfin.Api/Controllers/MoviesController.cs
+++ b/Jellyfin.Api/Controllers/MoviesController.cs
@@ -5,6 +5,7 @@ using System.Linq;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Extensions;
using Jellyfin.Data.Entities;
+using Jellyfin.Data.Enums;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto;
diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs
index 1c38b8de5..b62ff80fc 100644
--- a/Jellyfin.Api/Controllers/SubtitleController.cs
+++ b/Jellyfin.Api/Controllers/SubtitleController.cs
@@ -276,11 +276,12 @@ namespace Jellyfin.Api.Controllers
throw new ArgumentException("segmentLength was not given, or it was given incorrectly. (It should be bigger than 0)");
}
- builder.AppendLine("#EXTM3U");
- builder.AppendLine("#EXT-X-TARGETDURATION:" + segmentLength.ToString(CultureInfo.InvariantCulture));
- builder.AppendLine("#EXT-X-VERSION:3");
- builder.AppendLine("#EXT-X-MEDIA-SEQUENCE:0");
- builder.AppendLine("#EXT-X-PLAYLIST-TYPE:VOD");
+ builder.AppendLine("#EXTM3U")
+ .Append("#EXT-X-TARGETDURATION:")
+ .AppendLine(segmentLength.ToString(CultureInfo.InvariantCulture))
+ .AppendLine("#EXT-X-VERSION:3")
+ .AppendLine("#EXT-X-MEDIA-SEQUENCE:0")
+ .AppendLine("#EXT-X-PLAYLIST-TYPE:VOD");
long positionTicks = 0;
@@ -291,7 +292,9 @@ namespace Jellyfin.Api.Controllers
var remaining = runtime - positionTicks;
var lengthTicks = Math.Min(remaining, segmentLengthTicks);
- builder.AppendLine("#EXTINF:" + TimeSpan.FromTicks(lengthTicks).TotalSeconds.ToString(CultureInfo.InvariantCulture) + ",");
+ builder.Append("#EXTINF:")
+ .Append(TimeSpan.FromTicks(lengthTicks).TotalSeconds.ToString(CultureInfo.InvariantCulture))
+ .AppendLine(",");
var endPositionTicks = Math.Min(runtime, positionTicks + segmentLengthTicks);
diff --git a/Jellyfin.Api/Controllers/SuggestionsController.cs b/Jellyfin.Api/Controllers/SuggestionsController.cs
index bf3c1e2b1..55759f316 100644
--- a/Jellyfin.Api/Controllers/SuggestionsController.cs
+++ b/Jellyfin.Api/Controllers/SuggestionsController.cs
@@ -2,11 +2,11 @@
using System.Linq;
using Jellyfin.Api.Extensions;
using Jellyfin.Api.Helpers;
+using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
diff --git a/Jellyfin.Api/Controllers/TvShowsController.cs b/Jellyfin.Api/Controllers/TvShowsController.cs
index d54bc10c0..508b5e24e 100644
--- a/Jellyfin.Api/Controllers/TvShowsController.cs
+++ b/Jellyfin.Api/Controllers/TvShowsController.cs
@@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Extensions;
+using Jellyfin.Data.Enums;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
@@ -11,7 +12,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
diff --git a/Jellyfin.Api/Controllers/UserController.cs b/Jellyfin.Api/Controllers/UserController.cs
index 8038ca044..ce0c9281b 100644
--- a/Jellyfin.Api/Controllers/UserController.cs
+++ b/Jellyfin.Api/Controllers/UserController.cs
@@ -455,7 +455,7 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<UserDto>> CreateUserByName([FromBody] CreateUserByName request)
{
- var newUser = _userManager.CreateUser(request.Name);
+ var newUser = await _userManager.CreateUserAsync(request.Name).ConfigureAwait(false);
// no need to authenticate password for new user
if (request.Password != null)
diff --git a/Jellyfin.Api/Models/DisplayPreferencesDtos/DisplayPreferencesDto.cs b/Jellyfin.Api/Models/DisplayPreferencesDtos/DisplayPreferencesDto.cs
new file mode 100644
index 000000000..249d828d3
--- /dev/null
+++ b/Jellyfin.Api/Models/DisplayPreferencesDtos/DisplayPreferencesDto.cs
@@ -0,0 +1,106 @@
+using System.Collections.Generic;
+using Jellyfin.Data.Enums;
+
+namespace Jellyfin.Api.Models.DisplayPreferencesDtos
+{
+ /// <summary>
+ /// Defines the display preferences for any item that supports them (usually Folders).
+ /// </summary>
+ public class DisplayPreferencesDto
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DisplayPreferencesDto" /> class.
+ /// </summary>
+ public DisplayPreferencesDto()
+ {
+ RememberIndexing = false;
+ PrimaryImageHeight = 250;
+ PrimaryImageWidth = 250;
+ ShowBackdrop = true;
+ CustomPrefs = new Dictionary<string, string>();
+ }
+
+ /// <summary>
+ /// Gets or sets the user id.
+ /// </summary>
+ /// <value>The user id.</value>
+ public string? Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the type of the view.
+ /// </summary>
+ /// <value>The type of the view.</value>
+ public string? ViewType { get; set; }
+
+ /// <summary>
+ /// Gets or sets the sort by.
+ /// </summary>
+ /// <value>The sort by.</value>
+ public string? SortBy { get; set; }
+
+ /// <summary>
+ /// Gets or sets the index by.
+ /// </summary>
+ /// <value>The index by.</value>
+ public string? IndexBy { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether [remember indexing].
+ /// </summary>
+ /// <value><c>true</c> if [remember indexing]; otherwise, <c>false</c>.</value>
+ public bool RememberIndexing { get; set; }
+
+ /// <summary>
+ /// Gets or sets the height of the primary image.
+ /// </summary>
+ /// <value>The height of the primary image.</value>
+ public int PrimaryImageHeight { get; set; }
+
+ /// <summary>
+ /// Gets or sets the width of the primary image.
+ /// </summary>
+ /// <value>The width of the primary image.</value>
+ public int PrimaryImageWidth { get; set; }
+
+ /// <summary>
+ /// Gets the custom prefs.
+ /// </summary>
+ /// <value>The custom prefs.</value>
+ public Dictionary<string, string> CustomPrefs { get; }
+
+ /// <summary>
+ /// Gets or sets the scroll direction.
+ /// </summary>
+ /// <value>The scroll direction.</value>
+ public ScrollDirection ScrollDirection { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether to show backdrops on this item.
+ /// </summary>
+ /// <value><c>true</c> if showing backdrops; otherwise, <c>false</c>.</value>
+ public bool ShowBackdrop { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether [remember sorting].
+ /// </summary>
+ /// <value><c>true</c> if [remember sorting]; otherwise, <c>false</c>.</value>
+ public bool RememberSorting { get; set; }
+
+ /// <summary>
+ /// Gets or sets the sort order.
+ /// </summary>
+ /// <value>The sort order.</value>
+ public SortOrder SortOrder { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether [show sidebar].
+ /// </summary>
+ /// <value><c>true</c> if [show sidebar]; otherwise, <c>false</c>.</value>
+ public bool ShowSidebar { get; set; }
+
+ /// <summary>
+ /// Gets or sets the client.
+ /// </summary>
+ public string? Client { get; set; }
+ }
+}
diff --git a/MediaBrowser.Api/DisplayPreferencesService.cs b/MediaBrowser.Api/DisplayPreferencesService.cs
deleted file mode 100644
index 559b71efc..000000000
--- a/MediaBrowser.Api/DisplayPreferencesService.cs
+++ /dev/null
@@ -1,189 +0,0 @@
-using System;
-using System.Linq;
-using Jellyfin.Data.Entities;
-using Jellyfin.Data.Enums;
-using MediaBrowser.Controller;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api
-{
- /// <summary>
- /// Class UpdateDisplayPreferences.
- /// </summary>
- [Route("/DisplayPreferences/{DisplayPreferencesId}", "POST", Summary = "Updates a user's display preferences for an item")]
- public class UpdateDisplayPreferences : DisplayPreferencesDto, IReturnVoid
- {
- /// <summary>
- /// Gets or sets the id.
- /// </summary>
- /// <value>The id.</value>
- [ApiMember(Name = "DisplayPreferencesId", Description = "DisplayPreferences Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
- public string DisplayPreferencesId { get; set; }
-
- [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
- public string UserId { get; set; }
- }
-
- [Route("/DisplayPreferences/{Id}", "GET", Summary = "Gets a user's display preferences for an item")]
- public class GetDisplayPreferences : IReturn<DisplayPreferencesDto>
- {
- /// <summary>
- /// Gets or sets the id.
- /// </summary>
- /// <value>The id.</value>
- [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
- public string Id { get; set; }
-
- [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
- public string UserId { get; set; }
-
- [ApiMember(Name = "Client", Description = "Client", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
- public string Client { get; set; }
- }
-
- /// <summary>
- /// Class DisplayPreferencesService.
- /// </summary>
- [Authenticated]
- public class DisplayPreferencesService : BaseApiService
- {
- /// <summary>
- /// The display preferences manager.
- /// </summary>
- private readonly IDisplayPreferencesManager _displayPreferencesManager;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="DisplayPreferencesService" /> class.
- /// </summary>
- /// <param name="displayPreferencesManager">The display preferences manager.</param>
- public DisplayPreferencesService(
- ILogger<DisplayPreferencesService> logger,
- IServerConfigurationManager serverConfigurationManager,
- IHttpResultFactory httpResultFactory,
- IDisplayPreferencesManager displayPreferencesManager)
- : base(logger, serverConfigurationManager, httpResultFactory)
- {
- _displayPreferencesManager = displayPreferencesManager;
- }
-
- /// <summary>
- /// Gets the specified request.
- /// </summary>
- /// <param name="request">The request.</param>
- public object Get(GetDisplayPreferences request)
- {
- var displayPreferences = _displayPreferencesManager.GetDisplayPreferences(Guid.Parse(request.UserId), request.Client);
- var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(displayPreferences.UserId, Guid.Empty, displayPreferences.Client);
-
- var dto = new DisplayPreferencesDto
- {
- Client = displayPreferences.Client,
- Id = displayPreferences.UserId.ToString(),
- ViewType = itemPreferences.ViewType.ToString(),
- SortBy = itemPreferences.SortBy,
- SortOrder = itemPreferences.SortOrder,
- IndexBy = displayPreferences.IndexBy?.ToString(),
- RememberIndexing = itemPreferences.RememberIndexing,
- RememberSorting = itemPreferences.RememberSorting,
- ScrollDirection = displayPreferences.ScrollDirection,
- ShowBackdrop = displayPreferences.ShowBackdrop,
- ShowSidebar = displayPreferences.ShowSidebar
- };
-
- foreach (var homeSection in displayPreferences.HomeSections)
- {
- dto.CustomPrefs["homesection" + homeSection.Order] = homeSection.Type.ToString().ToLowerInvariant();
- }
-
- foreach (var itemDisplayPreferences in _displayPreferencesManager.ListItemDisplayPreferences(displayPreferences.UserId, displayPreferences.Client))
- {
- dto.CustomPrefs["landing-" + itemDisplayPreferences.ItemId] = itemDisplayPreferences.ViewType.ToString().ToLowerInvariant();
- }
-
- dto.CustomPrefs["chromecastVersion"] = displayPreferences.ChromecastVersion.ToString().ToLowerInvariant();
- dto.CustomPrefs["skipForwardLength"] = displayPreferences.SkipForwardLength.ToString();
- dto.CustomPrefs["skipBackLength"] = displayPreferences.SkipBackwardLength.ToString();
- dto.CustomPrefs["enableNextVideoInfoOverlay"] = displayPreferences.EnableNextVideoInfoOverlay.ToString();
- dto.CustomPrefs["tvhome"] = displayPreferences.TvHome;
-
- return ToOptimizedResult(dto);
- }
-
- /// <summary>
- /// Posts the specified request.
- /// </summary>
- /// <param name="request">The request.</param>
- public void Post(UpdateDisplayPreferences request)
- {
- 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.IndexBy = Enum.TryParse<IndexingKind>(request.IndexBy, true, out var indexBy) ? indexBy : (IndexingKind?)null;
- prefs.ShowBackdrop = request.ShowBackdrop;
- prefs.ShowSidebar = request.ShowSidebar;
-
- prefs.ScrollDirection = request.ScrollDirection;
- prefs.ChromecastVersion = request.CustomPrefs.TryGetValue("chromecastVersion", out var chromecastVersion)
- ? Enum.Parse<ChromecastVersion>(chromecastVersion, true)
- : ChromecastVersion.Stable;
- prefs.EnableNextVideoInfoOverlay = request.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enableNextVideoInfoOverlay)
- ? bool.Parse(enableNextVideoInfoOverlay)
- : true;
- prefs.SkipBackwardLength = request.CustomPrefs.TryGetValue("skipBackLength", out var skipBackLength) ? int.Parse(skipBackLength) : 10000;
- prefs.SkipForwardLength = request.CustomPrefs.TryGetValue("skipForwardLength", out var skipForwardLength) ? int.Parse(skipForwardLength) : 30000;
- prefs.DashboardTheme = request.CustomPrefs.TryGetValue("dashboardTheme", out var theme) ? theme : string.Empty;
- prefs.TvHome = request.CustomPrefs.TryGetValue("tvhome", out var home) ? home : string.Empty;
- prefs.HomeSections.Clear();
-
- foreach (var key in request.CustomPrefs.Keys.Where(key => key.StartsWith("homesection")))
- {
- var order = int.Parse(key.AsSpan().Slice("homesection".Length));
- if (!Enum.TryParse<HomeSectionType>(request.CustomPrefs[key], true, out var type))
- {
- type = order < 7 ? defaults[order] : HomeSectionType.None;
- }
-
- prefs.HomeSections.Add(new HomeSection
- {
- Order = order,
- Type = type
- });
- }
-
- foreach (var key in request.CustomPrefs.Keys.Where(key => key.StartsWith("landing-")))
- {
- var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(prefs.UserId, Guid.Parse(key.Substring("landing-".Length)), prefs.Client);
- itemPreferences.ViewType = Enum.Parse<ViewType>(request.ViewType);
- _displayPreferencesManager.SaveChanges(itemPreferences);
- }
-
- var itemPrefs = _displayPreferencesManager.GetItemDisplayPreferences(prefs.UserId, Guid.Empty, prefs.Client);
- itemPrefs.SortBy = request.SortBy;
- itemPrefs.SortOrder = request.SortOrder;
- itemPrefs.RememberIndexing = request.RememberIndexing;
- itemPrefs.RememberSorting = request.RememberSorting;
-
- if (Enum.TryParse<ViewType>(request.ViewType, true, out var viewType))
- {
- itemPrefs.ViewType = viewType;
- }
-
- _displayPreferencesManager.SaveChanges(prefs);
- _displayPreferencesManager.SaveChanges(itemPrefs);
- }
- }
-}