Announce incoming messages on the node's terminal
The node now checks for new messages every 10 s in the background (before, only when the web UI asked), and Inbox.Collect reports newly filed visible messages through OnArrivals. The CLI logs one line per conversation with the listing title and a link to it, never the buyer's text. Hidden messages are not announced, a backlog is capped at 5 lines, and a lock stops a background check and a UI request from filing the same message twice. The e2e checks that node A announces the message before its API is called. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,57 @@ func TestCollectFilesConversationsOnce(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestArrivalsAreAnnouncedOnceAndWithoutText(t *testing.T) {
|
||||
f := newFixture(t, 0)
|
||||
var calls [][]Arrival
|
||||
f.in.OnArrivals = func(a []Arrival) { calls = append(calls, a) }
|
||||
l := f.listing()
|
||||
ref := message.Ref{Author: l.Author, ID: l.ID}
|
||||
a, b, spam := f.newThread(), f.newThread(), f.newThread()
|
||||
|
||||
if f.collect(); len(calls) != 0 {
|
||||
t.Fatalf("nothing arrived but %d calls were made", len(calls))
|
||||
}
|
||||
|
||||
f.buyer(l, a, 1, "Ist die Wohnung noch frei?", msgDifficulty)
|
||||
f.buyer(l, a, 2, "Ich könnte morgen vorbeikommen.", msgDifficulty)
|
||||
f.buyer(l, b, 1, "Guten Tag", msgDifficulty)
|
||||
f.buyer(l, spam, 1, "Schaut euch https://example.com/x an", msgDifficulty) // hidden
|
||||
f.collect()
|
||||
if len(calls) != 1 {
|
||||
t.Fatalf("one collection must make one call, got %d", len(calls))
|
||||
}
|
||||
got := calls[0]
|
||||
if len(got) != 3 {
|
||||
t.Fatalf("got %d arrivals, want 3 (the hidden one is not announced): %+v", len(got), got)
|
||||
}
|
||||
starts := 0
|
||||
for _, x := range got {
|
||||
if x.Listing != ref {
|
||||
t.Errorf("wrong listing %+v", x.Listing)
|
||||
}
|
||||
if x.Thread == spam.PublicHex() {
|
||||
t.Error("a hidden message was announced")
|
||||
}
|
||||
if x.New {
|
||||
starts++
|
||||
}
|
||||
}
|
||||
if starts != 2 {
|
||||
t.Errorf("%d conversations started, want 2 (a and b)", starts)
|
||||
}
|
||||
|
||||
// Nothing new: no repeat. A further message in a known conversation is not a start.
|
||||
if f.collect(); len(calls) != 1 {
|
||||
t.Fatalf("a second collection announced again: %d calls", len(calls))
|
||||
}
|
||||
f.buyer(l, a, 3, "Noch da?", msgDifficulty)
|
||||
f.collect()
|
||||
if len(calls) != 2 || len(calls[1]) != 1 || calls[1][0].New || calls[1][0].Thread != a.PublicHex() {
|
||||
t.Fatalf("follow-up not announced as a plain message in a: %+v", calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinksInFirstMessagesAreHiddenUntilTheOwnerReplies(t *testing.T) {
|
||||
f := newFixture(t, 0)
|
||||
l := f.listing()
|
||||
|
||||
Reference in New Issue
Block a user