Skip to content

Commit

Permalink
Mayhaps working
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeViper committed Feb 4, 2025
1 parent 3a1de80 commit 8d4a089
Show file tree
Hide file tree
Showing 11 changed files with 2,351 additions and 376 deletions.
2,146 changes: 2,146 additions & 0 deletions Valour/Database/Migrations/20250204180538_PushNotif2.Designer.cs

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions Valour/Database/Migrations/20250204180538_PushNotif2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Valour.Database.Migrations
{
/// <inheritdoc />
public partial class PushNotif2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_notification_subscriptions_planet_members_member_id",
table: "notification_subscriptions");

migrationBuilder.DropForeignKey(
name: "FK_notification_subscriptions_planets_planet_id",
table: "notification_subscriptions");

migrationBuilder.DropIndex(
name: "IX_notification_subscriptions_member_id",
table: "notification_subscriptions");

migrationBuilder.DropIndex(
name: "IX_notification_subscriptions_planet_id",
table: "notification_subscriptions");

migrationBuilder.DropColumn(
name: "member_id",
table: "notification_subscriptions");

migrationBuilder.DropColumn(
name: "planet_id",
table: "notification_subscriptions");

migrationBuilder.RenameColumn(
name: "role_hash_key",
table: "notification_subscriptions",
newName: "PlanetMemberId");

migrationBuilder.CreateIndex(
name: "IX_notification_subscriptions_PlanetMemberId",
table: "notification_subscriptions",
column: "PlanetMemberId");

migrationBuilder.AddForeignKey(
name: "FK_notification_subscriptions_planet_members_PlanetMemberId",
table: "notification_subscriptions",
column: "PlanetMemberId",
principalTable: "planet_members",
principalColumn: "id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_notification_subscriptions_planet_members_PlanetMemberId",
table: "notification_subscriptions");

migrationBuilder.DropIndex(
name: "IX_notification_subscriptions_PlanetMemberId",
table: "notification_subscriptions");

migrationBuilder.RenameColumn(
name: "PlanetMemberId",
table: "notification_subscriptions",
newName: "role_hash_key");

migrationBuilder.AddColumn<long>(
name: "member_id",
table: "notification_subscriptions",
type: "bigint",
nullable: true);

migrationBuilder.AddColumn<long>(
name: "planet_id",
table: "notification_subscriptions",
type: "bigint",
nullable: true);

migrationBuilder.CreateIndex(
name: "IX_notification_subscriptions_member_id",
table: "notification_subscriptions",
column: "member_id",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_notification_subscriptions_planet_id",
table: "notification_subscriptions",
column: "planet_id");

migrationBuilder.AddForeignKey(
name: "FK_notification_subscriptions_planet_members_member_id",
table: "notification_subscriptions",
column: "member_id",
principalTable: "planet_members",
principalColumn: "id");

migrationBuilder.AddForeignKey(
name: "FK_notification_subscriptions_planets_planet_id",
table: "notification_subscriptions",
column: "planet_id",
principalTable: "planets",
principalColumn: "id");
}
}
}
32 changes: 5 additions & 27 deletions Valour/Database/Migrations/ValourDbModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,28 +1047,16 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("text")
.HasColumnName("key");

b.Property<long?>("MemberId")
.HasColumnType("bigint")
.HasColumnName("member_id");

b.Property<long?>("PlanetId")
.HasColumnType("bigint")
.HasColumnName("planet_id");

b.Property<long?>("RoleHashKey")
.HasColumnType("bigint")
.HasColumnName("role_hash_key");
b.Property<long?>("PlanetMemberId")
.HasColumnType("bigint");

b.Property<long>("UserId")
.HasColumnType("bigint")
.HasColumnName("user_id");

b.HasKey("Id");

b.HasIndex("MemberId")
.IsUnique();

b.HasIndex("PlanetId");
b.HasIndex("PlanetMemberId");

b.HasIndex("UserId");

Expand Down Expand Up @@ -1955,24 +1943,16 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("Valour.Database.PushNotificationSubscription", b =>
{
b.HasOne("Valour.Database.PlanetMember", "Member")
b.HasOne("Valour.Database.PlanetMember", null)
.WithMany("PushSubscriptions")
.HasForeignKey("MemberId");

b.HasOne("Valour.Database.Planet", "Planet")
.WithMany("NotificationSubscriptions")
.HasForeignKey("PlanetId");
.HasForeignKey("PlanetMemberId");

b.HasOne("Valour.Database.User", "User")
.WithMany("NotificationSubscriptions")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.Navigation("Member");

b.Navigation("Planet");

b.Navigation("User");
});

