💥 Make chat room name, description optional
This commit is contained in:
parent
27f934c634
commit
5951dab6f1
@ -15,8 +15,8 @@ public enum ChatRoomType
|
|||||||
public class ChatRoom : ModelBase
|
public class ChatRoom : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
[MaxLength(1024)] public string Name { get; set; } = string.Empty;
|
[MaxLength(1024)] public string? Name { get; set; }
|
||||||
[MaxLength(4096)] public string Description { get; set; } = string.Empty;
|
[MaxLength(4096)] public string? Description { get; set; }
|
||||||
public ChatRoomType Type { get; set; }
|
public ChatRoomType Type { get; set; }
|
||||||
public bool IsPublic { get; set; }
|
public bool IsPublic { get; set; }
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class ChatRoomController(
|
|||||||
|
|
||||||
if (HttpContext.Items["CurrentUser"] is Account.Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is Account.Account currentUser)
|
||||||
chatRoom = await crs.LoadDirectMessageMembers(chatRoom, currentUser.Id);
|
chatRoom = await crs.LoadDirectMessageMembers(chatRoom, currentUser.Id);
|
||||||
|
|
||||||
return Ok(chatRoom);
|
return Ok(chatRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ public class ChatRoomController(
|
|||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (existingDm != null)
|
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
|
// Create new DM chat room
|
||||||
var dmRoom = new ChatRoom
|
var dmRoom = new ChatRoom
|
||||||
@ -425,28 +425,12 @@ public class ChatRoomController(
|
|||||||
.Include(e => e.Account.Profile)
|
.Include(e => e.Account.Profile)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
var directRoomsId = members
|
var chatRooms = members.Select(m => m.ChatRoom).ToList();
|
||||||
.Where(m => m.ChatRoom.Type == ChatRoomType.DirectMessage)
|
var directMembers =
|
||||||
.Select(m => m.ChatRoom.Id)
|
(await crs.LoadDirectMessageMembers(chatRooms, userId)).ToDictionary(c => c.Id, c => c.Members);
|
||||||
.ToList();
|
|
||||||
|
foreach (var member in members.Where(member => member.ChatRoom.Type == ChatRoomType.DirectMessage))
|
||||||
var directMembers = directRoomsId.Count != 0
|
member.ChatRoom.Members = directMembers[member.ChatRoom.Id];
|
||||||
? 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) };
|
|
||||||
});
|
|
||||||
|
|
||||||
return members.ToList();
|
return members.ToList();
|
||||||
}
|
}
|
||||||
|
3386
DysonNetwork.Sphere/Migrations/20250517144042_OptionalChatRoomNameAndDescription.Designer.cs
generated
Normal file
3386
DysonNetwork.Sphere/Migrations/20250517144042_OptionalChatRoomNameAndDescription.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -969,7 +969,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnName("deleted_at");
|
.HasColumnName("deleted_at");
|
||||||
|
|
||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(4096)
|
.HasMaxLength(4096)
|
||||||
.HasColumnType("character varying(4096)")
|
.HasColumnType("character varying(4096)")
|
||||||
.HasColumnName("description");
|
.HasColumnName("description");
|
||||||
@ -979,7 +978,6 @@ namespace DysonNetwork.Sphere.Migrations
|
|||||||
.HasColumnName("is_public");
|
.HasColumnName("is_public");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
|
||||||
.HasMaxLength(1024)
|
.HasMaxLength(1024)
|
||||||
.HasColumnType("character varying(1024)")
|
.HasColumnType("character varying(1024)")
|
||||||
.HasColumnName("name");
|
.HasColumnName("name");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user