Commit Graph
4 Commits
  • fix(tgbot): scope the add-client wizard to the admin, not the chat (#6604)
    Two admins in one group chat shared one draft and one wizard step: clientDrafts and userStateStore were keyed by chat id alone, so the second admin's wizard opened on the first one's email and limits, and whichever of them tapped a control last decided what the other created.
    
    Key both stores by (chat, user) instead. A private chat is unaffected: its two ids are equal, so the key matches what the chat alone used to be. A message with no sender (a channel post) keys to user 0, which no admin holds.
    
    Fixes #6593.
  • refactor(tgbot): make the add-client expiry presets say what they do (#6503)
    * refactor(tgbot): make the add-client expiry presets say what they do
    
    The wizard's "Add N days" buttons were a copy of the renewal handler, whose
    accumulate branch they cleared two lines later: the branch tested a value the
    line above had just set to zero, so it was dead and only the "set N days from
    first use" path was reachable. That reads as an accident, and the automated
    review of #6499 flagged it twice.
    
    The wizard keeps the term it sets, which is now the code: a create flow has no
    expiry to add to, the custom keypad lands in this same case, and a corrected
    number has to replace the one it follows. 0 stays the Unlimited button. The
    renewal handler (reset_exp_c) genuinely adds to the client's remaining time and
    is unchanged.
    
    * refactor(tgbot): fold in the review of the expiry-preset change
    
    The test now starts every row from a term a preset could have left, so each row
    fails on its own under the accumulate semantics rather than depending on the row
    before it, and it reuses the package's draft helpers instead of a second copy.
    The wizard presets drop the "Add" verb they never honoured; the renewal
    keyboard keeps it, where reset_exp_c really does add to the remaining time.
  • fix(tgbot): keep the add-client draft with the chat that owns it (#6499)
    * fix(tgbot): keep the add-client draft with the chat that owns it
    
    The wizard held one package-level draft for the whole bot. Its steps run on
    the ten-goroutine worker pool, so two admins adding a client at the same time
    wrote into the same form: whichever step ran last decided the email, the
    limits and the attached inbounds of a client the other chat went on to
    create, and the attach picker mutated one shared slice from several
    goroutines at once as well.
    
    Each chat now gets its own draft, reached only through the chat that owns it
    and held for the duration of a step, so a client is created from the values
    its own chat collected.
    
    * fix(tgbot): take the wizard's draft lock only for the wizard
    
    A queued report tap held one of the ten worker slots while it waited on the
    chat's draft, and every chat that reached answerCallback grew the draft map
    even when the admin gate rejected it. Both follow from acquiring the draft
    before the gate; the wizard's own steps are the only callers that read it.
    
    The draft is now looked up under the same admin-and-wizard check, addClient
    takes the draft its caller locked instead of looking it up again, a submit
    drops the entry, and StopBot clears the map with the conversation states.
  • fix(tgbot): render the add-client draft as HTML and escape its values (#6492)
    The draft is sent with ParseMode HTML but was written in Markdown, so every
    card showed literal asterisks and backticks while the rest of the bot's
    messages render properly. Its admin-supplied values (email, comment, TG id,
    inbound remarks) were also interpolated raw, and a single '<' in any of them
    makes Telegram reject the whole message as unparsable.
    
    The wizard's own email and comment prompts echo those same draft values into
    HTML-parsed messages and were escaped too: the card is deleted before the
    prompt goes out, so a rejected prompt left the admin with an empty screen.