Beispiel #1
0
        public ActionResult <DisplayPreferencesDto> GetDisplayPreferences(
            [FromRoute, Required] string displayPreferencesId,
            [FromQuery, Required] Guid userId,
            [FromQuery, Required] string client)
        {
            if (!Guid.TryParse(displayPreferencesId, out var itemId))
            {
                itemId = displayPreferencesId.GetMD5();
            }

            var displayPreferences = _displayPreferencesManager.GetDisplayPreferences(userId, itemId, client);
            var itemPreferences    = _displayPreferencesManager.GetItemDisplayPreferences(displayPreferences.UserId, itemId, displayPreferences.Client);

            itemPreferences.ItemId = itemId;

            var dto = new DisplayPreferencesDto
            {
                Client           = displayPreferences.Client,
                Id               = displayPreferences.ItemId.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();
            }

            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;
            dto.CustomPrefs["dashboardTheme"] = displayPreferences.DashboardTheme;

            // Load all custom display preferences
            var customDisplayPreferences = _displayPreferencesManager.ListCustomItemDisplayPreferences(displayPreferences.UserId, itemId, displayPreferences.Client);

            if (customDisplayPreferences != null)
            {
                foreach (var(key, value) in customDisplayPreferences)
                {
                    dto.CustomPrefs.TryAdd(key, value);
                }
            }

            // This will essentially be a noop if no changes have been made, but new prefs must be saved at least.
            _displayPreferencesManager.SaveChanges();

            return(dto);
        }
        public ActionResult <DisplayPreferencesDto> GetDisplayPreferences(
            [FromRoute, Required] string displayPreferencesId,
            [FromQuery, Required] Guid userId,
            [FromQuery, Required] string 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;

            // This will essentially be a noop if no changes have been made, but new prefs must be saved at least.
            _displayPreferencesManager.SaveChanges();

            return(dto);
        }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        public ActionResult UpdateDisplayPreferences(
            [FromRoute, Required] string displayPreferencesId,
            [FromQuery, Required] Guid userId,
            [FromQuery, Required] string client,
            [FromBody, Required] DisplayPreferencesDto displayPreferences)
        {
            HomeSectionType[] defaults =
            {
                HomeSectionType.SmallLibraryTiles,
                HomeSectionType.Resume,
                HomeSectionType.ResumeAudio,
                HomeSectionType.LiveTv,
                HomeSectionType.NextUp,
                HomeSectionType.LatestMedia,      HomeSectionType.None,
            };

            if (!Guid.TryParse(displayPreferencesId, out var itemId))
            {
                itemId = displayPreferencesId.GetMD5();
            }

            var existingDisplayPreferences = _displayPreferencesManager.GetDisplayPreferences(userId, itemId, 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;
            displayPreferences.CustomPrefs.Remove("chromecastVersion");

            existingDisplayPreferences.EnableNextVideoInfoOverlay = displayPreferences.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enableNextVideoInfoOverlay)
                ? bool.Parse(enableNextVideoInfoOverlay)
                : true;
            displayPreferences.CustomPrefs.Remove("enableNextVideoInfoOverlay");

            existingDisplayPreferences.SkipBackwardLength = displayPreferences.CustomPrefs.TryGetValue("skipBackLength", out var skipBackLength)
                ? int.Parse(skipBackLength, CultureInfo.InvariantCulture)
                : 10000;
            displayPreferences.CustomPrefs.Remove("skipBackLength");

            existingDisplayPreferences.SkipForwardLength = displayPreferences.CustomPrefs.TryGetValue("skipForwardLength", out var skipForwardLength)
                ? int.Parse(skipForwardLength, CultureInfo.InvariantCulture)
                : 30000;
            displayPreferences.CustomPrefs.Remove("skipForwardLength");

            existingDisplayPreferences.DashboardTheme = displayPreferences.CustomPrefs.TryGetValue("dashboardTheme", out var theme)
                ? theme
                : string.Empty;
            displayPreferences.CustomPrefs.Remove("dashboardTheme");

            existingDisplayPreferences.TvHome = displayPreferences.CustomPrefs.TryGetValue("tvhome", out var home)
                ? home
                : string.Empty;
            displayPreferences.CustomPrefs.Remove("tvhome");

            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;
                }

                displayPreferences.CustomPrefs.Remove(key);
                existingDisplayPreferences.HomeSections.Add(new HomeSection {
                    Order = order, Type = type
                });
            }

            foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("landing-", StringComparison.OrdinalIgnoreCase)))
            {
                if (Guid.TryParse(key.AsSpan().Slice("landing-".Length), out var preferenceId))
                {
                    var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, preferenceId, existingDisplayPreferences.Client);
                    itemPreferences.ViewType = Enum.Parse <ViewType>(displayPreferences.ViewType);
                    displayPreferences.CustomPrefs.Remove(key);
                }
            }

            var itemPrefs = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, itemId, existingDisplayPreferences.Client);

            itemPrefs.SortBy           = displayPreferences.SortBy;
            itemPrefs.SortOrder        = displayPreferences.SortOrder;
            itemPrefs.RememberIndexing = displayPreferences.RememberIndexing;
            itemPrefs.RememberSorting  = displayPreferences.RememberSorting;
            itemPrefs.ItemId           = itemId;

            if (Enum.TryParse <ViewType>(displayPreferences.ViewType, true, out var viewType))
            {
                itemPrefs.ViewType = viewType;
            }

            // Set all remaining custom preferences.
            _displayPreferencesManager.SetCustomItemDisplayPreferences(userId, itemId, existingDisplayPreferences.Client, displayPreferences.CustomPrefs);
            _displayPreferencesManager.SaveChanges();

            return(NoContent());
        }