fix: resolve session edit crashes and rendering mode bugs
This commit is contained in:
@@ -53,23 +53,23 @@ public sealed class SessionService(
|
||||
await using var conn = await dataSource.OpenConnectionAsync();
|
||||
await using var transaction = await conn.BeginTransactionAsync();
|
||||
|
||||
// 1. Update Session
|
||||
// 1. Fetch current session with all required columns for WebSession record
|
||||
var oldSession = await conn.QuerySingleAsync<WebSession>(
|
||||
"SELECT title, scheduled_at AS ScheduledAt, join_link AS JoinLink, batch_id AS BatchId, batch_message_id AS BatchMessageId FROM sessions WHERE id = @Id",
|
||||
@"SELECT s.id, s.group_id AS GroupId, s.title, s.scheduled_at AS ScheduledAt, s.status, s.join_link AS JoinLink,
|
||||
s.batch_id AS BatchId, s.batch_message_id AS BatchMessageId,
|
||||
g.telegram_chat_id AS TelegramChatId
|
||||
FROM sessions s
|
||||
JOIN game_groups g ON g.id = s.group_id
|
||||
WHERE s.id = @Id",
|
||||
new { Id = sessionId }, transaction);
|
||||
|
||||
// 2. Update Session
|
||||
await conn.ExecuteAsync(
|
||||
@"UPDATE sessions SET title = @Title, scheduled_at = @ScheduledAt, join_link = @JoinLink, updated_at = now()
|
||||
WHERE id = @Id",
|
||||
new { Id = sessionId, Title = title, ScheduledAt = scheduledAt, JoinLink = joinLink },
|
||||
transaction);
|
||||
|
||||
// 2. Fetch context for notification
|
||||
var group = await conn.QuerySingleAsync<WebGameGroup>(
|
||||
@"SELECT telegram_chat_id AS TelegramChatId FROM game_groups g
|
||||
JOIN sessions s ON s.group_id = g.id WHERE s.id = @Id",
|
||||
new { Id = sessionId }, transaction);
|
||||
|
||||
// 3. Update all sessions in the same batch with new title (optional, usually batch shares title)
|
||||
await conn.ExecuteAsync(
|
||||
"UPDATE sessions SET title = @Title WHERE batch_id = @BatchId",
|
||||
@@ -84,12 +84,12 @@ public sealed class SessionService(
|
||||
$"📌 <b>{System.Net.WebUtility.HtmlEncode(title)}</b>\n" +
|
||||
$"📅 Время: <b>{scheduledAt.FormatMoscow()}</b> (МСК)" + (timeChanged ? " (изменено)" : "");
|
||||
|
||||
await bot.SendMessage(group.TelegramChatId, notification, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html);
|
||||
await bot.SendMessage(oldSession.TelegramChatId, notification, parseMode: Telegram.Bot.Types.Enums.ParseMode.Html);
|
||||
|
||||
// 5. Update Original Batch Message
|
||||
if (oldSession.BatchMessageId.HasValue)
|
||||
{
|
||||
await TryUpdateBatchMessageAsync(oldSession.BatchId, group.TelegramChatId, oldSession.BatchMessageId.Value, title);
|
||||
await TryUpdateBatchMessageAsync(oldSession.BatchId, oldSession.TelegramChatId, oldSession.BatchMessageId.Value, title);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user