Структура, доп модули, федерация, документация

This commit is contained in:
Халимов Рустам
2026-03-27 00:55:01 +03:00
parent 7cb6ac61dd
commit 7ef73b414c
64 changed files with 3080 additions and 133 deletions
+35
View File
@@ -2,6 +2,8 @@ using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Domain;
public sealed record UserStatusChangedDomainEvent(Guid UserId, bool IsOnline, DateTime LastSeen) : IDomainEvent;
/// <summary>
/// Сущность пользователя в контексте идентификации (Identity).
/// </summary>
@@ -16,6 +18,11 @@ public sealed class User : AggregateRoot<Guid>
public DateTime? Birthday { get; private set; }
public DateTime CreatedAt { get; private set; }
public bool HideStoryViews { get; private set; }
public bool IsExternal { get; private set; }
public string? Domain { get; private set; }
public bool IsOnline { get; private set; }
public DateTime? LastSeen { get; private set; }
public bool HideStatus { get; private set; }
private User(Guid id, string username, string passwordHash, string displayName, string? email, string? bio = null)
: base(id)
@@ -36,6 +43,18 @@ public sealed class User : AggregateRoot<Guid>
return new User(Guid.NewGuid(), username, passwordHash, displayName, email, bio);
}
/// <summary>
/// Создает "теневого" пользователя для контакта с другого сервера.
/// </summary>
public static User CreateExternal(Guid id, string username, string displayName, string domain, string? avatar = null)
{
var user = new User(id, username, "EXTERNAL_USER", displayName, null, null);
user.IsExternal = true;
user.Domain = domain;
user.Avatar = avatar;
return user;
}
public void UpdateProfile(string displayName, string? bio, DateTime? birthday)
{
DisplayName = displayName;
@@ -57,5 +76,21 @@ public sealed class User : AggregateRoot<Guid>
{
PasswordHash = newPasswordHash;
}
public void UpdateStatus(bool isOnline)
{
IsOnline = isOnline;
LastSeen = DateTime.UtcNow;
if (!HideStatus)
{
RaiseDomainEvent(new UserStatusChangedDomainEvent(Id, IsOnline, LastSeen.Value));
}
}
public void SetHideStatus(bool hide)
{
HideStatus = hide;
}
}