diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2020-12-04 20:05:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-04 20:05:04 -0500 |
| commit | 4e6584c345a45c3ac46ac3aa95d39472eb6fbcbf (patch) | |
| tree | b40c4f5fc23e6a818ed8c48ac4088dff77cddb35 /Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | |
| parent | 3980b5ce9f6a6cbd3c0eed5316f9f0758e0fa542 (diff) | |
| parent | 76250a88959fa54646b45bbbb412dfeda30d556d (diff) | |
Merge pull request #4652 from crobibero/display-preferences
Add support for custom item display preferences
Diffstat (limited to 'Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs index 76f943385..c8a589cab 100644 --- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs +++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs @@ -26,16 +26,16 @@ namespace Jellyfin.Server.Implementations.Users } /// <inheritdoc /> - public DisplayPreferences GetDisplayPreferences(Guid userId, string client) + public DisplayPreferences GetDisplayPreferences(Guid userId, Guid itemId, string client) { var prefs = _dbContext.DisplayPreferences .Include(pref => pref.HomeSections) .FirstOrDefault(pref => - pref.UserId == userId && string.Equals(pref.Client, client)); + pref.UserId == userId && string.Equals(pref.Client, client) && pref.ItemId == itemId); if (prefs == null) { - prefs = new DisplayPreferences(userId, client); + prefs = new DisplayPreferences(userId, itemId, client); _dbContext.DisplayPreferences.Add(prefs); } @@ -67,6 +67,34 @@ namespace Jellyfin.Server.Implementations.Users } /// <inheritdoc /> + public IDictionary<string, string> ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client) + { + return _dbContext.CustomItemDisplayPreferences + .AsQueryable() + .Where(prefs => prefs.UserId == userId + && prefs.ItemId == itemId + && string.Equals(prefs.Client, client)) + .ToDictionary(prefs => prefs.Key, prefs => prefs.Value); + } + + /// <inheritdoc /> + public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary<string, string> customPreferences) + { + var existingPrefs = _dbContext.CustomItemDisplayPreferences + .AsQueryable() + .Where(prefs => prefs.UserId == userId + && prefs.ItemId == itemId + && string.Equals(prefs.Client, client)); + _dbContext.CustomItemDisplayPreferences.RemoveRange(existingPrefs); + + foreach (var (key, value) in customPreferences) + { + _dbContext.CustomItemDisplayPreferences + .Add(new CustomItemDisplayPreferences(userId, itemId, client, key, value)); + } + } + + /// <inheritdoc /> public void SaveChanges() { _dbContext.SaveChanges(); |
