Add chat message handling and WebSocket integration

Introduce new `ChatService` for managing chat messages, including marking messages as read and checking read status. Add `WebSocketPacket` class for handling WebSocket communication and integrate it with `WebSocketService` to process chat-related packets. Enhance `ChatRoom` and `ChatMember` models with additional fields and relationships. Update `AppDatabase` to include new chat-related entities and adjust permissions for chat creation.
This commit is contained in:
2025-05-02 19:51:32 +08:00
parent da6a891b5f
commit 17de9a0f23
18 changed files with 483 additions and 1819 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,51 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
namespace DysonNetwork.Sphere.Migrations
{
/// <inheritdoc />
public partial class RealmAndChat : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Instant>(
name: "created_at",
table: "publisher_members",
type: "timestamp with time zone",
nullable: false,
defaultValue: NodaTime.Instant.FromUnixTimeTicks(0L));
migrationBuilder.AddColumn<Instant>(
name: "deleted_at",
table: "publisher_members",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn<Instant>(
name: "updated_at",
table: "publisher_members",
type: "timestamp with time zone",
nullable: false,
defaultValue: NodaTime.Instant.FromUnixTimeTicks(0L));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "created_at",
table: "publisher_members");
migrationBuilder.DropColumn(
name: "deleted_at",
table: "publisher_members");
migrationBuilder.DropColumn(
name: "updated_at",
table: "publisher_members");
}
}
}

View File

@ -16,8 +16,8 @@ using NpgsqlTypes;
namespace DysonNetwork.Sphere.Migrations
{
[DbContext(typeof(AppDatabase))]
[Migration("20250502040651_RealmAndChat")]
partial class RealmAndChat
[Migration("20250502041309_InitialMigration")]
partial class InitialMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -405,6 +405,52 @@ namespace DysonNetwork.Sphere.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "chat_members",
columns: table => new
{
chat_room_id = table.Column<long>(type: "bigint", nullable: false),
account_id = table.Column<long>(type: "bigint", nullable: false),
role = table.Column<int>(type: "integer", nullable: false),
joined_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
is_bot = table.Column<bool>(type: "boolean", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_chat_members", x => new { x.chat_room_id, x.account_id });
table.ForeignKey(
name: "fk_chat_members_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "chat_rooms",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
description = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
type = table.Column<int>(type: "integer", nullable: false),
is_public = table.Column<bool>(type: "boolean", nullable: false),
picture_id = table.Column<string>(type: "character varying(128)", nullable: true),
background_id = table.Column<string>(type: "character varying(128)", nullable: true),
realm_id = table.Column<long>(type: "bigint", nullable: true),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_chat_rooms", x => x.id);
});
migrationBuilder.CreateTable(
name: "files",
columns: table => new
@ -476,6 +522,47 @@ namespace DysonNetwork.Sphere.Migrations
principalColumn: "id");
});
migrationBuilder.CreateTable(
name: "realms",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
slug = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
name = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: false),
description = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
verified_as = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: true),
verified_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
is_community = table.Column<bool>(type: "boolean", nullable: false),
is_public = table.Column<bool>(type: "boolean", nullable: false),
picture_id = table.Column<string>(type: "character varying(128)", nullable: true),
background_id = table.Column<string>(type: "character varying(128)", nullable: true),
account_id = table.Column<long>(type: "bigint", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_realms", x => x.id);
table.ForeignKey(
name: "fk_realms_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_realms_files_background_id",
column: x => x.background_id,
principalTable: "files",
principalColumn: "id");
table.ForeignKey(
name: "fk_realms_files_picture_id",
column: x => x.picture_id,
principalTable: "files",
principalColumn: "id");
});
migrationBuilder.CreateTable(
name: "post_collections",
columns: table => new
@ -588,6 +675,35 @@ namespace DysonNetwork.Sphere.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "realm_members",
columns: table => new
{
realm_id = table.Column<long>(type: "bigint", nullable: false),
account_id = table.Column<long>(type: "bigint", nullable: false),
role = table.Column<int>(type: "integer", nullable: false),
joined_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_realm_members", x => new { x.realm_id, x.account_id });
table.ForeignKey(
name: "fk_realm_members_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_realm_members_realms_realm_id",
column: x => x.realm_id,
principalTable: "realms",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "post_category_links",
columns: table => new
@ -742,6 +858,26 @@ namespace DysonNetwork.Sphere.Migrations
table: "auth_sessions",
column: "challenge_id");
migrationBuilder.CreateIndex(
name: "ix_chat_members_account_id",
table: "chat_members",
column: "account_id");
migrationBuilder.CreateIndex(
name: "ix_chat_rooms_background_id",
table: "chat_rooms",
column: "background_id");
migrationBuilder.CreateIndex(
name: "ix_chat_rooms_picture_id",
table: "chat_rooms",
column: "picture_id");
migrationBuilder.CreateIndex(
name: "ix_chat_rooms_realm_id",
table: "chat_rooms",
column: "realm_id");
migrationBuilder.CreateIndex(
name: "ix_files_account_id",
table: "files",
@ -878,6 +1014,32 @@ namespace DysonNetwork.Sphere.Migrations
table: "publishers",
column: "picture_id");
migrationBuilder.CreateIndex(
name: "ix_realm_members_account_id",
table: "realm_members",
column: "account_id");
migrationBuilder.CreateIndex(
name: "ix_realms_account_id",
table: "realms",
column: "account_id");
migrationBuilder.CreateIndex(
name: "ix_realms_background_id",
table: "realms",
column: "background_id");
migrationBuilder.CreateIndex(
name: "ix_realms_picture_id",
table: "realms",
column: "picture_id");
migrationBuilder.CreateIndex(
name: "ix_realms_slug",
table: "realms",
column: "slug",
unique: true);
migrationBuilder.AddForeignKey(
name: "fk_account_profiles_files_background_id",
table: "account_profiles",
@ -892,6 +1054,35 @@ namespace DysonNetwork.Sphere.Migrations
principalTable: "files",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_chat_members_chat_rooms_chat_room_id",
table: "chat_members",
column: "chat_room_id",
principalTable: "chat_rooms",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "fk_chat_rooms_files_background_id",
table: "chat_rooms",
column: "background_id",
principalTable: "files",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_chat_rooms_files_picture_id",
table: "chat_rooms",
column: "picture_id",
principalTable: "files",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_chat_rooms_realms_realm_id",
table: "chat_rooms",
column: "realm_id",
principalTable: "realms",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_files_posts_post_id",
table: "files",
@ -937,6 +1128,9 @@ namespace DysonNetwork.Sphere.Migrations
migrationBuilder.DropTable(
name: "auth_sessions");
migrationBuilder.DropTable(
name: "chat_members");
migrationBuilder.DropTable(
name: "magic_spells");
@ -967,9 +1161,15 @@ namespace DysonNetwork.Sphere.Migrations
migrationBuilder.DropTable(
name: "publisher_members");
migrationBuilder.DropTable(
name: "realm_members");
migrationBuilder.DropTable(
name: "auth_challenges");
migrationBuilder.DropTable(
name: "chat_rooms");
migrationBuilder.DropTable(
name: "permission_groups");
@ -982,6 +1182,9 @@ namespace DysonNetwork.Sphere.Migrations
migrationBuilder.DropTable(
name: "post_tags");
migrationBuilder.DropTable(
name: "realms");
migrationBuilder.DropTable(
name: "accounts");