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
24 changes: 20 additions & 4 deletions apps/ios/app/shared/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isTextKind, withReferral, type Item, type List, type PublicList } from "@pluck/shared-schemas";
import { isTextKind, REPORT_REASONS, withReferral, type Item, type List, type PublicList } from "@pluck/shared-schemas";
import { Refused } from "@pluck/client";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { router, useLocalSearchParams } from "expo-router";
Expand Down Expand Up @@ -61,6 +61,17 @@ export default function SharedList() {
},
]);

// Something wrong with it: why, from the same reasons the public page asks, sent to a person. iOS's own alert,
// which lists them on iPhone and iPad alike.
const report = () =>
Alert.alert(tr("shared.reportTitle"), undefined, [
...REPORT_REASONS.map((reason) => ({
text: tr(`shared.reportReasons.${reason}`),
onPress: () => void api(`/api/v1/shared/${id}/report`, { json: { reason } }).then(() => toast(tr("shared.reported")), failed),
})),
{ text: tr("common.cancel"), style: "cancel" as const },
]);

return (
<View style={{ flex: 1, backgroundColor: t.ground }}>
<View style={[styles.top, { paddingTop: insets.top + 8 }]}>
Expand All @@ -69,9 +80,14 @@ export default function SharedList() {
<Text maxFontSizeMultiplier={scale.title} style={[font.regular, { color: t.ink, fontSize: 15 }]}>{tr("tabs.lists")}</Text>
</Pressable>
{list && (
<Pressable accessibilityRole="button" onPress={leave} style={styles.leave}>
<Text maxFontSizeMultiplier={scale.title} style={[font.regular, { color: t.ink2, fontSize: 15 }]}>{tr("shared.leave")}</Text>
</Pressable>
<View style={{ flexDirection: "row" }}>
<Pressable accessibilityRole="button" onPress={report} style={styles.leave}>
<Text maxFontSizeMultiplier={scale.title} style={[font.regular, { color: t.ink2, fontSize: 15 }]}>{tr("shared.report")}</Text>
</Pressable>
<Pressable accessibilityRole="button" onPress={leave} style={styles.leave}>
<Text maxFontSizeMultiplier={scale.title} style={[font.regular, { color: t.ink2, fontSize: 15 }]}>{tr("shared.leave")}</Text>
</Pressable>
</View>
)}
</View>
<FlatList
Expand Down
13 changes: 10 additions & 3 deletions apps/ios/components/split/Shortcuts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isTask, withReferral } from "@pluck/shared-schemas";
import * as Clipboard from "expo-clipboard";
import * as Haptics from "expo-haptics";
import { router } from "expo-router";
import { router, usePathname } from "expo-router";
import * as WebBrowser from "expo-web-browser";
import { useEffect, useRef } from "react";
import { Share } from "react-native";
Expand All @@ -12,9 +12,16 @@ import { toast } from "../Toast";
import { shown, useSplit } from "./context";
import { useGo } from "./Sidebar";

// The sheets and modals that come up over the split view (app/_layout.tsx).
const OVER = /^\/(pick|add|tags|note|handle|share|settings)(\/|$)/;

// The iPad's keyboard (iPad-Shortcuts board), held ⌘ to see: the open Item's moves on single letters, the places on
// ⌘ and a number, and plucking. Mounted with the split view, so a narrow window (the iPhone layout) has none.
export function Shortcuts() {
// While a sheet is up, the keys that act on what is behind it (the single letters, the arrows, ⌘V) step aside, as
// they do while a field is being edited. The sheet's own field may not have the keyboard yet: a tag name typed
// there must not archive the Item underneath on its "e".
const over = OVER.test(usePathname());
const tr = useTranslations("ios");
const split = useSplit();
const go = useGo();
Expand Down Expand Up @@ -80,12 +87,12 @@ export function Shortcuts() {
run.current = (id) => commands.find((c) => c.id === id)?.run();
const titles = commands.map((c) => c.title).join("|"); // set again only if the words change (another language)
useEffect(() => {
void keyCommands.set(commands.map(({ run: _, ...c }) => c));
void keyCommands.set(commands.filter((c) => !(over && c.typing === false)).map(({ run: _, ...c }) => c));
const sub = keyCommands.listen((id) => run.current(id));
return () => {
sub.remove();
void keyCommands.set([]);
};
}, [titles]);
}, [titles, over]);
return null;
}
10 changes: 10 additions & 0 deletions apps/web/app/api/v1/shared/[id]/report/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SharedReportBody } from "@pluck/shared-schemas";
import { parseBody, route } from "@/lib/api";
import { reportShared } from "@/lib/library";

