feat: много запланированного

- клонирование коллекции
- добавление паблик-коллекций
- регенерация паблик-ссылок
This commit is contained in:
2026-10-07 02:45:37 +04:00
parent c1b052e2c7
commit 274e60a433
30 changed files with 719 additions and 112 deletions
@@ -16,6 +16,9 @@ public sealed class BotUser
public DateTimeOffset CreatedAt { get; private set; }
public DateTimeOffset LastSeenAt { get; private set; }
/// <summary>FK на коллекцию, в которую по умолчанию сохраняется новый контент.</summary>
public Guid? InboxCollectionId { get; private set; }
public IReadOnlyList<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();
// EF Core constructor
@@ -38,6 +41,11 @@ public sealed class BotUser
return user;
}
public void SetInboxCollection(Guid collectionId)
{
InboxCollectionId = collectionId;
}
public void RecordActivity()
{
LastSeenAt = DateTimeOffset.UtcNow;
@@ -6,7 +6,6 @@ namespace MemeVault.Domain.Aggregates.Collection;
/// <summary>
/// Aggregate Root: коллекция медиа-элементов с ACL-моделью доступа.
/// Каждый пользователь имеет ровно одну системную коллекцию Inbox (IsInbox = true).
/// </summary>
public sealed class Collection
{
@@ -23,9 +22,6 @@ public sealed class Collection
public string? Description { get; private set; }
public CollectionVisibility Visibility { get; private set; }
/// <summary>Системная коллекция входящих. Нельзя удалить или переименовать.</summary>
public bool IsInbox { get; private set; }
/// <summary>Коллекция содержит контент 18+. Скрывается в inline-режиме.</summary>
public bool IsNsfw { get; private set; }
@@ -41,12 +37,11 @@ public sealed class Collection
// EF Core constructor
private Collection() { }
private Collection(Guid id, long ownerTelegramId, string name, string? description, bool isInbox)
private Collection(Guid id, long ownerTelegramId, string name, string? description)
{
Id = id;
Name = name;
Description = description;
IsInbox = isInbox;
Visibility = CollectionVisibility.Private;
CreatedAt = DateTimeOffset.UtcNow;
@@ -62,12 +57,12 @@ public sealed class Collection
if (name.Length > 100)
throw new DomainException("Collection name must be 100 characters or less.");
return new Collection(Guid.NewGuid(), ownerTelegramId, name, description, isInbox: false);
return new Collection(Guid.NewGuid(), ownerTelegramId, name, description);
}
/// <summary>Создаёт системную коллекцию входящих для нового пользователя.</summary>
public static Collection CreateInbox(long ownerTelegramId) =>
new(Guid.NewGuid(), ownerTelegramId, "Inbox", description: null, isInbox: true);
new(Guid.NewGuid(), ownerTelegramId, "Inbox", description: null);
// ── Управление участниками ─────────────────────────────────────────────────
@@ -131,9 +126,6 @@ public sealed class Collection
public void Rename(string newName, long requestingTelegramId)
{
if (IsInbox)
throw new DomainException("Cannot rename the Inbox collection.");
EnsureRole(requestingTelegramId, CollectionRole.Manager);
if (string.IsNullOrWhiteSpace(newName))
@@ -152,29 +144,39 @@ public sealed class Collection
public void Delete(long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Owner);
if (IsInbox)
throw new DomainException("Cannot delete the Inbox collection.");
}
// ── Inbox ─────────────────────────────────────────────────────────────────
// ── Share-ссылка ──────────────────────────────────────────────────────────
/// <summary>
/// Делает коллекцию основной (Inbox). Вызывать только после снятия флага с текущего Inbox.
/// Перегенерирует токен share-ссылки. Доступно Manager и Owner.
/// Бросает <see cref="DomainException"/>, если коллекция Private (ссылки нет).
/// </summary>
public void PromoteToInbox(long requestingTelegramId)
public string RegenerateShareLink(long requestingTelegramId)
{
EnsureRole(requestingTelegramId, CollectionRole.Owner);
if (IsInbox)
throw new DomainException("Collection is already the Inbox.");
IsInbox = true;
EnsureRole(requestingTelegramId, CollectionRole.Manager);
if (Visibility == CollectionVisibility.Private)
throw new DomainException("Cannot regenerate share link for a private collection.");
ShareToken = GenerateToken();
UpdatedAt = DateTimeOffset.UtcNow;
return ShareToken;
}
/// <summary>Снимает флаг Inbox. Вызывать перед промоцией другой коллекции.</summary>
public void DemoteFromInbox()
// ── Публичное вступление ─────────────────────────────────────────────────
/// <summary>
/// Добавляет пользователя как Viewer в публичную коллекцию без инвайта.
/// Бросает <see cref="DomainException"/>, если коллекция не публичная.
/// Идемпотентно: уже являющийся участником — без изменений (возвращает false).
/// </summary>
public bool TryJoinPublic(long telegramId)
{
IsInbox = false;
UpdatedAt = DateTimeOffset.UtcNow;
if (Visibility != CollectionVisibility.Public)
throw new DomainException("Collection is not public.");
return TryAcceptInvite(telegramId, CollectionRole.Viewer);
}
// ── Инвайты ───────────────────────────────────────────────────────────────