mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 14:28:46 +01:00
Add ItemId to all display preferences
This commit is contained in:
@@ -153,7 +153,7 @@ namespace Jellyfin.Server.Implementations
|
||||
.IsUnique(false);
|
||||
|
||||
modelBuilder.Entity<DisplayPreferences>()
|
||||
.HasIndex(entity => new { entity.UserId, entity.Client })
|
||||
.HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client })
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<CustomItemDisplayPreferences>()
|
||||
@@ -161,7 +161,7 @@ namespace Jellyfin.Server.Implementations
|
||||
.IsUnique(false);
|
||||
|
||||
modelBuilder.Entity<CustomItemDisplayPreferences>()
|
||||
.HasIndex(entity => new { entity.UserId, entity.Client, entity.Key })
|
||||
.HasIndex(entity => new { entity.UserId, entity.ItemId, entity.Client, entity.Key })
|
||||
.IsUnique();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Jellyfin.Server.Implementations.Migrations
|
||||
{
|
||||
[DbContext(typeof(JellyfinDb))]
|
||||
[Migration("20201203203707_AddCustomDisplayPreferences")]
|
||||
[Migration("20201204223655_AddCustomDisplayPreferences")]
|
||||
partial class AddCustomDisplayPreferences
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -102,6 +102,9 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("ItemId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -117,7 +120,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("UserId", "Client", "Key")
|
||||
b.HasIndex("UserId", "ItemId", "Client", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("CustomItemDisplayPreferences");
|
||||
@@ -147,6 +150,9 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
b.Property<int?>("IndexBy")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("ItemId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ScrollDirection")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
@@ -173,7 +179,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("UserId", "Client")
|
||||
b.HasIndex("UserId", "ItemId", "Client")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DisplayPreferences");
|
||||
@@ -9,6 +9,11 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DisplayPreferences_UserId_Client",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "MaxActiveSessions",
|
||||
schema: "jellyfin",
|
||||
@@ -20,6 +25,14 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
oldType: "INTEGER",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "ItemId",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CustomItemDisplayPreferences",
|
||||
schema: "jellyfin",
|
||||
@@ -28,6 +41,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
UserId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
ItemId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Client = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
|
||||
Key = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Value = table.Column<string>(type: "TEXT", nullable: false)
|
||||
@@ -37,6 +51,13 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
table.PrimaryKey("PK_CustomItemDisplayPreferences", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DisplayPreferences_UserId_ItemId_Client",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences",
|
||||
columns: new[] { "UserId", "ItemId", "Client" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CustomItemDisplayPreferences_UserId",
|
||||
schema: "jellyfin",
|
||||
@@ -44,10 +65,10 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_CustomItemDisplayPreferences_UserId_Client_Key",
|
||||
name: "IX_CustomItemDisplayPreferences_UserId_ItemId_Client_Key",
|
||||
schema: "jellyfin",
|
||||
table: "CustomItemDisplayPreferences",
|
||||
columns: new[] { "UserId", "Client", "Key" },
|
||||
columns: new[] { "UserId", "ItemId", "Client", "Key" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
@@ -57,6 +78,16 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
name: "CustomItemDisplayPreferences",
|
||||
schema: "jellyfin");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DisplayPreferences_UserId_ItemId_Client",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ItemId",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "MaxActiveSessions",
|
||||
schema: "jellyfin",
|
||||
@@ -65,6 +96,13 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
nullable: true,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "INTEGER");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DisplayPreferences_UserId_Client",
|
||||
schema: "jellyfin",
|
||||
table: "DisplayPreferences",
|
||||
columns: new[] { "UserId", "Client" },
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,9 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("ItemId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
@@ -114,7 +117,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("UserId", "Client", "Key")
|
||||
b.HasIndex("UserId", "ItemId", "Client", "Key")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("CustomItemDisplayPreferences");
|
||||
@@ -144,6 +147,9 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
b.Property<int?>("IndexBy")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<Guid>("ItemId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ScrollDirection")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
@@ -170,7 +176,7 @@ namespace Jellyfin.Server.Implementations.Migrations
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("UserId", "Client")
|
||||
b.HasIndex("UserId", "ItemId", "Client")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("DisplayPreferences");
|
||||
|
||||
@@ -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,26 +67,30 @@ namespace Jellyfin.Server.Implementations.Users
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDictionary<string, string> ListCustomItemDisplayPreferences(Guid userId, string client)
|
||||
public IDictionary<string, string> ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client)
|
||||
{
|
||||
return _dbContext.CustomItemDisplayPreferences
|
||||
.AsQueryable()
|
||||
.Where(prefs => prefs.UserId == userId && string.Equals(prefs.Client, client))
|
||||
.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, string client, Dictionary<string, string> customPreferences)
|
||||
public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary<string, string> customPreferences)
|
||||
{
|
||||
var existingPrefs = _dbContext.CustomItemDisplayPreferences
|
||||
.AsQueryable()
|
||||
.Where(prefs => prefs.UserId == userId && string.Equals(prefs.Client, client));
|
||||
.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, client, key, value));
|
||||
.Add(new CustomItemDisplayPreferences(userId, itemId, client, key, value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user