添加项目文件。
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using GroupService.Domain.Enums;
|
||||
using GroupService.Domain.Events;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace GroupService.Domain.Entities
|
||||
{
|
||||
public class Group : AggregateRootEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 群聊名称
|
||||
/// </summary>
|
||||
public string Name { get; private set; } = "新建群聊";
|
||||
|
||||
/// <summary>
|
||||
/// 群主
|
||||
/// </summary>
|
||||
public Guid GroupMaster { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 群权限
|
||||
/// (0:需管理员同意,1:任意人可加群,2:不允许任何人加入)
|
||||
/// </summary>
|
||||
public GroupAuthorityType Authority { get; private set; } = GroupAuthorityType.REQUIRE_CONSENT;
|
||||
|
||||
/// <summary>
|
||||
/// 全员禁言(false允许发言,true全员禁言)
|
||||
/// </summary>
|
||||
public bool AllMembersBanned { get; private set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 群聊状态
|
||||
/// (1:正常,2:封禁)
|
||||
/// </summary>
|
||||
public GroupState Status { get; private set; } = GroupState.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// 群公告
|
||||
/// </summary>
|
||||
public string Announcement { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 群头像
|
||||
/// </summary>
|
||||
public string? Avatar { get; private set; } = "https://ts1.tc.mm.bing.net/th/id/OIP-C.XiB9NHwI57WPmotCbXuwawAAAA?rs=1&pid=ImgDetMain&o=7&rm=3";
|
||||
public long MaxSequenceId { get; private set; } = 0;
|
||||
public string LastMessage { get; private set; } = string.Empty;
|
||||
public string LastSenderName { get; private set; } = string.Empty;
|
||||
|
||||
private Group() { }
|
||||
|
||||
public Group(Guid groupMaster, string name = "新建群聊")
|
||||
{
|
||||
Name = name;
|
||||
GroupMaster = groupMaster;
|
||||
AddDomainEvent(new GroupCreateDomainEvent(this));
|
||||
}
|
||||
|
||||
public void setAllMembersBanned(bool isBanned)
|
||||
{
|
||||
if (isBanned == AllMembersBanned) return;
|
||||
|
||||
AllMembersBanned = isBanned;
|
||||
|
||||
AddDomainEvent(new AllMembersBannedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Ban()
|
||||
{
|
||||
Status = GroupState.Blocked;
|
||||
ModificationTime = DateTime.Now;
|
||||
AddDomainEvent(new GroupBlockedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Update(string? name, GroupAuthorityType? groupAuthority, string? announcement, string? avatar)
|
||||
{
|
||||
bool isChanged = false;
|
||||
if (name != null)
|
||||
{
|
||||
Name = name;
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (groupAuthority != null)
|
||||
{
|
||||
Authority = groupAuthority.Value;
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (announcement != null)
|
||||
{
|
||||
Announcement = announcement;
|
||||
isChanged = true;
|
||||
}
|
||||
if (avatar != null)
|
||||
{
|
||||
Avatar = avatar;
|
||||
isChanged = true;
|
||||
}
|
||||
|
||||
if (isChanged)
|
||||
{
|
||||
ModificationTime = DateTime.Now;
|
||||
AddDomainEvent(new GroupUpdateDomainEvent(this));
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLastMsg(long maxSequenceId, string lastMsg, string lastSenderName)
|
||||
{
|
||||
MaxSequenceId = maxSequenceId;
|
||||
LastMessage = lastMsg;
|
||||
LastSenderName = lastSenderName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using GroupService.Domain.Enums;
|
||||
using GroupService.Domain.Events;
|
||||
using GroupService.Domain.ValueObjects;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace GroupService.Domain.Entities
|
||||
{
|
||||
public class GroupInvitation : AggregateRootEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 群聊编号
|
||||
/// </summary>
|
||||
public Guid GroupId { get; private set; }
|
||||
public GroupProfile GroupProfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被邀请用户
|
||||
/// </summary>
|
||||
public Guid UserId { get; private set; }
|
||||
public UserProfile UserProfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 邀请用户
|
||||
/// </summary>
|
||||
public Guid OperatorId { get; private set; }
|
||||
public UserProfile OperatorProfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态(0:待被邀请人同意
|
||||
/// 1:被邀请人已同意)
|
||||
/// </summary>
|
||||
public GroupInvitationState State { get; private set; } = GroupInvitationState.Pending;
|
||||
|
||||
|
||||
private GroupInvitation() { }
|
||||
public GroupInvitation(Guid groupId, GroupProfile groupProfile, Guid userId, UserProfile userProfile, Guid operatorId, UserProfile operatorProfile)
|
||||
{
|
||||
GroupId = groupId;
|
||||
GroupProfile = groupProfile;
|
||||
UserId = userId;
|
||||
UserProfile = userProfile;
|
||||
OperatorId = operatorId;
|
||||
OperatorProfile = operatorProfile;
|
||||
AddDomainEvent(new GroupInvitationCreateDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Accept()
|
||||
{
|
||||
if (State != GroupInvitationState.Pending) return;
|
||||
State = GroupInvitationState.Passed;
|
||||
ModificationTime = DateTime.Now;
|
||||
AddDomainEvent(new GroupInvitationAcceptDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Reject()
|
||||
{
|
||||
if (State != GroupInvitationState.Pending) return;
|
||||
State = GroupInvitationState.Reject;
|
||||
ModificationTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using GroupService.Domain.Enums;
|
||||
using GroupService.Domain.Events;
|
||||
using GroupService.Domain.ValueObjects;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace GroupService.Domain.Entities
|
||||
{
|
||||
public class GroupJoinRequest : AggregateRootEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 群聊编号
|
||||
///
|
||||
/// </summary>
|
||||
public Guid GroupId { get; private set; }
|
||||
public GroupProfile GroupProfile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请人
|
||||
/// </summary>
|
||||
public Guid UserId { get; private set; }
|
||||
public UserProfile UserProfile { get; private set; }
|
||||
|
||||
public Guid? OperatorId { get; private set; }
|
||||
public string? OperatorName { get; private set; }
|
||||
public string? OperatorAvatar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请状态(0:待管理员同意,1:已拒绝,2:已同意)
|
||||
/// </summary>
|
||||
public GroupJoinRequestState State { get; private set; } = GroupJoinRequestState.Pending;
|
||||
|
||||
/// <summary>
|
||||
/// 入群附言
|
||||
/// </summary>
|
||||
public string Description { get; private set; } = "申请入群";
|
||||
|
||||
private GroupJoinRequest() { }
|
||||
|
||||
public GroupJoinRequest(Guid userId, UserProfile user, Guid groupId, GroupProfile group, string? desc)
|
||||
{
|
||||
UserId = userId;
|
||||
GroupId = groupId;
|
||||
GroupProfile = group;
|
||||
UserProfile = user;
|
||||
if (desc is not null && desc.Length > 20)
|
||||
{
|
||||
throw new DomainException("入群描述不可超过20字符");
|
||||
}
|
||||
Description = desc ?? Description;
|
||||
}
|
||||
|
||||
public void Approve(Guid id, string nickName, string avatar)
|
||||
{
|
||||
if (State != GroupJoinRequestState.Pending) return;
|
||||
State = GroupJoinRequestState.Passed;
|
||||
OperatorAvatar = avatar;
|
||||
OperatorId = id;
|
||||
OperatorName = nickName;
|
||||
ModificationTime = DateTime.Now;
|
||||
AddDomainEvent(new GroupJoinRequestPassedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void Decline(Guid id, string nickName, string avatar)
|
||||
{
|
||||
if (State != GroupJoinRequestState.Pending) return;
|
||||
State = GroupJoinRequestState.Declined;
|
||||
OperatorAvatar = avatar;
|
||||
OperatorId = id;
|
||||
OperatorName = nickName;
|
||||
ModificationTime = DateTime.Now;
|
||||
AddDomainEvent(new GroupJoinRequestDeclinedDomainEvent(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using GroupService.Domain.Enums;
|
||||
using GroupService.Domain.Events;
|
||||
using IM.DomainCommons;
|
||||
|
||||
namespace GroupService.Domain.Entities
|
||||
{
|
||||
public class GroupMember : AggregateRootEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户编号
|
||||
/// </summary>
|
||||
public Guid UserId { get; private set; }
|
||||
public string GroupNickName { get; private set; }
|
||||
public string? Avatar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 群聊编号
|
||||
/// </summary>
|
||||
public Guid GroupId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成员角色(0:普通成员,1:管理员,2:群主)
|
||||
/// </summary>
|
||||
public GroupMemberRole Role { get; private set; }
|
||||
|
||||
private GroupMember() { }
|
||||
|
||||
public GroupMember(Guid userId, Guid groupId, string groupNickname, string? avatar, GroupMemberRole role = GroupMemberRole.Normal)
|
||||
{
|
||||
UserId = userId;
|
||||
GroupId = groupId;
|
||||
Role = role;
|
||||
GroupNickName = groupNickname;
|
||||
Avatar = avatar;
|
||||
AddDomainEvent(new GroupMemberJoinedDomainEvent(this));
|
||||
}
|
||||
|
||||
public void UpdateRole(GroupMemberRole role)
|
||||
{
|
||||
if (role == Role) return;
|
||||
Role = role;
|
||||
}
|
||||
|
||||
public void UpdateAvatar(string avatar)
|
||||
{
|
||||
Avatar = avatar;
|
||||
}
|
||||
public void UpdateGroupNickname(string nickname)
|
||||
{
|
||||
GroupNickName = nickname;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user