🗃️ Update schema to clean up unused code
This commit is contained in:
2497
DysonNetwork.Pass/Migrations/20251022164134_RemoveChatRoom.Designer.cs
generated
Normal file
2497
DysonNetwork.Pass/Migrations/20251022164134_RemoveChatRoom.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using DysonNetwork.Shared.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Pass.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemoveChatRoom : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "sn_chat_member");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "sn_chat_room");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "sn_chat_room",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
background = table.Column<SnCloudFileReferenceObject>(type: "jsonb", nullable: true),
|
||||||
|
background_id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||||
|
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
description = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: true),
|
||||||
|
is_community = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
is_public = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
name = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
|
||||||
|
picture = table.Column<SnCloudFileReferenceObject>(type: "jsonb", nullable: true),
|
||||||
|
picture_id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||||
|
realm_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||||
|
sn_realm_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||||
|
type = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("pk_sn_chat_room", x => x.id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "fk_sn_chat_room_realms_sn_realm_id",
|
||||||
|
column: x => x.sn_realm_id,
|
||||||
|
principalTable: "realms",
|
||||||
|
principalColumn: "id");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "sn_chat_member",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
chat_room_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
account_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
break_until = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
is_bot = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
joined_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
last_read_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
leave_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
nick = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
|
||||||
|
notify = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
role = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
timeout_cause = table.Column<ChatTimeoutCause>(type: "jsonb", nullable: true),
|
||||||
|
timeout_until = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("pk_sn_chat_member", x => x.id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "fk_sn_chat_member_sn_chat_room_chat_room_id",
|
||||||
|
column: x => x.chat_room_id,
|
||||||
|
principalTable: "sn_chat_room",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_sn_chat_member_chat_room_id",
|
||||||
|
table: "sn_chat_member",
|
||||||
|
column: "chat_room_id");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_sn_chat_room_sn_realm_id",
|
||||||
|
table: "sn_chat_room",
|
||||||
|
column: "sn_realm_id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.7")
|
.HasAnnotation("ProductVersion", "9.0.9")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
@@ -954,159 +954,6 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
b.ToTable("auth_sessions", (string)null);
|
b.ToTable("auth_sessions", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatMember", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<Guid>("AccountId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("account_id");
|
|
||||||
|
|
||||||
b.Property<Instant?>("BreakUntil")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("break_until");
|
|
||||||
|
|
||||||
b.Property<Guid>("ChatRoomId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("chat_room_id");
|
|
||||||
|
|
||||||
b.Property<Instant>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("DeletedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("deleted_at");
|
|
||||||
|
|
||||||
b.Property<bool>("IsBot")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_bot");
|
|
||||||
|
|
||||||
b.Property<Instant?>("JoinedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("joined_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("LastReadAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("last_read_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("LeaveAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("leave_at");
|
|
||||||
|
|
||||||
b.Property<string>("Nick")
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)")
|
|
||||||
.HasColumnName("nick");
|
|
||||||
|
|
||||||
b.Property<int>("Notify")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("notify");
|
|
||||||
|
|
||||||
b.Property<int>("Role")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("role");
|
|
||||||
|
|
||||||
b.Property<ChatTimeoutCause>("TimeoutCause")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("timeout_cause");
|
|
||||||
|
|
||||||
b.Property<Instant?>("TimeoutUntil")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("timeout_until");
|
|
||||||
|
|
||||||
b.Property<Instant>("UpdatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("updated_at");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_sn_chat_member");
|
|
||||||
|
|
||||||
b.HasIndex("ChatRoomId")
|
|
||||||
.HasDatabaseName("ix_sn_chat_member_chat_room_id");
|
|
||||||
|
|
||||||
b.ToTable("sn_chat_member", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatRoom", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<SnCloudFileReferenceObject>("Background")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("background");
|
|
||||||
|
|
||||||
b.Property<string>("BackgroundId")
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)")
|
|
||||||
.HasColumnName("background_id");
|
|
||||||
|
|
||||||
b.Property<Instant>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("DeletedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("deleted_at");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.HasMaxLength(4096)
|
|
||||||
.HasColumnType("character varying(4096)")
|
|
||||||
.HasColumnName("description");
|
|
||||||
|
|
||||||
b.Property<bool>("IsCommunity")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_community");
|
|
||||||
|
|
||||||
b.Property<bool>("IsPublic")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_public");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)")
|
|
||||||
.HasColumnName("name");
|
|
||||||
|
|
||||||
b.Property<SnCloudFileReferenceObject>("Picture")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("picture");
|
|
||||||
|
|
||||||
b.Property<string>("PictureId")
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)")
|
|
||||||
.HasColumnName("picture_id");
|
|
||||||
|
|
||||||
b.Property<Guid?>("RealmId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("realm_id");
|
|
||||||
|
|
||||||
b.Property<Guid?>("SnRealmId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("sn_realm_id");
|
|
||||||
|
|
||||||
b.Property<int>("Type")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("type");
|
|
||||||
|
|
||||||
b.Property<Instant>("UpdatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("updated_at");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_sn_chat_room");
|
|
||||||
|
|
||||||
b.HasIndex("SnRealmId")
|
|
||||||
.HasDatabaseName("ix_sn_chat_room_sn_realm_id");
|
|
||||||
|
|
||||||
b.ToTable("sn_chat_room", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnCheckInResult", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnCheckInResult", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -2363,26 +2210,6 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
b.Navigation("Challenge");
|
b.Navigation("Challenge");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatMember", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnChatRoom", "ChatRoom")
|
|
||||||
.WithMany("Members")
|
|
||||||
.HasForeignKey("ChatRoomId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired()
|
|
||||||
.HasConstraintName("fk_sn_chat_member_sn_chat_room_chat_room_id");
|
|
||||||
|
|
||||||
b.Navigation("ChatRoom");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatRoom", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnRealm", null)
|
|
||||||
.WithMany("ChatRooms")
|
|
||||||
.HasForeignKey("SnRealmId")
|
|
||||||
.HasConstraintName("fk_sn_chat_room_realms_sn_realm_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnCheckInResult", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnCheckInResult", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnAccount", "Account")
|
b.HasOne("DysonNetwork.Shared.Models.SnAccount", "Account")
|
||||||
@@ -2635,11 +2462,6 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
b.Navigation("Sessions");
|
b.Navigation("Sessions");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatRoom", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Members");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPermissionGroup", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPermissionGroup", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Members");
|
b.Navigation("Members");
|
||||||
@@ -2649,8 +2471,6 @@ namespace DysonNetwork.Pass.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealm", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealm", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("ChatRooms");
|
|
||||||
|
|
||||||
b.Navigation("Members");
|
b.Navigation("Members");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class SnPublisher : ModelBase, IIdentifiedResource
|
|||||||
|
|
||||||
public Guid? AccountId { get; set; }
|
public Guid? AccountId { get; set; }
|
||||||
public Guid? RealmId { get; set; }
|
public Guid? RealmId { get; set; }
|
||||||
[JsonIgnore] public SnRealm? Realm { get; set; }
|
[NotMapped] public SnRealm? Realm { get; set; }
|
||||||
[NotMapped] public SnAccount? Account { get; set; }
|
[NotMapped] public SnAccount? Account { get; set; }
|
||||||
|
|
||||||
public string ResourceIdentifier => $"publisher:{Id}";
|
public string ResourceIdentifier => $"publisher:{Id}";
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class SnRealm : ModelBase, IIdentifiedResource
|
|||||||
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
|
[Column(TypeName = "jsonb")] public SnVerificationMark? Verification { get; set; }
|
||||||
|
|
||||||
[JsonIgnore] public ICollection<SnRealmMember> Members { get; set; } = new List<SnRealmMember>();
|
[JsonIgnore] public ICollection<SnRealmMember> Members { get; set; } = new List<SnRealmMember>();
|
||||||
[JsonIgnore] public ICollection<SnChatRoom> ChatRooms { get; set; } = new List<SnChatRoom>();
|
|
||||||
|
|
||||||
public Guid AccountId { get; set; }
|
public Guid AccountId { get; set; }
|
||||||
|
|
||||||
@@ -40,7 +39,9 @@ public class SnRealm : ModelBase, IIdentifiedResource
|
|||||||
{
|
{
|
||||||
Id = Id.ToString(),
|
Id = Id.ToString(),
|
||||||
Name = Name,
|
Name = Name,
|
||||||
Slug = Slug
|
Slug = Slug,
|
||||||
|
IsCommunity = IsCommunity,
|
||||||
|
IsPublic = IsPublic
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +53,8 @@ public class SnRealm : ModelBase, IIdentifiedResource
|
|||||||
Name = proto.Name,
|
Name = proto.Name,
|
||||||
Slug = proto.Slug,
|
Slug = proto.Slug,
|
||||||
Description = "",
|
Description = "",
|
||||||
IsCommunity = false,
|
IsCommunity = proto.IsCommunity,
|
||||||
IsPublic = false
|
IsPublic = proto.IsPublic
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ message Realm {
|
|||||||
string id = 1;
|
string id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string slug = 3;
|
string slug = 3;
|
||||||
|
bool is_community = 4;
|
||||||
|
bool is_public = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RealmMember {
|
message RealmMember {
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ public class AppDatabase(
|
|||||||
public DbSet<SnPublisherSubscription> PublisherSubscriptions { get; set; } = null!;
|
public DbSet<SnPublisherSubscription> PublisherSubscriptions { get; set; } = null!;
|
||||||
public DbSet<SnPublisherFeature> PublisherFeatures { get; set; } = null!;
|
public DbSet<SnPublisherFeature> PublisherFeatures { get; set; } = null!;
|
||||||
|
|
||||||
// TODO Remove the realms table after the data migration is done
|
|
||||||
public DbSet<SnRealm> Realms { get; set; } = null!;
|
|
||||||
public DbSet<SnRealmMember> RealmMembers { get; set; } = null!;
|
|
||||||
|
|
||||||
public DbSet<SnPost> Posts { get; set; } = null!;
|
public DbSet<SnPost> Posts { get; set; } = null!;
|
||||||
public DbSet<SnPostReaction> PostReactions { get; set; } = null!;
|
public DbSet<SnPostReaction> PostReactions { get; set; } = null!;
|
||||||
public DbSet<SnPostAward> PostAwards { get; set; } = null!;
|
public DbSet<SnPostAward> PostAwards { get; set; } = null!;
|
||||||
@@ -114,14 +110,6 @@ public class AppDatabase(
|
|||||||
.WithMany(c => c.Posts)
|
.WithMany(c => c.Posts)
|
||||||
.UsingEntity(j => j.ToTable("post_collection_links"));
|
.UsingEntity(j => j.ToTable("post_collection_links"));
|
||||||
|
|
||||||
modelBuilder.Entity<SnRealmMember>()
|
|
||||||
.HasKey(pm => new { pm.RealmId, pm.AccountId });
|
|
||||||
modelBuilder.Entity<SnRealmMember>()
|
|
||||||
.HasOne(pm => pm.Realm)
|
|
||||||
.WithMany(p => p.Members)
|
|
||||||
.HasForeignKey(pm => pm.RealmId)
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
modelBuilder.Entity<SnChatMember>()
|
modelBuilder.Entity<SnChatMember>()
|
||||||
.HasKey(pm => new { pm.Id });
|
.HasKey(pm => new { pm.Id });
|
||||||
modelBuilder.Entity<SnChatMember>()
|
modelBuilder.Entity<SnChatMember>()
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ public class AutocompletionService(AppDatabase db, RemoteAccountService remoteAc
|
|||||||
}
|
}
|
||||||
else if (realmId.HasValue)
|
else if (realmId.HasValue)
|
||||||
{
|
{
|
||||||
var realmMemberIds = await db.RealmMembers
|
// TODO: Filter to realm members only - needs efficient implementation
|
||||||
.Where(m => m.RealmId == realmId.Value && m.LeaveAt == null)
|
// var realmMemberIds = await db.RealmMembers
|
||||||
.Select(m => m.AccountId)
|
// .Where(m => m.RealmId == realmId.Value && m.LeaveAt == null)
|
||||||
.ToListAsync();
|
// .Select(m => m.AccountId)
|
||||||
var realmMemberIdStrings = realmMemberIds.Select(id => id.ToString()).ToHashSet();
|
// .ToListAsync();
|
||||||
filteredAccounts = allAccounts.Where(a => realmMemberIdStrings.Contains(a.Id)).ToList();
|
// var realmMemberIdStrings = realmMemberIds.Select(id => id.ToString()).ToHashSet();
|
||||||
|
// filteredAccounts = allAccounts.Where(a => realmMemberIdStrings.Contains(a.Id)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var users = filteredAccounts
|
var users = filteredAccounts
|
||||||
|
|||||||
@@ -1,30 +1,31 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using DysonNetwork.Shared.Registry;
|
||||||
|
|
||||||
namespace DysonNetwork.Sphere.Discovery;
|
namespace DysonNetwork.Sphere.Discovery;
|
||||||
|
|
||||||
public class DiscoveryService(AppDatabase appDatabase)
|
public class DiscoveryService(RemoteRealmService remoteRealmService)
|
||||||
{
|
{
|
||||||
public Task<List<Shared.Models.SnRealm>> GetCommunityRealmAsync(
|
public async Task<List<Shared.Models.SnRealm>> GetCommunityRealmAsync(
|
||||||
string? query,
|
string? query,
|
||||||
int take = 10,
|
int take = 10,
|
||||||
int offset = 0,
|
int offset = 0,
|
||||||
bool randomizer = false
|
bool randomizer = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var realmsQuery = appDatabase.Realms
|
var allRealms = await remoteRealmService.GetPublicRealms();
|
||||||
.Where(r => r.IsCommunity)
|
var communityRealms = allRealms.Where(r => r.IsCommunity);
|
||||||
.OrderByDescending(r => r.CreatedAt)
|
|
||||||
.AsQueryable();
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(query))
|
if (!string.IsNullOrEmpty(query))
|
||||||
realmsQuery = realmsQuery.Where(r =>
|
{
|
||||||
EF.Functions.ILike(r.Name, $"%{query}%") ||
|
communityRealms = communityRealms.Where(r =>
|
||||||
EF.Functions.ILike(r.Description, $"%{query}%")
|
r.Name.Contains(query, StringComparison.OrdinalIgnoreCase)
|
||||||
);
|
);
|
||||||
realmsQuery = randomizer
|
}
|
||||||
? realmsQuery.OrderBy(r => EF.Functions.Random())
|
|
||||||
: realmsQuery.OrderByDescending(r => r.CreatedAt);
|
|
||||||
|
|
||||||
return realmsQuery.Skip(offset).Take(take).ToListAsync();
|
// Since we don't have CreatedAt in the proto model, we'll just apply randomizer if requested
|
||||||
|
var orderedRealms = randomizer
|
||||||
|
? communityRealms.OrderBy(_ => Random.Shared.Next())
|
||||||
|
: communityRealms;
|
||||||
|
|
||||||
|
return orderedRealms.Skip(offset).Take(take).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1962
DysonNetwork.Sphere/Migrations/20251022170100_RemoveRealms.Designer.cs
generated
Normal file
1962
DysonNetwork.Sphere/Migrations/20251022170100_RemoveRealms.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
132
DysonNetwork.Sphere/Migrations/20251022170100_RemoveRealms.cs
Normal file
132
DysonNetwork.Sphere/Migrations/20251022170100_RemoveRealms.cs
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using DysonNetwork.Shared.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Sphere.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemoveRealms : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "fk_chat_rooms_realms_sn_realm_id",
|
||||||
|
table: "chat_rooms");
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "fk_publishers_realms_realm_id",
|
||||||
|
table: "publishers");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "realm_members");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "realms");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "ix_publishers_realm_id",
|
||||||
|
table: "publishers");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "ix_chat_rooms_sn_realm_id",
|
||||||
|
table: "chat_rooms");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "sn_realm_id",
|
||||||
|
table: "chat_rooms");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<Guid>(
|
||||||
|
name: "sn_realm_id",
|
||||||
|
table: "chat_rooms",
|
||||||
|
type: "uuid",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "realms",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
account_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
background = table.Column<SnCloudFileReferenceObject>(type: "jsonb", nullable: true),
|
||||||
|
background_id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||||
|
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
description = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
|
||||||
|
is_community = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
is_public = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
name = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
|
||||||
|
picture = table.Column<SnCloudFileReferenceObject>(type: "jsonb", nullable: true),
|
||||||
|
picture_id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||||
|
slug = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
|
||||||
|
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
verification = table.Column<SnVerificationMark>(type: "jsonb", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("pk_realms", x => x.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "realm_members",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
realm_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
account_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||||
|
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
joined_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
leave_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||||
|
role = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("pk_realm_members", x => new { x.realm_id, x.account_id });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "fk_realm_members_realms_realm_id",
|
||||||
|
column: x => x.realm_id,
|
||||||
|
principalTable: "realms",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_publishers_realm_id",
|
||||||
|
table: "publishers",
|
||||||
|
column: "realm_id");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_chat_rooms_sn_realm_id",
|
||||||
|
table: "chat_rooms",
|
||||||
|
column: "sn_realm_id");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_realms_slug",
|
||||||
|
table: "realms",
|
||||||
|
column: "slug",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "fk_chat_rooms_realms_sn_realm_id",
|
||||||
|
table: "chat_rooms",
|
||||||
|
column: "sn_realm_id",
|
||||||
|
principalTable: "realms",
|
||||||
|
principalColumn: "id");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "fk_publishers_realms_realm_id",
|
||||||
|
table: "publishers",
|
||||||
|
column: "realm_id",
|
||||||
|
principalTable: "realms",
|
||||||
|
principalColumn: "id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
{
|
{
|
||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder
|
modelBuilder
|
||||||
.HasAnnotation("ProductVersion", "9.0.7")
|
.HasAnnotation("ProductVersion", "9.0.9")
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
@@ -296,10 +296,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnType("uuid")
|
.HasColumnType("uuid")
|
||||||
.HasColumnName("realm_id");
|
.HasColumnName("realm_id");
|
||||||
|
|
||||||
b.Property<Guid?>("SnRealmId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("sn_realm_id");
|
|
||||||
|
|
||||||
b.Property<int>("Type")
|
b.Property<int>("Type")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("type");
|
.HasColumnName("type");
|
||||||
@@ -311,9 +307,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.HasKey("Id")
|
b.HasKey("Id")
|
||||||
.HasName("pk_chat_rooms");
|
.HasName("pk_chat_rooms");
|
||||||
|
|
||||||
b.HasIndex("SnRealmId")
|
|
||||||
.HasDatabaseName("ix_chat_rooms_sn_realm_id");
|
|
||||||
|
|
||||||
b.ToTable("chat_rooms", (string)null);
|
b.ToTable("chat_rooms", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -989,9 +982,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.IsUnique()
|
.IsUnique()
|
||||||
.HasDatabaseName("ix_publishers_name");
|
.HasDatabaseName("ix_publishers_name");
|
||||||
|
|
||||||
b.HasIndex("RealmId")
|
|
||||||
.HasDatabaseName("ix_publishers_realm_id");
|
|
||||||
|
|
||||||
b.ToTable("publishers", (string)null);
|
b.ToTable("publishers", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1117,127 +1107,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.ToTable("publisher_subscriptions", (string)null);
|
b.ToTable("publisher_subscriptions", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealm", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("id");
|
|
||||||
|
|
||||||
b.Property<Guid>("AccountId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("account_id");
|
|
||||||
|
|
||||||
b.Property<SnCloudFileReferenceObject>("Background")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("background");
|
|
||||||
|
|
||||||
b.Property<string>("BackgroundId")
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)")
|
|
||||||
.HasColumnName("background_id");
|
|
||||||
|
|
||||||
b.Property<Instant>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("DeletedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("deleted_at");
|
|
||||||
|
|
||||||
b.Property<string>("Description")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(4096)
|
|
||||||
.HasColumnType("character varying(4096)")
|
|
||||||
.HasColumnName("description");
|
|
||||||
|
|
||||||
b.Property<bool>("IsCommunity")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_community");
|
|
||||||
|
|
||||||
b.Property<bool>("IsPublic")
|
|
||||||
.HasColumnType("boolean")
|
|
||||||
.HasColumnName("is_public");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)")
|
|
||||||
.HasColumnName("name");
|
|
||||||
|
|
||||||
b.Property<SnCloudFileReferenceObject>("Picture")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("picture");
|
|
||||||
|
|
||||||
b.Property<string>("PictureId")
|
|
||||||
.HasMaxLength(32)
|
|
||||||
.HasColumnType("character varying(32)")
|
|
||||||
.HasColumnName("picture_id");
|
|
||||||
|
|
||||||
b.Property<string>("Slug")
|
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(1024)
|
|
||||||
.HasColumnType("character varying(1024)")
|
|
||||||
.HasColumnName("slug");
|
|
||||||
|
|
||||||
b.Property<Instant>("UpdatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("updated_at");
|
|
||||||
|
|
||||||
b.Property<SnVerificationMark>("Verification")
|
|
||||||
.HasColumnType("jsonb")
|
|
||||||
.HasColumnName("verification");
|
|
||||||
|
|
||||||
b.HasKey("Id")
|
|
||||||
.HasName("pk_realms");
|
|
||||||
|
|
||||||
b.HasIndex("Slug")
|
|
||||||
.IsUnique()
|
|
||||||
.HasDatabaseName("ix_realms_slug");
|
|
||||||
|
|
||||||
b.ToTable("realms", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealmMember", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("RealmId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("realm_id");
|
|
||||||
|
|
||||||
b.Property<Guid>("AccountId")
|
|
||||||
.HasColumnType("uuid")
|
|
||||||
.HasColumnName("account_id");
|
|
||||||
|
|
||||||
b.Property<Instant>("CreatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("created_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("DeletedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("deleted_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("JoinedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("joined_at");
|
|
||||||
|
|
||||||
b.Property<Instant?>("LeaveAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("leave_at");
|
|
||||||
|
|
||||||
b.Property<int>("Role")
|
|
||||||
.HasColumnType("integer")
|
|
||||||
.HasColumnName("role");
|
|
||||||
|
|
||||||
b.Property<Instant>("UpdatedAt")
|
|
||||||
.HasColumnType("timestamp with time zone")
|
|
||||||
.HasColumnName("updated_at");
|
|
||||||
|
|
||||||
b.HasKey("RealmId", "AccountId")
|
|
||||||
.HasName("pk_realm_members");
|
|
||||||
|
|
||||||
b.ToTable("realm_members", (string)null);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealtimeCall", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealtimeCall", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -1727,14 +1596,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.Navigation("Sender");
|
b.Navigation("Sender");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnChatRoom", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnRealm", null)
|
|
||||||
.WithMany("ChatRooms")
|
|
||||||
.HasForeignKey("SnRealmId")
|
|
||||||
.HasConstraintName("fk_chat_rooms_realms_sn_realm_id");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPoll", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPoll", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
|
b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
|
||||||
@@ -1864,16 +1725,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.Navigation("Post");
|
b.Navigation("Post");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisher", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnRealm", "Realm")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("RealmId")
|
|
||||||
.HasConstraintName("fk_publishers_realms_realm_id");
|
|
||||||
|
|
||||||
b.Navigation("Realm");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisherFeature", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisherFeature", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
|
b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
|
||||||
@@ -1910,18 +1761,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.Navigation("Publisher");
|
b.Navigation("Publisher");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealmMember", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnRealm", "Realm")
|
|
||||||
.WithMany("Members")
|
|
||||||
.HasForeignKey("RealmId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired()
|
|
||||||
.HasConstraintName("fk_realm_members_realms_realm_id");
|
|
||||||
|
|
||||||
b.Navigation("Realm");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealtimeCall", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealtimeCall", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("DysonNetwork.Shared.Models.SnChatRoom", "Room")
|
b.HasOne("DysonNetwork.Shared.Models.SnChatRoom", "Room")
|
||||||
@@ -2103,13 +1942,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
b.Navigation("Subscriptions");
|
b.Navigation("Subscriptions");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.SnRealm", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("ChatRooms");
|
|
||||||
|
|
||||||
b.Navigation("Members");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("DysonNetwork.Shared.Models.StickerPack", b =>
|
modelBuilder.Entity("DysonNetwork.Shared.Models.StickerPack", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Ownerships");
|
b.Navigation("Ownerships");
|
||||||
|
|||||||
@@ -685,6 +685,8 @@ public partial class PostService(
|
|||||||
post.ForwardedPost.Publisher = forwardedPublisher;
|
post.ForwardedPost.Publisher = forwardedPublisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await ps.LoadIndividualPublisherAccounts(publishers.Values);
|
||||||
|
|
||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -358,9 +358,7 @@ public class PublisherController(
|
|||||||
if (realm == null) return NotFound("Realm not found");
|
if (realm == null) return NotFound("Realm not found");
|
||||||
|
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
var isAdmin = await db.RealmMembers
|
var isAdmin = await remoteRealmService.IsMemberWithRole(realm.Id, accountId, [RealmMemberRole.Moderator]);
|
||||||
.AnyAsync(m =>
|
|
||||||
m.RealmId == realm.Id && m.AccountId == accountId && m.Role >= RealmMemberRole.Moderator);
|
|
||||||
if (!isAdmin)
|
if (!isAdmin)
|
||||||
return StatusCode(403, "You need to be a moderator of the realm to create an organization publisher");
|
return StatusCode(403, "You need to be a moderator of the realm to create an organization publisher");
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using DysonNetwork.Shared.Proto;
|
|||||||
using DysonNetwork.Shared.Registry;
|
using DysonNetwork.Shared.Registry;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
|
using PublisherType = DysonNetwork.Shared.Models.PublisherType;
|
||||||
|
|
||||||
namespace DysonNetwork.Sphere.Publisher;
|
namespace DysonNetwork.Sphere.Publisher;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class PublisherService(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||||
ICacheService cache,
|
ICacheService cache,
|
||||||
RemoteAccountService remoteAccountsHelper
|
RemoteAccountService remoteAccounts
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
public async Task<SnPublisher?> GetPublisherByName(string name)
|
public async Task<SnPublisher?> GetPublisherByName(string name)
|
||||||
@@ -408,7 +409,8 @@ public class PublisherService(
|
|||||||
return isEnabled.Value;
|
return isEnabled.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsMemberWithRole(Guid publisherId, Guid accountId, Shared.Models.PublisherMemberRole requiredRole)
|
public async Task<bool> IsMemberWithRole(Guid publisherId, Guid accountId,
|
||||||
|
Shared.Models.PublisherMemberRole requiredRole)
|
||||||
{
|
{
|
||||||
var member = await db.Publishers
|
var member = await db.Publishers
|
||||||
.Where(p => p.Id == publisherId)
|
.Where(p => p.Id == publisherId)
|
||||||
@@ -420,7 +422,7 @@ public class PublisherService(
|
|||||||
|
|
||||||
public async Task<SnPublisherMember> LoadMemberAccount(SnPublisherMember member)
|
public async Task<SnPublisherMember> LoadMemberAccount(SnPublisherMember member)
|
||||||
{
|
{
|
||||||
var account = await remoteAccountsHelper.GetAccount(member.AccountId);
|
var account = await remoteAccounts.GetAccount(member.AccountId);
|
||||||
member.Account = SnAccount.FromProtoValue(account);
|
member.Account = SnAccount.FromProtoValue(account);
|
||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
@@ -428,13 +430,35 @@ public class PublisherService(
|
|||||||
public async Task<List<SnPublisherMember>> LoadMemberAccounts(ICollection<SnPublisherMember> members)
|
public async Task<List<SnPublisherMember>> LoadMemberAccounts(ICollection<SnPublisherMember> members)
|
||||||
{
|
{
|
||||||
var accountIds = members.Select(m => m.AccountId).ToList();
|
var accountIds = members.Select(m => m.AccountId).ToList();
|
||||||
var accounts = (await remoteAccountsHelper.GetAccountBatch(accountIds)).ToDictionary(a => Guid.Parse(a.Id), a => a);
|
var accounts = (await remoteAccounts.GetAccountBatch(accountIds)).ToDictionary(a => Guid.Parse(a.Id), a => a);
|
||||||
|
|
||||||
return [.. members.Select(m =>
|
return
|
||||||
|
[
|
||||||
|
.. members.Select(m =>
|
||||||
|
{
|
||||||
|
if (accounts.TryGetValue(m.AccountId, out var account))
|
||||||
|
m.Account = SnAccount.FromProtoValue(account);
|
||||||
|
return m;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<SnPublisher>> LoadIndividualPublisherAccounts(ICollection<SnPublisher> publishers)
|
||||||
|
{
|
||||||
|
var accountIds = publishers
|
||||||
|
.Where(p => p.AccountId.HasValue && p.Type == PublisherType.Individual)
|
||||||
|
.Select(p => p.AccountId!.Value)
|
||||||
|
.ToList();
|
||||||
|
if (accountIds.Count == 0) return publishers.ToList();
|
||||||
|
|
||||||
|
var accounts = (await remoteAccounts.GetAccountBatch(accountIds)).ToDictionary(a => Guid.Parse(a.Id), a => a);
|
||||||
|
|
||||||
|
foreach (var p in publishers)
|
||||||
{
|
{
|
||||||
if (accounts.TryGetValue(m.AccountId, out var account))
|
if (p.AccountId.HasValue && accounts.TryGetValue(p.AccountId.Value, out var account))
|
||||||
m.Account = SnAccount.FromProtoValue(account);
|
p.Account = SnAccount.FromProtoValue(account);
|
||||||
return m;
|
}
|
||||||
})];
|
|
||||||
|
return publishers.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class WebFeed : ModelBase
|
|||||||
[Column(TypeName = "jsonb")] public WebFeedConfig Config { get; set; } = new();
|
[Column(TypeName = "jsonb")] public WebFeedConfig Config { get; set; } = new();
|
||||||
|
|
||||||
public Guid PublisherId { get; set; }
|
public Guid PublisherId { get; set; }
|
||||||
public Shared.Models.SnPublisher Publisher { get; set; } = null!;
|
public SnPublisher Publisher { get; set; } = null!;
|
||||||
|
|
||||||
[JsonIgnore] public ICollection<WebArticle> Articles { get; set; } = new List<WebArticle>();
|
[JsonIgnore] public ICollection<WebArticle> Articles { get; set; } = new List<WebArticle>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user