feat: add event notes with pending state, 5-min TTL, cancel, and /note command

This commit is contained in:
2026-06-24 19:49:32 +03:30
parent 68c8518522
commit 4165839477
3 changed files with 134 additions and 1 deletions

View File

@@ -157,6 +157,16 @@ func (h *Handler) handleHistoryCallback(ctx context.Context, chatID int64, msgID
h.editEventTimeMin(ctx, chatID, msgID, user, eid, hh, loc)
return
}
// Set note for an event — prompt user for text
if n, _ := fmt.Sscanf(data, "note_%d", &eid); n == 1 {
h.promptNote(ctx, chatID, msgID, user, eid, loc)
return
}
// Cancel note prompt — return to day view
if n, _ := fmt.Sscanf(data, "note_cancel_%d", &eid); n == 1 {
h.backToDayView(ctx, chatID, msgID, user, eid, loc)
return
}
// Add IN event — show hour picker
if strings.HasPrefix(data, "addin_") {
h.addEventTime(ctx, chatID, msgID, user, data[6:], "in", loc)
@@ -372,6 +382,7 @@ func (h *Handler) sendDayView(ctx context.Context, chatID int64, msgID int, user
kbRows = append(kbRows, []models.InlineKeyboardButton{
{Text: fmt.Sprintf("Time %s", t), CallbackData: fmt.Sprintf("edit_time_%d", e.ID)},
{Text: "Type", CallbackData: fmt.Sprintf("edit_type_%d", e.ID)},
{Text: "Note", CallbackData: fmt.Sprintf("note_%d", e.ID)},
{Text: "DEL", CallbackData: fmt.Sprintf("delete_%d", e.ID), Style: "danger"},
})
}
@@ -532,6 +543,29 @@ func (h *Handler) acknowledgeCallback(ctx context.Context, chatID int64, msgID i
h.Bot.AnswerCallbackQuery(ctx, &bot.AnswerCallbackQueryParams{CallbackQueryID: fmt.Sprintf("cb_%d_%d", chatID, msgID)})
}
// promptNote asks the user to type a note for the event, then re-renders the day view.
func (h *Handler) promptNote(ctx context.Context, chatID int64, msgID int, user *db.User, eventID int64, loc *time.Location) {
event, err := h.getEventByID(user.ID, eventID)
if err != nil {
return
}
t := time.Unix(event.OccurredAt, 0).In(loc).Format("15:04")
h.mu.Lock()
h.pendingNotes[chatID] = &pendingNote{eventID: eventID, createdAt: time.Now()}
h.mu.Unlock()
kb := models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{{Text: "Cancel", CallbackData: fmt.Sprintf("note_cancel_%d", eventID)}},
},
}
h.Bot.EditMessageText(ctx, &bot.EditMessageTextParams{
ChatID: chatID, MessageID: msgID,
Text: fmt.Sprintf("Send the note for event at %s:", t), ReplyMarkup: &kb,
})
}
// deleteEventPrompt asks the user to confirm event deletion.
func (h *Handler) deleteEventPrompt(ctx context.Context, chatID int64, msgID int, user *db.User, eventID int64, loc *time.Location) {
kb := models.InlineKeyboardMarkup{