mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-24 21:46:07 +00:00
588a524fa5
SendMsgToTgbotDeleteAfter spawns a goroutine that, after the display delay, deleted the transient message and then unconditionally cleared the chat's conversation state. Every caller that ends a wizard step already clears the state synchronously, so that call was redundant — and harmful: if within the delay the user advanced to the next step (a callback sets a fresh awaiting_* state), the late goroutine wiped it, and the user's next message fell through unrecognized, silently dropping their input. Move the delayed deletion into deleteMessageAfterDelay, which only removes the message and no longer touches the conversation state. Guard deleteMessageTgBot against a nil bot so the deletion path is unit-testable.
23 lines
758 B
Go
23 lines
758 B
Go
package tgbot
|
|
|
|
import "testing"
|
|
|
|
// A transient "delete after N seconds" message must not reset the conversation
|
|
// state when its timer fires: the user may have advanced to the next wizard step
|
|
// (setting a fresh state) within that window, and clearing it would silently
|
|
// drop their next input.
|
|
func TestDeleteMessageAfterDelayKeepsUserState(t *testing.T) {
|
|
userStateMgr.reset()
|
|
t.Cleanup(userStateMgr.reset)
|
|
|
|
const chatID = int64(4242)
|
|
userStateMgr.set(chatID, "awaiting_comment")
|
|
|
|
tg := &Tgbot{}
|
|
tg.deleteMessageAfterDelay(chatID, 1, 0)
|
|
|
|
if st, ok := userStateMgr.get(chatID); !ok || st != "awaiting_comment" {
|
|
t.Fatalf("delayed message deletion cleared the conversation state: got (%q, %v), want (%q, true)", st, ok, "awaiting_comment")
|
|
}
|
|
}
|