messaging: owners can block a conversation
A blocked thread key is dropped unread (not announced, not counted against the daily new-conversation limit). API, UI button with confirmation, and a list with unblock. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
Vendored
+56
-1
@@ -291,6 +291,11 @@ var de = {
|
||||
"own.delete": "Unterhaltung l\xF6schen",
|
||||
"own.deleteSure": "Wirklich l\xF6schen? Sie wird von deinem Knoten entfernt.",
|
||||
"own.deleteYes": "Ja, l\xF6schen",
|
||||
"own.block": "Blockieren",
|
||||
"own.blockSure": "Blockieren? Die Unterhaltung wird gel\xF6scht und weitere Nachrichten dieser Person werden ungelesen verworfen. Sie erf\xE4hrt davon nichts.",
|
||||
"own.blockYes": "Ja, blockieren",
|
||||
"own.blocked": "Blockiert ({n})",
|
||||
"own.unblock": "Freigeben",
|
||||
"own.sheetTitle": "Adresse freigeben",
|
||||
"own.sheetHelp": "Eine signierte Nachricht, nur f\xFCr diese Person sichtbar. Ihr Bildschirm blendet sie nach dem Datum aus. Sie k\xF6nnte sie trotzdem kopiert haben.",
|
||||
"own.fNote": "Hinweis an die Person",
|
||||
@@ -543,6 +548,11 @@ var en = {
|
||||
"own.delete": "Delete conversation",
|
||||
"own.deleteSure": "Really delete? It is removed from your node.",
|
||||
"own.deleteYes": "Yes, delete",
|
||||
"own.block": "Block",
|
||||
"own.blockSure": "Block? The conversation is deleted and anything more from this person is dropped unread. They are not told.",
|
||||
"own.blockYes": "Yes, block",
|
||||
"own.blocked": "Blocked ({n})",
|
||||
"own.unblock": "Unblock",
|
||||
"own.sheetTitle": "Release address",
|
||||
"own.sheetHelp": "A signed message, visible only to this person. Their screen hides it after the date. They could still have copied it.",
|
||||
"own.fNote": "Note to the buyer",
|
||||
@@ -4864,6 +4874,15 @@ async function sendReply(listing, thread, r) {
|
||||
async function deleteThread(listing, thread) {
|
||||
await call("DELETE", `/api/v1/inbox/${e(listing)}/${e(thread)}`);
|
||||
}
|
||||
async function blockThread(listing, thread) {
|
||||
await call("PUT", `/api/v1/inbox/${e(listing)}/${e(thread)}/block`);
|
||||
}
|
||||
async function unblockThread(listing, thread) {
|
||||
await call("DELETE", `/api/v1/inbox/${e(listing)}/${e(thread)}/block`);
|
||||
}
|
||||
async function getBlocked() {
|
||||
return await call("GET", "/api/v1/blocked");
|
||||
}
|
||||
async function getAddress(listing) {
|
||||
try {
|
||||
return await call("GET", `/api/v1/listings/${e(listing)}/address`);
|
||||
@@ -4978,6 +4997,7 @@ async function showOwner(listingId, thread) {
|
||||
addr.root,
|
||||
chips,
|
||||
reqBox,
|
||||
blockedList(listingId, () => void refresh()),
|
||||
h("p", { class: "muted small" }, t("own.limitNote"))
|
||||
] : [h("p", { class: "muted pick" }, t("own.pickListing"))]
|
||||
);
|
||||
@@ -4995,7 +5015,8 @@ async function showOwner(listingId, thread) {
|
||||
firstNote,
|
||||
addressHint,
|
||||
composer2(listingId, thread, () => void refresh(), (opener) => openSheet(listingId, thread, opener, () => void refresh())),
|
||||
deleteControl2(listingId, thread)
|
||||
deleteControl2(listingId, thread),
|
||||
blockControl(listingId, thread)
|
||||
]);
|
||||
} else {
|
||||
threadPane.append(h("p", { class: "muted pick" }, listingId ? t("own.pickRequest") : ""));
|
||||
@@ -5273,6 +5294,40 @@ function deleteControl2(listingId, thread) {
|
||||
slot.append(h("button", { type: "button", class: "btn", onclick: ask }, t("own.delete")));
|
||||
return slot;
|
||||
}
|
||||
function blockControl(listingId, thread) {
|
||||
const slot = h("p", null);
|
||||
const ask = () => {
|
||||
clear(slot);
|
||||
append(slot, [
|
||||
t("own.blockSure"),
|
||||
" ",
|
||||
h("button", { type: "button", class: "btn", onclick: () => void blockThread(listingId, thread).then(() => location.hash = `#/mine/${listingId}`) }, t("own.blockYes"))
|
||||
]);
|
||||
};
|
||||
slot.append(h("button", { type: "button", class: "btn", onclick: ask }, t("own.block")));
|
||||
return slot;
|
||||
}
|
||||
function blockedList(listingId, changed) {
|
||||
const box = h("details", { class: "blocked", hidden: true });
|
||||
void getBlocked().then((all) => {
|
||||
const mine2 = all.filter((b) => b.listing === listingId);
|
||||
if (mine2.length === 0) return;
|
||||
box.hidden = false;
|
||||
append(box, [
|
||||
h("summary", null, t("own.blocked", { n: mine2.length })),
|
||||
...mine2.map(
|
||||
(b) => h(
|
||||
"p",
|
||||
{ class: "muted small" },
|
||||
`#${b.thread.slice(0, 6)} \xB7 ${new Date(b.blocked_at * 1e3).toLocaleDateString()} `,
|
||||
h("button", { type: "button", class: "btn", onclick: () => void unblockThread(listingId, b.thread).then(changed) }, t("own.unblock"))
|
||||
)
|
||||
)
|
||||
]);
|
||||
}).catch(() => {
|
||||
});
|
||||
return box;
|
||||
}
|
||||
function addressCard(listingId, changed) {
|
||||
const root = h("div", { class: "panel addr" });
|
||||
let saved = null;
|
||||
|
||||
@@ -199,6 +199,11 @@ const de = {
|
||||
"own.delete": "Unterhaltung löschen",
|
||||
"own.deleteSure": "Wirklich löschen? Sie wird von deinem Knoten entfernt.",
|
||||
"own.deleteYes": "Ja, löschen",
|
||||
"own.block": "Blockieren",
|
||||
"own.blockSure": "Blockieren? Die Unterhaltung wird gelöscht und weitere Nachrichten dieser Person werden ungelesen verworfen. Sie erfährt davon nichts.",
|
||||
"own.blockYes": "Ja, blockieren",
|
||||
"own.blocked": "Blockiert ({n})",
|
||||
"own.unblock": "Freigeben",
|
||||
"own.sheetTitle": "Adresse freigeben",
|
||||
"own.sheetHelp":
|
||||
"Eine signierte Nachricht, nur für diese Person sichtbar. Ihr Bildschirm blendet sie nach dem Datum aus. Sie könnte sie trotzdem kopiert haben.",
|
||||
@@ -476,6 +481,11 @@ const en: Record<keyof typeof de, string> = {
|
||||
"own.delete": "Delete conversation",
|
||||
"own.deleteSure": "Really delete? It is removed from your node.",
|
||||
"own.deleteYes": "Yes, delete",
|
||||
"own.block": "Block",
|
||||
"own.blockSure": "Block? The conversation is deleted and anything more from this person is dropped unread. They are not told.",
|
||||
"own.blockYes": "Yes, block",
|
||||
"own.blocked": "Blocked ({n})",
|
||||
"own.unblock": "Unblock",
|
||||
"own.sheetTitle": "Release address",
|
||||
"own.sheetHelp":
|
||||
"A signed message, visible only to this person. Their screen hides it after the date. They could still have copied it.",
|
||||
|
||||
@@ -111,6 +111,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
addr!.root,
|
||||
chips,
|
||||
reqBox,
|
||||
blockedList(listingId, () => void refresh()),
|
||||
h("p", { class: "muted small" }, t("own.limitNote")),
|
||||
]
|
||||
: [h("p", { class: "muted pick" }, t("own.pickListing"))],
|
||||
@@ -132,6 +133,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
|
||||
addressHint,
|
||||
composer(listingId, thread, () => void refresh(), (opener) => openSheet(listingId, thread, opener, () => void refresh())),
|
||||
deleteControl(listingId, thread),
|
||||
blockControl(listingId, thread),
|
||||
]);
|
||||
} else {
|
||||
threadPane.append(h("p", { class: "muted pick" }, listingId ? t("own.pickRequest") : ""));
|
||||
@@ -451,6 +453,45 @@ function deleteControl(listingId: string, thread: string): HTMLElement {
|
||||
return slot;
|
||||
}
|
||||
|
||||
function blockControl(listingId: string, thread: string): HTMLElement {
|
||||
const slot = h("p", null);
|
||||
const ask = () => {
|
||||
clear(slot);
|
||||
append(slot, [
|
||||
t("own.blockSure"),
|
||||
" ",
|
||||
h("button", { type: "button", class: "btn", onclick: () => void o.blockThread(listingId, thread).then(() => (location.hash = `#/mine/${listingId}`)) }, t("own.blockYes")),
|
||||
]);
|
||||
};
|
||||
slot.append(h("button", { type: "button", class: "btn", onclick: ask }, t("own.block")));
|
||||
return slot;
|
||||
}
|
||||
|
||||
/** The blocked conversations of one listing, each with a way to lift the block. */
|
||||
function blockedList(listingId: string, changed: () => void): HTMLElement {
|
||||
const box = h("details", { class: "blocked", hidden: true });
|
||||
void o
|
||||
.getBlocked()
|
||||
.then((all) => {
|
||||
const mine = all.filter((b) => b.listing === listingId);
|
||||
if (mine.length === 0) return;
|
||||
box.hidden = false;
|
||||
append(box, [
|
||||
h("summary", null, t("own.blocked", { n: mine.length })),
|
||||
...mine.map((b) =>
|
||||
h(
|
||||
"p",
|
||||
{ class: "muted small" },
|
||||
`#${b.thread.slice(0, 6)} · ${new Date(b.blocked_at * 1000).toLocaleDateString()} `,
|
||||
h("button", { type: "button", class: "btn", onclick: () => void o.unblockThread(listingId, b.thread).then(changed) }, t("own.unblock")),
|
||||
),
|
||||
),
|
||||
]);
|
||||
})
|
||||
.catch(() => {});
|
||||
return box;
|
||||
}
|
||||
|
||||
/** The listing's saved address, shown and editable. It lives on this node only. */
|
||||
function addressCard(listingId: string, changed: () => void): { root: HTMLElement } {
|
||||
const root = h("div", { class: "panel addr" });
|
||||
|
||||
@@ -157,6 +157,24 @@ export async function deleteThread(listing: string, thread: string): Promise<voi
|
||||
await call("DELETE", `/api/v1/inbox/${e(listing)}/${e(thread)}`);
|
||||
}
|
||||
|
||||
export async function blockThread(listing: string, thread: string): Promise<void> {
|
||||
await call("PUT", `/api/v1/inbox/${e(listing)}/${e(thread)}/block`);
|
||||
}
|
||||
|
||||
export async function unblockThread(listing: string, thread: string): Promise<void> {
|
||||
await call("DELETE", `/api/v1/inbox/${e(listing)}/${e(thread)}/block`);
|
||||
}
|
||||
|
||||
export interface Blocked {
|
||||
listing: string;
|
||||
thread: string;
|
||||
blocked_at: number;
|
||||
}
|
||||
|
||||
export async function getBlocked(): Promise<Blocked[]> {
|
||||
return (await call("GET", "/api/v1/blocked")) as Blocked[];
|
||||
}
|
||||
|
||||
/** The saved address of a listing, or null if none is saved. */
|
||||
export async function getAddress(listing: string): Promise<Address | null> {
|
||||
try {
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
}
|
||||
// The owner's token-protected routes are played by the test, if it sets `owner`.
|
||||
const writesListing = req.method !== "GET" && /^\/api\/v1\/listings(\/[0-9a-f]{32})?$/.test(url.pathname);
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
if (writesListing || /^\/api\/v1\/(mine|inbox|regions|blocked)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
|
||||
@@ -18,6 +18,7 @@ function fakeNode() {
|
||||
const s = {
|
||||
token: TOKEN,
|
||||
calls: [] as { method: string; path: string; body: string; auth: string }[],
|
||||
blocked: [] as { listing: string; thread: string; blocked_at: number }[],
|
||||
address: { address: "Musterweg 7, 22765 Hamburg", phone: "+49 40 1" } as Address | null,
|
||||
mine: [
|
||||
{ id: L1, title: "Helle Wohnung", kind: "rent", price: { amount_cents: 115000, currency: "EUR", period: "month" }, expires_at: NOW + 86400 * 30, threads: 3, needs_reply: 1, hidden: 1, address_saved: true },
|
||||
@@ -46,6 +47,13 @@ function fakeNode() {
|
||||
if (regions.includes("zzz")) return { status: 400, body: { error: `"zzz" is not a region: use 3 geohash characters` } };
|
||||
return { status: 200, body: { regions } };
|
||||
}
|
||||
if (r.path === "/api/v1/blocked") return { status: 200, body: s.blocked };
|
||||
const bl = /^\/api\/v1\/inbox\/([0-9a-f]{32})\/([0-9a-f]{64})\/block$/.exec(r.path);
|
||||
if (bl) {
|
||||
if (r.method === "DELETE") s.blocked = s.blocked.filter((b) => b.thread !== bl[2]);
|
||||
else s.blocked.push({ listing: bl[1]!, thread: bl[2]!, blocked_at: NOW });
|
||||
return { status: 204 };
|
||||
}
|
||||
if (r.path === "/api/v1/inbox") return { status: 200, body: s.threads.filter((t) => t.listing === r.query.get("listing")) };
|
||||
const th = /^\/api\/v1\/inbox\/([0-9a-f]{32})\/([0-9a-f]{64})$/.exec(r.path);
|
||||
if (th) {
|
||||
@@ -329,6 +337,23 @@ test("deleting a conversation asks first, then goes back to the requests", async
|
||||
assert.equal(node.s.calls.filter((c) => c.method === "DELETE")[0]!.path, `/api/v1/inbox/${L1}/${T_LINK}`);
|
||||
});
|
||||
|
||||
test("blocking asks first, goes back to the requests, and can be undone", async () => {
|
||||
open(`#/login/${TOKEN}`);
|
||||
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
|
||||
page!.window.location.hash = `#/mine/${L1}/${T_LINK}`;
|
||||
await page!.waitFor(() => button("Block") !== undefined, "the block button");
|
||||
|
||||
button("Block")!.click();
|
||||
assert.equal(node.s.blocked.length, 0, "nothing is blocked by one click");
|
||||
button("Yes, block")!.click();
|
||||
await page!.waitFor(() => page!.window.location.hash === `#/mine/${L1}`, "back to the requests");
|
||||
assert.equal(node.s.blocked[0]!.thread, T_LINK);
|
||||
|
||||
await page!.waitFor(() => text().includes("Blocked (1)"), "the blocked list");
|
||||
button("Unblock")!.click();
|
||||
await page!.waitFor(() => node.s.blocked.length === 0, "the block lifted");
|
||||
});
|
||||
|
||||
test("a token that stops working sends the owner back to sign in", async () => {
|
||||
open(`#/login/${TOKEN}`);
|
||||
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
|
||||
|
||||
Reference in New Issue
Block a user