59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
using GmRelay.Shared.Domain;
|
|
using Telegram.Bot.Types.ReplyMarkups;
|
|
|
|
namespace GmRelay.Shared.Rendering;
|
|
|
|
public sealed record SessionBatchDto(Guid SessionId, DateTime ScheduledAt, string Status);
|
|
public sealed record ParticipantBatchDto(Guid SessionId, string DisplayName, string? TelegramUsername);
|
|
|
|
public static class SessionBatchRenderer
|
|
{
|
|
public static (string Text, InlineKeyboardMarkup Markup) Render(
|
|
string title,
|
|
IReadOnlyList<SessionBatchDto> sessions,
|
|
IReadOnlyList<ParticipantBatchDto> participants)
|
|
{
|
|
var activeSessions = sessions.OrderBy(s => s.ScheduledAt).ToList();
|
|
|
|
var messageText = $"🎲 <b>Новые игры:</b> {System.Net.WebUtility.HtmlEncode(title)}\n\n" +
|
|
$"<b>Расписание:</b>\n\n";
|
|
|
|
var buttons = new List<InlineKeyboardButton[]>();
|
|
|
|
foreach (var session in activeSessions)
|
|
{
|
|
var sessionPlayers = participants.Where(p => p.SessionId == session.SessionId).ToList();
|
|
|
|
messageText += $"📅 <b>{session.ScheduledAt.FormatMoscow()}</b>\n";
|
|
messageText += $"👥 Игроки ({sessionPlayers.Count}):\n";
|
|
|
|
if (sessionPlayers.Count > 0)
|
|
{
|
|
messageText += string.Join("\n", sessionPlayers.Select(p => $" 👤 {(p.TelegramUsername != null ? "@" + p.TelegramUsername : p.DisplayName)}")) + "\n";
|
|
}
|
|
else
|
|
{
|
|
messageText += " <i>Пока никто не записался</i>\n";
|
|
}
|
|
|
|
if (SessionStatus.IsCancelled(session.Status))
|
|
{
|
|
messageText += "❌ <i>Сессия отменена</i>\n\n";
|
|
}
|
|
else
|
|
{
|
|
messageText += "\n";
|
|
var dateTitle = session.ScheduledAt.FormatMoscowShort();
|
|
buttons.Add(new[]
|
|
{
|
|
InlineKeyboardButton.WithCallbackData($"✋ На {dateTitle}", $"join_session:{session.SessionId}"),
|
|
InlineKeyboardButton.WithCallbackData($"❌ Отменить {dateTitle} (ГМ)", $"cancel_session:{session.SessionId}"),
|
|
InlineKeyboardButton.WithCallbackData($"⏰ (ГМ)", $"reschedule_session:{session.SessionId}")
|
|
});
|
|
}
|
|
}
|
|
|
|
return (messageText, new InlineKeyboardMarkup(buttons));
|
|
}
|
|
}
|