add(conversation):完善私聊好友会话服务

This commit is contained in:
2026-01-03 22:13:28 +08:00
35 changed files with 456 additions and 54 deletions
+18 -12
View File
@@ -18,27 +18,33 @@ public partial class Conversation
public int TargetId { get; set; }
/// <summary>
/// 消息类型(同Messages.MsgType
/// 最后一条未读消息ID
/// </summary>
public int MsgType { get; set; }
/// <summary>
/// 最后一条消息ID
/// </summary>
public int LastMessageId { get; set; }
public int? LastReadMessageId { get; set; }
/// <summary>
/// 未读消息数
/// </summary>
public int UnreadCount { get; set; }
public string TargetName { get; set; } = null!;
public string? TargetAvatar { get; set; }
public int ChatType { get; set; }
public virtual Message LastMessage { get; set; } = null!;
/// <summary>
/// 消息推送唯一标识符
/// </summary>
public string StreamKey { get; set; } = null!;
/// <summary>
/// 最后一条最新消息
/// </summary>
public string LastMessage { get; set; } = null!;
/// <summary>
/// 最后一条消息发送时间
/// </summary>
public DateTime LastMessageTime { get; set; }
public virtual Message? LastReadMessage { get; set; }
public virtual User User { get; set; } = null!;
}
+5
View File
@@ -44,6 +44,11 @@ public partial class Group
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// 群头像
/// </summary>
public string Avatar { get; set; } = null!;
public virtual ICollection<GroupInvite> GroupInvites { get; set; } = new List<GroupInvite>();
public virtual User GroupMasterNavigation { get; set; } = null!;
+25 -20
View File
@@ -49,17 +49,10 @@ public partial class ImContext : DbContext
public virtual DbSet<Role> Roles { get; set; }
public virtual DbSet<User> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseMySql(
"server=frp-era.com;port=26582;database=IM;user=product;password=12345678",
ServerVersion.Parse("5.7.44-mysql")
);
}
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseMySql("server=frp-era.com;port=26582;database=IM;user=product;password=12345678", Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.44-mysql"));
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -117,18 +110,25 @@ public partial class ImContext : DbContext
entity.HasIndex(e => e.UserId, "Userid");
entity.HasIndex(e => e.LastMessageId, "lastMessageId");
entity.HasIndex(e => e.LastReadMessageId, "lastMessageId");
entity.Property(e => e.Id)
.HasColumnType("int(11)")
.HasColumnName("ID");
entity.Property(e => e.LastMessageId)
.HasComment("最后一条消息ID ")
entity.Property(e => e.ChatType).HasColumnType("int(11)");
entity.Property(e => e.LastMessage)
.HasMaxLength(255)
.HasComment("最后一条最新消息");
entity.Property(e => e.LastMessageTime)
.HasComment("最后一条消息发送时间")
.HasColumnType("datetime");
entity.Property(e => e.LastReadMessageId)
.HasComment("最后一条未读消息ID ")
.HasColumnType("int(11)")
.HasColumnName("lastMessageId");
entity.Property(e => e.MsgType)
.HasComment("消息类型(同Messages.MsgType ")
.HasColumnType("int(11)");
.HasColumnName("lastReadMessageId");
entity.Property(e => e.StreamKey)
.HasMaxLength(255)
.HasComment("消息推送唯一标识符");
entity.Property(e => e.TargetId)
.HasComment("对方ID(群聊为群聊ID,单聊为单聊ID) ")
.HasColumnType("int(11)");
@@ -139,9 +139,8 @@ public partial class ImContext : DbContext
.HasComment("用户")
.HasColumnType("int(11)");
entity.HasOne(d => d.LastMessage).WithMany(p => p.Conversations)
.HasForeignKey(d => d.LastMessageId)
.OnDelete(DeleteBehavior.ClientSetNull)
entity.HasOne(d => d.LastReadMessage).WithMany(p => p.Conversations)
.HasForeignKey(d => d.LastReadMessageId)
.HasConstraintName("conversations_ibfk_2");
entity.HasOne(d => d.User).WithMany(p => p.Conversations)
@@ -337,6 +336,9 @@ public partial class ImContext : DbContext
entity.Property(e => e.Auhority)
.HasComment("群权限\r\n(0:需管理员同意,1:任意人可加群,2:不允许任何人加入)")
.HasColumnType("tinyint(4)");
entity.Property(e => e.Avatar)
.HasMaxLength(255)
.HasComment("群头像");
entity.Property(e => e.Created)
.HasComment("群聊创建时间")
.HasColumnType("datetime");
@@ -557,6 +559,9 @@ public partial class ImContext : DbContext
entity.Property(e => e.State)
.HasComment("消息状态(0:已发送,1:已撤回) ")
.HasColumnType("tinyint(4)");
entity.Property(e => e.StreamKey)
.HasMaxLength(255)
.HasComment("消息推送唯一标识符");
entity.HasOne(d => d.SenderNavigation).WithMany(p => p.Messages)
.HasForeignKey(d => d.Sender)
+9 -13
View File
@@ -110,24 +110,22 @@ public partial class ImDbContext : DbContext
entity.HasIndex(e => e.UserId, "Userid");
entity.HasIndex(e => e.LastMessageId, "lastMessageId");
entity.HasIndex(e => e.LastReadMessageId, "lastReadMessageId");
entity.Property(e => e.Id)
.HasColumnType("int(11)")
.HasColumnName("ID");
entity.Property(e => e.ChatType).HasColumnType("int(11)");
entity.Property(e => e.LastMessageId)
.HasComment("最后一条消息ID ")
entity.Property(e => e.LastReadMessageId)
.HasComment("最后一条已读消息ID ")
.HasColumnType("int(11)")
.HasColumnName("lastMessageId");
entity.Property(e => e.MsgType)
.HasComment("消息类型(同Messages.MsgType ")
.HasColumnType("int(11)");
entity.Property(e => e.TargetAvatar).HasMaxLength(255);
entity.Property(e => e.StreamKey)
.HasMaxLength(255)
.HasComment("消息推送唯一标识符");
entity.Property(e => e.TargetId)
.HasComment("对方ID(群聊为群聊ID,单聊为单聊ID) ")
.HasColumnType("int(11)");
entity.Property(e => e.TargetName).HasMaxLength(255);
entity.Property(e => e.UnreadCount)
.HasComment("未读消息数 ")
.HasColumnType("int(11)");
@@ -135,11 +133,6 @@ public partial class ImDbContext : DbContext
.HasComment("用户")
.HasColumnType("int(11)");
entity.HasOne(d => d.LastMessage).WithMany(p => p.Conversations)
.HasForeignKey(d => d.LastMessageId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("conversations_ibfk_2");
entity.HasOne(d => d.User).WithMany(p => p.Conversations)
.HasForeignKey(d => d.UserId)
.OnDelete(DeleteBehavior.ClientSetNull)
@@ -553,6 +546,9 @@ public partial class ImDbContext : DbContext
entity.Property(e => e.State)
.HasComment("消息状态(0:已发送,1:已撤回) ")
.HasColumnType("tinyint(4)");
entity.Property(e => e.StreamKey)
.HasMaxLength(255)
.HasComment("消息推送唯一标识符");
entity.HasOne(d => d.SenderNavigation).WithMany(p => p.Messages)
.HasForeignKey(d => d.Sender)
+5
View File
@@ -44,6 +44,11 @@ public partial class Message
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// 消息推送唯一标识符
/// </summary>
public string StreamKey { get; set; } = null!;
public virtual ICollection<Conversation> Conversations { get; set; } = new List<Conversation>();
public virtual ICollection<File> Files { get; set; } = new List<File>();