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
4 changes: 4 additions & 0 deletions src/pepper_cli/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,10 @@ def on_thread_view_at_top(self, _event: ThreadView.AtTop) -> None:
def on_thread_view_pin_changed(self, _event: ThreadView.PinChanged) -> None:
"""Reached the end (the newest row is on screen, so it is read) or scrolled away from
it (rows below are unseen: the open topic shows as unread)."""
if not self.query(ThreadView):
# A message queued as the app tears down is dispatched after the screen's widgets
# are gone; there is no thread left to read or mark (#139).
return
self._note_viewed()
self._run("publish")
self.refresh_chrome()
Expand Down
13 changes: 13 additions & 0 deletions tests/test_tui_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from pepper_cli.tui import app as tui_app
from pepper_cli.tui import state, stream
from pepper_cli.tui.thread import ThreadView
from tests import tui_support as ts
from tests.tui_support import body_text, until

Expand Down Expand Up @@ -292,6 +293,18 @@ async def test_nothing_is_marked_read_while_the_thread_is_scrolled_up(
await until(pilot, lambda: (ts.TOPIC_A1, arrived) in server.puts)


async def test_a_pin_change_delivered_after_the_thread_is_gone_is_ignored() -> None:
"""The cue can be dispatched during teardown, once the thread is gone (#139): no crash."""
server = ts.standard_server()
app = tui_app.PepperApp(server.client())
async with app.run_test(size=(120, 20)) as pilot:
await until(pilot, lambda: len(app.rooms) == 2)
app.open_conversation(state.Conversation(ts.ROOM_A, ts.TOPIC_A1))
await until(pilot, lambda: app.loaded_topic)
await app.thread.remove()
app.on_thread_view_pin_changed(ThreadView.PinChanged(True))


async def test_reaching_the_end_marks_the_newest_row_read(monkeypatch: pytest.MonkeyPatch) -> None:
server = ts.standard_server()
_long_topic(server)
Expand Down
Loading