Expand Down Expand Up @@ -2111,8 +2091,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("Messages");

b.Navigation("NotificationSubscriptions");

b.Navigation("RoleMembers");

b.Navigation("Roles");
Expand Down
3 changes: 0 additions & 3 deletions Valour/Database/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class Planet : ISharedPlanet
[InverseProperty("Planet")]
public virtual ICollection<PlanetInvite> Invites { get; set; }

[InverseProperty("Planet")]
public virtual ICollection<PushNotificationSubscription> NotificationSubscriptions { get; set; }

public virtual ICollection<Message> Messages { get; set; }

public virtual ICollection<UserChannelState> UserChannelStates { get; set; }
Expand Down
38 changes: 1 addition & 37 deletions Valour/Database/PushNotificationSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class PushNotificationSubscription : ISharedPushNotificationSubscription
///////////////////////////

public virtual User? User { get; set; }
public virtual PlanetMember? Member { get; set; }
public virtual Planet? Planet { get; set; }

///////////////////////
// Entity Properties //
Expand All @@ -37,20 +35,8 @@ public class PushNotificationSubscription : ISharedPushNotificationSubscription
public long UserId { get; set; }

/// <summary>
/// The Id of the planet (if any) this subscription is for
/// The endpoint of the subscription
/// </summary>
public long? PlanetId { get; set; }

/// <summary>
/// The Id of the member this subscription is for, if a planet subscription.
/// </summary>
public long? MemberId { get; set; }

/// <summary>
/// The RoleHashKey the planet member is subscribed to. Should only be used for planet subscriptions.
/// </summary>
public long? RoleHashKey { get; set; }

public required string Endpoint { get; set; }

public string? Key { get; set; }
Expand Down Expand Up @@ -85,15 +71,6 @@ public static void SetUpDbModel(ModelBuilder builder)
e.Property(x => x.UserId)
.HasColumnName("user_id");

e.Property(x => x.PlanetId)
.HasColumnName("planet_id");

e.Property(x => x.MemberId)
.HasColumnName("member_id");

e.Property(x => x.RoleHashKey)
.HasColumnName("role_hash_key");

e.Property(x => x.Key)
.HasColumnName("key");

Expand All @@ -109,21 +86,8 @@ public static void SetUpDbModel(ModelBuilder builder)
.WithMany(x => x.NotificationSubscriptions)
.HasForeignKey(x => x.UserId);

e.HasOne(x => x.Planet)
.WithMany(x => x.NotificationSubscriptions)
.HasForeignKey(x => x.PlanetId);

e.HasOne(x => x.Member)
.WithMany(x => x.PushSubscriptions)
.HasForeignKey(x => x.MemberId);

// Indices

e.HasIndex(x => x.UserId);
e.HasIndex(x => x.PlanetId);

e.HasIndex(x => x.MemberId)
.IsUnique();
});
}
}
6 changes: 0 additions & 6 deletions Valour/Server/Mapping/NotificationSubscriptionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ public static PushNotificationSubscription ToModel(this Valour.Database.PushNoti
{
Id = subscription.Id,
UserId = subscription.UserId,
PlanetId = subscription.PlanetId,
MemberId = subscription.MemberId,
RoleHashKey = subscription.RoleHashKey,
Endpoint = subscription.Endpoint,
Key = subscription.Key,
Auth = subscription.Auth,
Expand All @@ -30,9 +27,6 @@ public static Valour.Database.PushNotificationSubscription ToDatabase(this PushN
{
Id = subscription.Id,
UserId = subscription.UserId,
PlanetId = subscription.PlanetId,
MemberId = subscription.MemberId,
RoleHashKey = subscription.RoleHashKey,
Endpoint = subscription.Endpoint,
Key = subscription.Key,
Auth = subscription.Auth,
Expand Down
8 changes: 0 additions & 8 deletions Valour/Server/Services/PlanetRoleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,6 @@ await _db.PermissionsNodes.Where(x => x.RoleId == roleId)

await _db.PlanetMembers.Where(x => x.RoleHashKey == oldHashKey)
.ExecuteUpdateAsync(x => x.SetProperty(p => p.RoleHashKey, newHashKey));

// We also need to let the Notification Sub Worker know to update tags
// This is because the role hash key is used in the notification tags
await _pushNotificationWorker.QueueNotificationAction(new PushNotificationRoleHashChange()
{
OldHash = oldHashKey,
NewHash = newHashKey
});
}

await _db.PlanetRoleMembers.Where(x => x.RoleId == roleId)
Expand Down
Loading

0 comments on commit 8d4a089

Please sign in to comment.