Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/).
every direct message.
- Staff are told when Discord refuses a reply. A new ticket whose first
message is refused is removed and the user is told, instead of leaving a
channel that pinged nobody.
channel that pinged nobody. A channel that already holds a message stays.
- A lost database connection is retried on the same pool. Before, each
failure opened another pool of ten connections.

Expand Down
6 changes: 4 additions & 2 deletions core/views/modmail_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ async def _open_ticket(
_logger.exception(
"Discord refused the ticket header of %s", user.id
)
# Without it nobody is pinged: start over next time.
# Without it nobody is pinged: start over next time,
# unless a message has reached the channel meanwhile.
with contextlib.suppress(discord.HTTPException):
await channel.delete()
if not [m async for m in channel.history(limit=1)]:
await channel.delete()
await self.initial_message.channel.send(
view=refused_notice(error)
)
Expand Down
32 changes: 30 additions & 2 deletions tests/test_ticket_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@
TicketOptionsView,
ticket_header,
)
from tests.conftest import USER_ID, member, said, text_of, ticket_channel
from tests.helpers import World, button, forbidden, refused, within_limits
from tests.conftest import (
USER_ID,
member,
said,
text_of,
ticket_channel,
)
from tests.helpers import (
World,
button,
forbidden,
history_message,
refused,
within_limits,
)
from tests.ui_helpers import interaction

TYPES = {
Expand Down Expand Up @@ -485,6 +498,21 @@ async def test_a_refused_header_leaves_no_silent_ticket(
assert flow.initial.add_reaction.await_count == 0


async def test_a_new_ticket_that_got_a_message_is_not_removed(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# A second direct message can arrive before the header is refused.
flow = _Flow(monkeypatch, "Confirm")
flow.channel.send.side_effect = refused()
flow.channel.delete = AsyncMock()
flow.channel.history.items = [history_message("already here")]

await flow.run()

flow.channel.delete.assert_not_awaited()
assert "not delivered" in said(flow.initial.channel.send)


async def test_staff_hear_that_only_part_of_a_reply_arrived(
monkeypatch: pytest.MonkeyPatch,
) -> None:
Expand Down