Add email to address release and an address hint
The release sheet gets an optional email field, prefilled from the saved address and kept with it. A conversation suggests releasing the address when the buyer's latest message contains words like "address" or "wo genau" (a keyword guess, German and English, only ever a suggestion). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+4
-1
@@ -311,7 +311,10 @@ text rules below are enforced by endpoints.
|
||||
- **Owner UI** (`#/mine`): your listings (requests needing a reply, whether an
|
||||
address is saved), the requests of one listing (status, preview, effort,
|
||||
filters), a conversation, and a sheet to **release the address** (prefilled
|
||||
from the saved one; address, phone, a free-text note, validity 1 to 30 days).
|
||||
from the saved one; address, phone, email, a free-text note, validity 1 to 30
|
||||
days). When the buyer's latest message contains words like "address" or "wo
|
||||
genau", the conversation suggests releasing it; that is a keyword guess and
|
||||
only ever a suggestion.
|
||||
Three panes side by side on a wide screen, one at a time on a phone. It uses
|
||||
the admin API above plus `GET /api/v1/mine` (own listings with request counts
|
||||
and `address_saved`) and `GET /api/v1/inbox?listing=<id>`, whose rows also
|
||||
|
||||
Vendored
+15
-1
@@ -246,6 +246,7 @@ var de = {
|
||||
"own.anon": "Anonym, Ende-zu-Ende-verschl\xFCsselt",
|
||||
"own.first": "Erste Nachricht dieser Person. Bis du antwortest, darf sie nur kurzen Text ohne Links schicken. Alles wird als reiner Text angezeigt, nie als Link.",
|
||||
"own.hiddenMsg": "Ausgeblendet: Eine erste Nachricht muss kurz sein und darf keine Links enthalten.",
|
||||
"own.hintAddress": "Die Person fragt m\xF6glicherweise nach der Adresse (Vermutung anhand einzelner W\xF6rter). Mit \u201EAdresse freigeben\u201C schickst du sie.",
|
||||
"own.grantSent": "Adresse freigegeben bis {date}",
|
||||
"own.reply": "Antwort",
|
||||
"own.send": "Senden",
|
||||
@@ -426,6 +427,7 @@ var en = {
|
||||
"own.anon": "Anonymous, end-to-end encrypted",
|
||||
"own.first": "First message from this person. Until you reply they can send short text only, no links. Everything is shown as plain text, never as a link.",
|
||||
"own.hiddenMsg": "Hidden: a first message must be short and contain no links.",
|
||||
"own.hintAddress": 'This person may be asking for the address (a guess based on a few words). Use "Release address" to send it.',
|
||||
"own.grantSent": "Address released until {date}",
|
||||
"own.reply": "Reply",
|
||||
"own.send": "Send",
|
||||
@@ -4690,6 +4692,7 @@ async function showOwner(listingId, thread) {
|
||||
const msgBox = h("div", { class: "thread", "aria-live": "polite" });
|
||||
const threadHead = h("h2", { class: "pane-title" });
|
||||
const firstNote = h("p", { class: "note warn" }, t("own.first"));
|
||||
const addressHint = h("p", { class: "note hint", hidden: true }, t("own.hintAddress"));
|
||||
const threadPane = h("section", { class: "pane pane-thread" });
|
||||
if (listingId && thread) {
|
||||
append(threadPane, [
|
||||
@@ -4698,6 +4701,7 @@ async function showOwner(listingId, thread) {
|
||||
h("p", { class: "muted small" }, t("own.anon")),
|
||||
msgBox,
|
||||
firstNote,
|
||||
addressHint,
|
||||
composer2(listingId, thread, () => void refresh(), (opener) => openSheet(listingId, thread, opener, () => void refresh())),
|
||||
deleteControl2(listingId, thread)
|
||||
]);
|
||||
@@ -4782,6 +4786,7 @@ async function showOwner(listingId, thread) {
|
||||
clear(msgBox);
|
||||
for (const m of msgs) msgBox.append(bubble2(m));
|
||||
firstNote.hidden = msgs.some((m) => m.dir === "out");
|
||||
addressHint.hidden = !asksForAddress(msgs);
|
||||
}
|
||||
function renderAll() {
|
||||
renderListings();
|
||||
@@ -4828,6 +4833,11 @@ async function showOwner(listingId, thread) {
|
||||
};
|
||||
tick2();
|
||||
}
|
||||
var ASKS_ADDRESS = /adress|address|anschrift|wo genau|wo liegt|wo befindet|which street|what street|where exactly|where is|where in/i;
|
||||
function asksForAddress(msgs) {
|
||||
const last = msgs[msgs.length - 1];
|
||||
return !!last && last.dir === "in" && !last.hidden && last.type === "text" && ASKS_ADDRESS.test(last.text ?? "");
|
||||
}
|
||||
function bubble2(m) {
|
||||
const mine2 = m.dir === "out";
|
||||
const who = mine2 ? t("own.you") : t("own.buyer");
|
||||
@@ -4985,6 +4995,7 @@ function openSheet(listingId, thread, opener, done) {
|
||||
};
|
||||
const address = h("input", { name: "address", maxlength: 300, required: true });
|
||||
const phone = h("input", { name: "phone", maxlength: 40 });
|
||||
const email = h("input", { name: "email", type: "email", maxlength: 120, autocomplete: "off" });
|
||||
const note = h("textarea", { name: "note", rows: 2, maxlength: 1e3 });
|
||||
const valid = h("select", { name: "valid" }, ...VALID_DAYS.map((d) => h("option", { value: String(d), selected: d === DEFAULT_DAYS }, d === 1 ? t("own.day") : t("own.days", { n: d }))));
|
||||
const remember = h("input", { type: "checkbox", name: "remember" });
|
||||
@@ -5009,12 +5020,13 @@ function openSheet(listingId, thread, opener, done) {
|
||||
send.textContent = t("own.sending");
|
||||
try {
|
||||
if (remember.checked && (!saved || saved.address !== a)) {
|
||||
await putAddress(listingId, { address: a, phone: phone.value.trim() || void 0, email: saved?.email });
|
||||
await putAddress(listingId, { address: a, phone: phone.value.trim() || void 0, email: email.value.trim() || void 0 });
|
||||
}
|
||||
await sendReply(listingId, thread, {
|
||||
type: "grant",
|
||||
address: a,
|
||||
phone: phone.value.trim() || void 0,
|
||||
email: email.value.trim() || void 0,
|
||||
note: note.value.trim() || void 0,
|
||||
valid_days: Number(valid.value)
|
||||
});
|
||||
@@ -5030,6 +5042,7 @@ function openSheet(listingId, thread, opener, done) {
|
||||
},
|
||||
h("label", null, t("own.fAddress"), address),
|
||||
h("label", null, t("own.fPhone"), phone),
|
||||
h("label", null, t("own.fEmail"), email),
|
||||
h("label", null, t("own.fNote"), note),
|
||||
h("label", null, t("own.fValid"), valid),
|
||||
rememberRow,
|
||||
@@ -5058,6 +5071,7 @@ function openSheet(listingId, thread, opener, done) {
|
||||
if (a) {
|
||||
if (!address.value) address.value = a.address;
|
||||
if (!phone.value && a.phone) phone.value = a.phone;
|
||||
if (!email.value && a.email) email.value = a.email;
|
||||
} else {
|
||||
remember.checked = true;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,8 @@ const de = {
|
||||
"own.first":
|
||||
"Erste Nachricht dieser Person. Bis du antwortest, darf sie nur kurzen Text ohne Links schicken. Alles wird als reiner Text angezeigt, nie als Link.",
|
||||
"own.hiddenMsg": "Ausgeblendet: Eine erste Nachricht muss kurz sein und darf keine Links enthalten.",
|
||||
"own.hintAddress":
|
||||
"Die Person fragt möglicherweise nach der Adresse (Vermutung anhand einzelner Wörter). Mit „Adresse freigeben“ schickst du sie.",
|
||||
"own.grantSent": "Adresse freigegeben bis {date}",
|
||||
"own.reply": "Antwort",
|
||||
"own.send": "Senden",
|
||||
@@ -355,6 +357,8 @@ const en: Record<keyof typeof de, string> = {
|
||||
"own.first":
|
||||
"First message from this person. Until you reply they can send short text only, no links. Everything is shown as plain text, never as a link.",
|
||||
"own.hiddenMsg": "Hidden: a first message must be short and contain no links.",
|
||||
"own.hintAddress":
|
||||
"This person may be asking for the address (a guess based on a few words). Use \"Release address\" to send it.",
|
||||
"own.grantSent": "Address released until {date}",
|
||||
"own.reply": "Reply",
|
||||
"own.send": "Send",
|
||||
|
||||
+18
-1
@@ -116,6 +116,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
const msgBox = h("div", { class: "thread", "aria-live": "polite" });
|
||||
const threadHead = h("h2", { class: "pane-title" });
|
||||
const firstNote = h("p", { class: "note warn" }, t("own.first"));
|
||||
const addressHint = h("p", { class: "note hint", hidden: true }, t("own.hintAddress"));
|
||||
const threadPane = h("section", { class: "pane pane-thread" });
|
||||
if (listingId && thread) {
|
||||
append(threadPane, [
|
||||
@@ -124,6 +125,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
h("p", { class: "muted small" }, t("own.anon")),
|
||||
msgBox,
|
||||
firstNote,
|
||||
addressHint,
|
||||
composer(listingId, thread, () => void refresh(), (opener) => openSheet(listingId, thread, opener, () => void refresh())),
|
||||
deleteControl(listingId, thread),
|
||||
]);
|
||||
@@ -222,6 +224,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
clear(msgBox);
|
||||
for (const m of msgs) msgBox.append(bubble(m));
|
||||
firstNote.hidden = msgs.some((m) => m.dir === "out");
|
||||
addressHint.hidden = !asksForAddress(msgs);
|
||||
}
|
||||
|
||||
function renderAll(): void {
|
||||
@@ -277,6 +280,16 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
|
||||
// --- pieces ------------------------------------------------------------------------------
|
||||
|
||||
// Words that suggest the buyer wants to know where the place is, in German and
|
||||
// English. A guess, so it only ever produces a suggestion, never an action.
|
||||
const ASKS_ADDRESS = /adress|address|anschrift|wo genau|wo liegt|wo befindet|which street|what street|where exactly|where is|where in/i;
|
||||
|
||||
/** True if the buyer's latest readable message looks like a request for the address. */
|
||||
function asksForAddress(msgs: o.OwnerMessage[]): boolean {
|
||||
const last = msgs[msgs.length - 1];
|
||||
return !!last && last.dir === "in" && !last.hidden && last.type === "text" && ASKS_ADDRESS.test(last.text ?? "");
|
||||
}
|
||||
|
||||
function bubble(m: o.OwnerMessage): HTMLElement {
|
||||
const mine = m.dir === "out";
|
||||
const who = mine ? t("own.you") : t("own.buyer");
|
||||
@@ -437,6 +450,7 @@ function openSheet(listingId: string, thread: string, opener: HTMLElement, done:
|
||||
};
|
||||
const address = h("input", { name: "address", maxlength: 300, required: true });
|
||||
const phone = h("input", { name: "phone", maxlength: 40 });
|
||||
const email = h("input", { name: "email", type: "email", maxlength: 120, autocomplete: "off" });
|
||||
const note = h("textarea", { name: "note", rows: 2, maxlength: 1000 });
|
||||
const valid = h("select", { name: "valid" }, ...VALID_DAYS.map((d) => h("option", { value: String(d), selected: d === DEFAULT_DAYS }, d === 1 ? t("own.day") : t("own.days", { n: d }))));
|
||||
const remember = h("input", { type: "checkbox", name: "remember" });
|
||||
@@ -462,12 +476,13 @@ function openSheet(listingId: string, thread: string, opener: HTMLElement, done:
|
||||
send.textContent = t("own.sending");
|
||||
try {
|
||||
if (remember.checked && (!saved || saved.address !== a)) {
|
||||
await o.putAddress(listingId, { address: a, phone: phone.value.trim() || undefined, email: saved?.email });
|
||||
await o.putAddress(listingId, { address: a, phone: phone.value.trim() || undefined, email: email.value.trim() || undefined });
|
||||
}
|
||||
await o.sendReply(listingId, thread, {
|
||||
type: "grant",
|
||||
address: a,
|
||||
phone: phone.value.trim() || undefined,
|
||||
email: email.value.trim() || undefined,
|
||||
note: note.value.trim() || undefined,
|
||||
valid_days: Number(valid.value),
|
||||
});
|
||||
@@ -483,6 +498,7 @@ function openSheet(listingId: string, thread: string, opener: HTMLElement, done:
|
||||
},
|
||||
h("label", null, t("own.fAddress"), address),
|
||||
h("label", null, t("own.fPhone"), phone),
|
||||
h("label", null, t("own.fEmail"), email),
|
||||
h("label", null, t("own.fNote"), note),
|
||||
h("label", null, t("own.fValid"), valid),
|
||||
rememberRow,
|
||||
@@ -509,6 +525,7 @@ function openSheet(listingId: string, thread: string, opener: HTMLElement, done:
|
||||
if (a) {
|
||||
if (!address.value) address.value = a.address;
|
||||
if (!phone.value && a.phone) phone.value = a.phone;
|
||||
if (!email.value && a.email) email.value = a.email;
|
||||
} else {
|
||||
remember.checked = true; // nothing saved yet: offer to keep what is typed
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ export interface Reply {
|
||||
text?: string;
|
||||
address?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
note?: string;
|
||||
valid_days?: number;
|
||||
}
|
||||
|
||||
@@ -307,6 +307,45 @@ test("a token that stops working sends the owner back to sign in", async () => {
|
||||
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), null);
|
||||
});
|
||||
|
||||
test("the sheet offers an email, prefilled from the saved address, and sends it", async () => {
|
||||
node.s.address = { address: "Musterweg 7, 22765 Hamburg", phone: "+49 40 1", email: "vermietung@example.org" };
|
||||
open(`#/login/${TOKEN}`);
|
||||
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
|
||||
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
|
||||
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
|
||||
|
||||
button("Release address")!.click();
|
||||
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="email"]')?.value === "vermietung@example.org", "email prefill");
|
||||
submit(q(".sheet form")!);
|
||||
await page!.waitFor(() => posts().length === 1, "the grant");
|
||||
assert.equal(JSON.parse(posts()[0]!.body).email, "vermietung@example.org");
|
||||
|
||||
// Cleared, it is not sent at all.
|
||||
button("Release address")!.click();
|
||||
await page!.waitFor(() => q<HTMLInputElement>('.sheet input[name="email"]')?.value === "vermietung@example.org", "prefill again");
|
||||
q<HTMLInputElement>('.sheet input[name="email"]')!.value = "";
|
||||
submit(q(".sheet form")!);
|
||||
await page!.waitFor(() => posts().length === 2, "the second grant");
|
||||
assert.equal("email" in JSON.parse(posts()[1]!.body), false);
|
||||
});
|
||||
|
||||
test("a buyer asking where the place is gets a suggestion to release the address", async () => {
|
||||
const ask = async (text: string, dir: "in" | "out" = "in", hidden = false) => {
|
||||
node.s.msgs[T_NEW] = [{ hash: "q", dir, hidden, received_at: NOW, type: "text", n: 1, sent_at: NOW - 60, text }];
|
||||
page?.close();
|
||||
open(`#/login/${TOKEN}`);
|
||||
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
|
||||
page!.window.location.hash = `#/mine/${L1}/${T_NEW}`;
|
||||
await page!.waitFor(() => qa(".pane-thread .msg").length === 1, "the conversation");
|
||||
return q<HTMLElement>(".pane-thread .hint")!.hidden;
|
||||
};
|
||||
assert.equal(await ask("Sehr gerne! Wo genau ist die Wohnung?"), false, "German question");
|
||||
assert.equal(await ask("Could you send me the address please?"), false, "English request");
|
||||
assert.equal(await ask("Ist die Wohnung noch frei?"), true, "an unrelated question");
|
||||
assert.equal(await ask("Wo genau ist die Wohnung?", "out"), true, "only the buyer's words count");
|
||||
assert.equal(await ask("Wie ist die Adresse?", "in", true), true, "a hidden message is never read");
|
||||
});
|
||||
|
||||
test("signing out forgets the token", async () => {
|
||||
open(`#/login/${TOKEN}`);
|
||||
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
|
||||
|
||||
Reference in New Issue
Block a user