💥 Make chat room name, description optional

This commit is contained in:
LittleSheep 2025-05-17 23:10:39 +08:00
parent 27f934c634
commit 5951dab6f1
5 changed files with 3458 additions and 28 deletions

View File

@ -15,8 +15,8 @@ public enum ChatRoomType
public class ChatRoom : ModelBase
{
public Guid Id { get; set; }
[MaxLength(1024)] public string Name { get; set; } = string.Empty;
[MaxLength(4096)] public string Description { get; set; } = string.Empty;
[MaxLength(1024)] public string? Name { get; set; }
[MaxLength(4096)] public string? Description { get; set; }
public ChatRoomType Type { get; set; }
public bool IsPublic { get; set; }

View File

@ -31,7 +31,7 @@ public class ChatRoomController(
if (HttpContext.Items["CurrentUser"] is Account.Account currentUser)
chatRoom = await crs.LoadDirectMessageMembers(chatRoom, currentUser.Id);
return Ok(chatRoom);
}
@ -79,7 +79,7 @@ public class ChatRoomController(
.FirstOrDefaultAsync();
if (existingDm != null)
return Ok(existingDm); // Return existing DM if found
return BadRequest("You already have a DM with this user.");
// Create new DM chat room
var dmRoom = new ChatRoom
@ -425,28 +425,12 @@ public class ChatRoomController(
.Include(e => e.Account.Profile)
.ToListAsync();
var directRoomsId = members
.Where(m => m.ChatRoom.Type == ChatRoomType.DirectMessage)
.Select(m => m.ChatRoom.Id)
.ToList();
var directMembers = directRoomsId.Count != 0
? await db.ChatMembers
.Where(m => directRoomsId.Contains(m.ChatRoomId))
.Where(m => m.AccountId != userId)
.Include(m => m.Account)
.Include(m => m.Account.Profile)
.ToDictionaryAsync(m => m.ChatRoomId, m => m)
: new Dictionary<Guid, ChatMember>();
// Map the results
members.ForEach(m =>
{
if (m.ChatRoom.Type == ChatRoomType.DirectMessage &&
directMembers.TryGetValue(m.ChatRoomId, out var otherMember))
m.ChatRoom.DirectMembers = new List<ChatMemberTransmissionObject>
{ ChatMemberTransmissionObject.FromEntity(otherMember) };
});
var chatRooms = members.Select(m => m.ChatRoom).ToList();
var directMembers =
(await crs.LoadDirectMessageMembers(chatRooms, userId)).ToDictionary(c => c.Id, c => c.Members);
foreach (var member in members.Where(member => member.ChatRoom.Type == ChatRoomType.DirectMessage))
member.ChatRoom.Members = directMembers[member.ChatRoom.Id];
return members.ToList();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DysonNetwork.Sphere.Migrations
{
/// <inheritdoc />
public partial class OptionalChatRoomNameAndDescription : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "name",
table: "chat_rooms",
type: "character varying(1024)",
maxLength: 1024,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(1024)",
oldMaxLength: 1024);
migrationBuilder.AlterColumn<string>(
name: "description",
table: "chat_rooms",
type: "character varying(4096)",
maxLength: 4096,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(4096)",
oldMaxLength: 4096);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "name",
table: "chat_rooms",
type: "character varying(1024)",
maxLength: 1024,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(1024)",
oldMaxLength: 1024,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "description",
table: "chat_rooms",
type: "character varying(4096)",
maxLength: 4096,
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(4096)",
oldMaxLength: 4096,
oldNullable: true);
}
}
}

View File

@ -969,7 +969,6 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnName("deleted_at");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
.HasColumnName("description");
@ -979,7 +978,6 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnName("is_public");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("character varying(1024)")
.HasColumnName("name");