// Report a List someone shared with you. It goes to a person, with the reports from public pages.
export const POST = route<{ id: string }>({ kind: "write" }, async ({ req, caller, params }) => {
const b = await parseBody(req, SharedReportBody);
await reportShared(caller.userId, params.id, b.reason, b.details);
return new Response(null, { status: 204 });
});
8 changes: 5 additions & 3 deletions apps/web/app/p/[handle]/[slug]/ReportLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { useTranslations } from "next-intl";
import { useState, type FormEvent } from "react";
import styles from "./public.module.css";

// The Report link in the footer: a short form, sent to a person.
export function ReportLink({ listId }: { listId: string }) {
// The Report link in the footer: a short form, sent to a person. `shared`: on a List shared with you, which may be
// private, the report goes in as the signed-in person it is shared with.
export function ReportLink({ listId, shared = false }: { listId: string; shared?: boolean }) {
const t = useTranslations("site.publicList.report");
const [open, setOpen] = useState(false);
const [reason, setReason] = useState<(typeof REPORT_REASONS)[number]>("spam");
Expand All @@ -15,7 +16,8 @@ export function ReportLink({ listId }: { listId: string }) {

async function send(e: FormEvent) {
e.preventDefault();
const res = await fetch("/api/v1/reports", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ listId, reason, details: details || undefined }) });
const [to, about] = shared ? [`/api/v1/shared/${listId}/report`, {}] : ["/api/v1/reports", { listId }];
const res = await fetch(to, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ ...about, reason, details: details || undefined }) });
setState(res.ok ? "sent" : "error");
}

Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/shared/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useFormat } from "@/components/useFormat";
import { ItemRow, RowLead, RowNote } from "@/components/ItemRow";
import { readShared } from "@/lib/library";
import styles from "../../p/[handle]/[slug]/public.module.css";
import { ReportLink } from "../../p/[handle]/[slug]/ReportLink";
import { LeaveButton } from "./LeaveButton";
import { NoAccess } from "./NoAccess";

