/// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(UpdateDisplayPreferences request)
        {
            // Serialize to json and then back so that the core doesn't see the request dto type
            var displayPreferences = _jsonSerializer.DeserializeFromString <DisplayPreferences>(_jsonSerializer.SerializeToString(request));

            _displayPreferencesManager.SaveDisplayPreferences(displayPreferences, request.UserId, request.Client, CancellationToken.None);
        }
Beispiel #2
0
        /// <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);
        }