feat: invites

This commit is contained in:
2026-09-28 09:32:22 +04:00
parent 3055381788
commit 7e1e036bf1
24 changed files with 936 additions and 29 deletions
@@ -1,4 +1,5 @@
using MediatR;
using MemeVault.Application.Commands.AcceptCollectionInvite;
using MemeVault.Application.Commands.EnsureUser;
using MemeVault.Application.Commands.SaveMedia;
using MemeVault.Domain.Enums;
@@ -25,6 +26,9 @@ public sealed class MessageHandler
// Сколько ждать, пока все части альбома придут от Telegram
private static readonly TimeSpan MediaGroupBuffer = TimeSpan.FromSeconds(2);
// Префикс токена в параметре /start
private const string InvitePrefix = "/start inv_";
public MessageHandler(
IMediator mediator,
ITelegramBotClient bot,
@@ -193,7 +197,17 @@ public sealed class MessageHandler
private async Task HandleCommandAsync(Message message, CancellationToken ct)
{
var reply = message.Text switch
var text = message.Text ?? "";
// /start inv_<TOKEN> — принять приглашение в коллекцию
if (text.StartsWith(InvitePrefix, StringComparison.OrdinalIgnoreCase))
{
var token = text[InvitePrefix.Length..].Trim();
await HandleInviteAsync(message, token, ct);
return;
}
var reply = text switch
{
"/start" => "👋 Привет! Отправь мне картинку, видео, стикер или текст — я сохраню.\n" +
"Теги прямо в подписи: #мем #кот\n" +
@@ -206,6 +220,21 @@ public sealed class MessageHandler
await _bot.SendMessage(message.Chat.Id, reply, cancellationToken: ct);
}
private async Task HandleInviteAsync(Message message, string token, CancellationToken ct)
{
_logger.LogInformation("User {UserId} accepting invite token {Token}",
message.From!.Id, token);
var collectionId = await _mediator.Send(
new AcceptCollectionInviteCommand(token, message.From!.Id), ct);
var reply = collectionId is not null
? "✅ Ты добавлен в коллекцию! Открой мини-апп, чтобы увидеть её."
: "❌ Ссылка недействительна или была отозвана.";
await _bot.SendMessage(message.Chat.Id, reply, cancellationToken: ct);
}
// ── Вспомогательные ───────────────────────────────────────────────────────
private static (MediaSource? source, MediaType type) ExtractMedia(Message message) =>