Expand Down Expand Up @@ -60,6 +61,7 @@ export default async function SharedListPage({ params }: { params: Promise<{ id:
</ol>
<div className={styles.links}>
<LeaveButton listId={list.id} className={styles.leave} />
<ReportLink listId={list.id} shared />
</div>
</main>
</div>
Expand Down
15 changes: 15 additions & 0 deletions apps/web/lib/library/sharing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { signedUrl } from "@pluck/blob";
import {
createList, createReport, createTextItem, getListMeta, getMe, hitRateLimit, leaveSharedList, listOwnedBy, listsSharedWith, pluckLink, publicCoverKey,
reportSharedList,
publicList, publicListById, recordView, setHandle, setName, setVisibility, sharedCoverKey, sharedList, shareList, sharesOf, unshareList,
setHeardFrom, updateSettings, MAX_PEOPLE,
} from "@pluck/db";
Expand Down Expand Up @@ -173,6 +174,20 @@ export async function readShared(userId: string, listId: string): Promise<Public
return page;
}

// A report on a List shared with you: to the same person who reads the public pages' reports. A few a day per
// account, since each one is an email to a person.
export async function reportShared(userId: string, listId: string, reason: string, details?: string): Promise<void> {
if (!(await hitRateLimit(`report:${userId}`, 10, 86_400)).ok) throw new ApiError("rate_limited", "That is a lot of reports for one day. Try again tomorrow.", 429);
if (!(await reportSharedList(listId, (await me(userId)).email, reason, details ?? null))) throw new ApiError("not_found", "That List is not shared with you.", 404);
const to = process.env.ABUSE_EMAIL;
if (!to) return;
await sendEmail({
to,
subject: `Report: ${reason} on shared list ${listId}`,
text: `A List was reported by someone it is shared with. It may be private.\n\nList: ${listId}\nReason: ${reason}\nDetails: ${details ?? "(none)"}\n\nReview it in /admin.\n`,
}).catch((e) => log("error", "report email failed", { error: e }));
}

export async function leaveShared(userId: string, listId: string): Promise<void> {
if (!(await leaveSharedList(listId, (await me(userId)).email))) throw new ApiError("not_found", "That List is not shared with you.", 404);
}
Expand Down
1 change: 1 addition & 0 deletions docs/ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ The share extension and the shared Keychain need real signing, so these are chec
17. Add, the microphone in the box: iOS asks twice; say a sentence, tap stop: the words are in the box, and Pluck it makes a Note. In a Note, tap the microphone in the bar, speak over a pause, tap stop: the words are where the caret was. Airplane mode: it still works in a language the phone recognises itself (English, for one).
18. Add, type a sentence, tap a List chip and a tag chip, Pluck it: the row in the Inbox shows the tag, the Item shows it under its title, and the List holds the Item. Tap the chip there: the tag picker opens. Add, Note, type a line: a Tags chip appears under the title; pick a tag and it shows in its place.
19. A new account (sign in with an email never used): the Inbox holds "Nothing is deleted.", and Lists holds Favourites (empty) and Ideas with "Ask your AI what you plucked." in it. Lists, the +: type a name, Add: the new List opens. In a Note, type `#recipes` and a space: a recipes chip appears under the title within a second. Change the word to `#recipe`: the chip changes with it, and Settings, Tags shows no leftover.
20. A List someone shared with you: Report asks what is wrong (iOS's own alert, eight reasons), and choosing one says "Thanks. A person reads every report."; Leave still takes it off your Lists. On an iPad with a keyboard: open an Item, press T, and type a tag name without tapping the field first: nothing behind the sheet moves (the single-letter keys, the arrows and ⌘V step aside while a sheet is up).

## Known gaps

Expand Down
6 changes: 6 additions & 0 deletions e2e/lists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,19 @@ test("share a List with one person, See only: the email link, their Lists, no ta
await expect(visitor.getByText("Book early.")).toBeVisible();
await expect(visitor.getByText("private-tag")).toHaveCount(0);
await expect(visitor.getByRole("checkbox")).toHaveCount(0); // no marks: they are the owner's
// Something wrong with it: a report goes to a person, from someone it is shared with.
await visitor.getByRole("button", { name: "Report this list" }).click();
await visitor.getByLabel("What is wrong?").selectOption("harassment");
await visitor.getByRole("button", { name: "Send the report" }).click();
await expect(visitor.getByRole("status").filter({ hasText: "A person reads every report." })).toBeVisible();
await visitor.goto("/lists");
await expect(visitor.getByRole("region", { name: "Shared with you" })).toContainText("Holiday ideas");

// Someone else signed in cannot open it.
const stranger = await (await browser.newContext()).newPage();
await signIn(stranger);
expect((await stranger.request.get(`/api/v1/shared/${list.id}`)).status()).toBe(404);
expect((await stranger.request.post(`/api/v1/shared/${list.id}/report`, { data: { reason: "spam" } })).status()).toBe(404); // nor report it
await stranger.goto(`/shared/${list.id}`);
await expect(stranger.getByRole("heading", { name: "Not shared with you." })).toBeVisible();
await expect(stranger.getByRole("button", { name: "Use another email" })).toBeVisible();
Expand Down
3 changes: 2 additions & 1 deletion packages/db/src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export const DEFAULT_SETTINGS: UserSettings = { expiryDays: 30, expiryScope: "in
export type ReportDoc = {
_id: ObjectId;
listId: ObjectId;
reporterIp: string; // a salted hash, never the address itself
reporterIp: string; // a salted hash, never the address itself (for a shared List, of the email it was shared with)
shared?: true; // reported by someone it was shared with, not from its public page: it may well be private
reason: string;
details: string | null;
createdAt: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export { analyticsOf, claimStarters, getMe, markMcpCall, setHeardFrom, setName,
export { expireItems, archiveStale, countExpiringSoon, runDueExpiry, claimOnce, localNow } from "./expiry.ts";
export { DEFAULT_SETTINGS, type SignUpVia, type UserSettings } from "./collections.ts";
export { publicList, publicListById, publicCoverKey, recordView, createReport, PUBLIC_ITEM_FIELDS, sharedList, listsSharedWith, sharedCoverKey } from "./public.ts";
export { shareList, sharesOf, unshareList, leaveSharedList, MAX_PEOPLE, type ShareResult } from "./shares.ts";
export { shareList, sharesOf, unshareList, leaveSharedList, reportSharedList, MAX_PEOPLE, type ShareResult } from "./shares.ts";
export { openReports, resolveReport, killList, killUser, isAdminEmail } from "./admin.ts";
export { digestFor, isEmptyDigest, claimDueDigests, sendDigestOnce } from "./digest.ts";
export { aliasOf, regenerateAlias, userForAlias, createEmailItem, setRawEmailKey, type EmailItemInput } from "./email-in.ts";
Expand Down
19 changes: 18 additions & 1 deletion packages/db/src/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from "vitest";
import {
applyExtraction, createList, createTag, editItem, getListMeta, getMe, killList, killUser, moveToBin, pluckLink, PUBLIC_ITEM_FIELDS,
publicCoverKey, publicList, publicListById, recordView, setHandle, setItemTags, setBlobKeys, setVisibility, updateEntry, updateList,
addToList, deleteList, leaveSharedList, listsSharedWith, sharedList, shareList, sharesOf, unshareList, updateSettings,
addToList, deleteList, leaveSharedList, listsSharedWith, openReports, reportSharedList, sharedList, shareList, sharesOf, unshareList, updateSettings,
} from "./index.ts";
import { twoUsers } from "./testing.ts";

Expand Down Expand Up @@ -173,3 +173,20 @@ describe("lists shared with people (See only)", () => {
expect(await listsSharedWith("c@example.test")).toEqual([]);
});
});

test("a List can be reported by someone it is shared with, and by nobody else; the report reaches the admin's list", async () => {
const { a, b } = await twoUsers();
const list = await createList(a, { name: `Private and shared ${Date.now()}`, createdBy: "user" });
const [aEmail, bEmail] = [(await getMe(a))!.email, (await getMe(b))!.email];
// Not shared yet: b has no say on a List they cannot see. Nor has its owner, nor a stranger, once it is shared.
expect(await reportSharedList(list.id, bEmail, "spam", null)).toBe(false);
await shareList(a, list.id, bEmail);
expect(await reportSharedList(list.id, aEmail, "spam", null)).toBe(false);
expect(await reportSharedList(list.id, "stranger@example.test", "spam", null)).toBe(false);
expect(await reportSharedList(list.id, bEmail.toUpperCase(), "harassment", " Not for me. ")).toBe(true);
const mine = (await openReports()).filter((r) => r.list?.id === list.id);
expect(mine.map((r) => [r.reason, r.details, r.list?.name])).toEqual([["harassment", "Not for me.", list.name]]);
// Leaving ends it: no more reports from someone it is no longer shared with.
await leaveSharedList(list.id, bEmail);
expect(await reportSharedList(list.id, bEmail, "spam", null)).toBe(false);
});
17 changes: 16 additions & 1 deletion packages/db/src/shares.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Locale } from "@pluck/i18n";
import type { ListShare } from "@pluck/shared-schemas";
import { createHash } from "node:crypto";
import { ObjectId } from "mongodb";
import { lists, listShares, oid, users, type ListShareDoc } from "./collections.ts";
import { lists, listShares, oid, reports, users, type ListShareDoc } from "./collections.ts";
import { getMe } from "./users.ts";

// Sharing a list with people, See only. The owner adds and removes them by email; they read it through public.ts.
Expand Down Expand Up @@ -49,6 +50,20 @@ export async function unshareList(userId: string, listId: string, shareId: strin
return res.deletedCount === 1;
}

// A report from someone the List is shared with, kept with the reports from public pages (packages/db/src/public.ts)
// for the same person to read. Only someone it is shared with can make one; who, is kept as a salted hash.
export async function reportSharedList(listId: string, viewerEmail: string, reason: string, details: string | null): Promise<boolean> {
const email = viewerEmail.toLowerCase();
const share = await (await listShares()).findOne({ listId: oid(listId), email }, { projection: { _id: 1 } });
if (!share) return false;
const salt = process.env.BETTER_AUTH_SECRET ?? "pluck";
await (await reports()).insertOne({
_id: new ObjectId(), listId: oid(listId), reporterIp: createHash("sha256").update(`${salt}:${email}`).digest("hex").slice(0, 32),
reason, details: details?.trim().slice(0, 2000) || null, createdAt: new Date(), state: "open", shared: true,
});
return true;
}

// The person it was shared with takes it off their Lists.
export async function leaveSharedList(listId: string, viewerEmail: string): Promise<boolean> {
const res = await (await listShares()).deleteOne({ listId: oid(listId), email: viewerEmail.toLowerCase() });
Expand Down
13 changes: 13 additions & 0 deletions packages/i18n/messages/ios/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@
"leaveTitle": "Diese Liste verlassen?",
"leaveBody": "Sie verschwindet aus deinen Listen. Sie kann wieder mit dir geteilt werden.",
"leave": "Verlassen",
"report": "Melden",
"reportTitle": "Was stimmt nicht?",
"reportReasons": {
"illegal": "Illegale Inhalte",
"minors": "Sexualisiert Minderjährige",
"harassment": "Belästigung",
"doxxing": "Veröffentlicht private Daten anderer",
"spam": "Spam oder eine Linkfarm",
"malware": "Schadsoftware oder Phishing",
"infringement": "Urheber- oder Markenrecht",
"other": "Etwas anderes"
},
"reported": "Danke. Ein Mensch liest jede Meldung.",
"byNamed": "Mit dir geteilt von {name} (@{handle}) · nur ansehen",
"by": "Mit dir geteilt von @{handle} · nur ansehen",
"notShared": {
Expand Down
13 changes: 13 additions & 0 deletions packages/i18n/messages/ios/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@
"leaveTitle": "Leave this List?",
"leaveBody": "It comes off your Lists. They can share it with you again.",
"leave": "Leave",
"report": "Report",
"reportTitle": "What is wrong?",
"reportReasons": {
"illegal": "Illegal content",
"minors": "Sexualises minors",
"harassment": "Harassment",
"doxxing": "Shares someone's private details",
"spam": "Spam or a link farm",
"malware": "Malware or phishing",
"infringement": "Copyright or trademark",
"other": "Something else"
},
"reported": "Thanks. A person reads every report.",
"byNamed": "Shared with you by {name} (@{handle}) · see only",
"by": "Shared with you by @{handle} · see only",
"notShared": {
Expand Down
13 changes: 13 additions & 0 deletions packages/i18n/messages/ios/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@
"leaveTitle": "¿Salir de esta Lista?",
"leaveBody": "Desaparece de tus Listas. Esa persona puede volver a compartirla contigo.",
"leave": "Salir",
"report": "Denunciar",
"reportTitle": "¿Qué ocurre?",
"reportReasons": {
"illegal": "Contenido ilegal",
"minors": "Sexualiza a menores",
"harassment": "Acoso",
"doxxing": "Comparte datos privados de alguien",
"spam": "Spam o granja de enlaces",
"malware": "Malware o phishing",
"infringement": "Derechos de autor o marcas",
"other": "Otra cosa"
},
"reported": "Gracias. Una persona lee cada denuncia.",
"byNamed": "Compartida contigo por {name} (@{handle}) · solo lectura",
"by": "Compartida contigo por @{handle} · solo lectura",
"notShared": {
Expand Down
Loading
Loading