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: 3 additions & 1 deletion apps/api/scripts/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Also brings each site's public look up to date and adds starter public pages (landing copy, footer
// pages, guides) that a site doesn't have yet. It never touches members, and never overwrites a page an
// admin edited or brings back one an admin deleted.
import { addStarterPages, seedSites, upgradeSiteFields, upgradeSiteTheme, type Site } from '@whatbox/core';
import { addPolicyNotices, addStarterPages, seedSites, upgradeSiteFields, upgradeSiteTheme, type Site } from '@whatbox/core';
import { Client } from 'pg';
import { config, dbUrl } from '../src/config';
import { closePools, pool } from '../src/db-pool';
Expand All @@ -29,6 +29,8 @@ import { applySql, ensureDb } from '../src/provision';
if (upgradeSiteTheme(doc)) console.log(`updated look for ${doc.slug}`);
const wrote = await addStarterPages(doc, new PgSiteRepo(pool(siteDbName(doc.slug))), new Date());
if (wrote.length) console.log(`${doc.slug}: added pages ${wrote.join(', ')}`);
const notices = await addPolicyNotices(doc, new PgSiteRepo(pool(siteDbName(doc.slug))), new Date());
if (notices.length) console.log(`${doc.slug}: added the message-review paragraph to ${notices.join(', ')}`);
if (JSON.stringify(doc) !== before) await c.query('UPDATE sites SET doc=$2, updated_at=now() WHERE id=$1', [doc.id, doc]);
}
await c.end();
Expand Down
18 changes: 13 additions & 5 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { FileInterceptor } from '@nestjs/platform-express';
import { normalizeImage } from './photos';
import { safeReturnUrl } from './payments';
import { type ActivityKind, type ClientPlatform, type ContentPage, type ModerationDecision, type PhotoKind, type PhotoRating, type Platform, type ProfileFieldDef, RuleError, type SearchFilters, type SiteEvent, type Tier } from '@whatbox/core';
import { type ActivityKind, type ClientPlatform, type ContentPage, type ModerationDecision, type PhotoKind, type SuspendReason, type PhotoRating, type Platform, type ProfileFieldDef, RuleError, type SearchFilters, type SiteEvent, type Tier } from '@whatbox/core';
import type { Request, Response } from 'express';

export const PLATFORM = 'PLATFORM';
Expand Down Expand Up @@ -147,8 +147,9 @@ export class MembersController extends SiteScoped {
@Delete(':id/like') async unlike(@Req() r: Request, @Param('id') id: string) { return this.p.like(await this.ctx(r), id, false); }
@Post(':id/block') async block(@Req() r: Request, @Param('id') id: string) { return this.p.block(await this.ctx(r), id, true); }
@Delete(':id/block') async unblock(@Req() r: Request, @Param('id') id: string) { return this.p.block(await this.ctx(r), id, false); }
@Post(':id/report') async report(@Req() r: Request, @Param('id') id: string, @Body() b: { reason?: string }) {
return this.p.report(await this.ctx(r), id, String(b.reason ?? ''));
@Post(':id/report') async report(@Req() r: Request, @Param('id') id: string, @Body() b: { reason?: string; messageId?: string; photoId?: string }) {
const about = { ...(typeof b.messageId === 'string' ? { messageId: b.messageId } : {}), ...(typeof b.photoId === 'string' ? { photoId: b.photoId } : {}) };
return this.p.report(await this.ctx(r), id, String(b.reason ?? ''), about);
}
@Post(':id/private-access') async request(@Req() r: Request, @Param('id') id: string) { return { status: await this.p.requestAccess(await this.ctx(r), id) }; }
}
Expand Down Expand Up @@ -232,8 +233,15 @@ export class AdminController {
@Get('sites/:site/members/:id') async memberProfile(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string) {
return this.p.adminMemberProfile(await this.admin(a), s, id);
}
@Patch('sites/:site/members/:id') async memberStatus(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string, @Body() b: { status: 'active' | 'suspended' }) {
return this.p.adminSetMemberStatus(await this.admin(a), s, id, b.status);
@Patch('sites/:site/members/:id') async memberStatus(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string, @Body() b: { status: 'active' | 'suspended'; reason?: SuspendReason; notifyContacts?: boolean }) {
const reason = b.reason === 'scam' || b.reason === 'safety' || b.reason === 'other' ? b.reason : undefined;
return this.p.adminSetMemberStatus(await this.admin(a), s, id, b.status, { reason, notifyContacts: b.notifyContacts === true });
}
@Get('sites/:site/members/:id/conversations') async memberConversations(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string) {
return this.p.adminMemberConversations(await this.admin(a), s, id);
}
@Get('sites/:site/members/:id/conversations/:other') async memberConversation(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string, @Param('other') o: string) {
return this.p.adminMemberConversation(await this.admin(a), s, id, o);
}
@Patch('sites/:site/members/:id/tier') async memberTier(@Headers('authorization') a: string, @Param('site') s: string, @Param('id') id: string, @Body() b: { tier: Tier }) {
return this.p.adminSetMemberTier(await this.admin(a), s, id, b.tier);
Expand Down
16 changes: 15 additions & 1 deletion apps/api/src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// arriving on a shared phone or inbox gives nothing away (sensitive sites especially).
import { EmailClient } from '@azure/communication-email';
import { SmsClient } from '@azure/communication-sms';
import type { Notifier, Site } from '@whatbox/core';
import { type Notifier, safetyNoticeContent, type Site } from '@whatbox/core';
import { config } from './config';

export function codeText(site: Site, code: string) {
Expand All @@ -15,6 +15,9 @@ export const consoleNotifier: Notifier = {
const masked = channel === 'email' ? target.replace(/^(.).*@/, '$1•••@') : '•••' + target.slice(-2);
console.log(`[notify] ${site.slug} ${channel} ${masked} code=${config.exposeDevCodes ? code : '(hidden)'}`);
},
async sendSafetyNotice({ site, email, displayName }) {
console.log(`[notify] ${site.slug} safety notice to ${email.replace(/^(.).*@/, '$1•••@')} about "${displayName}"`);
},
async sendAdminCode({ email, code }) {
console.log(`[notify] admin ${email.replace(/^(.).*@/, '$1•••@')} code=${config.exposeDevCodes ? code : '(hidden)'}`);
},
Expand Down Expand Up @@ -67,6 +70,17 @@ export class AcsNotifier implements Notifier {
});
}

async sendSafetyNotice({ site, email, displayName }: { site: Site; email: string; displayName: string }) {
const from = this.siteSender(site);
if (!from) throw new Error(`No email sender configured for ${site.id}`);
const c = safetyNoticeContent(site, displayName);
await this.sendEmail(`${site.slug} safety notice ${mask(email)}`, from, {
senderAddress: from,
recipients: { to: [{ address: email }] },
content: { subject: c.subject, plainText: c.text, html: c.html },
});
}

private siteSender(site: Site) {
if (this.emailFrom[site.id]) return this.emailFrom[site.id];
for (const d of site.domains ?? []) {
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/pg-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ export class PgSiteRepo implements SiteRepo {
async saveReport(r: Report) {
await this.db.query('INSERT INTO reports VALUES ($1,$2,$3,$4,$5)', [r.id, r.reporterId, r.targetId, r.reason, r.at]);
}
async listReportsAbout(t: string) {
const r = await this.db.query('SELECT id, reporter_id, target_id, reason, at FROM reports WHERE target_id=$1 ORDER BY at DESC LIMIT 100', [t]);
return r.rows.map((x: any) => ({ id: x.id, reporterId: x.reporter_id, targetId: x.target_id, reason: x.reason, at: new Date(x.at).toISOString() }));
}
async countReports(t: string) { return Number((await this.db.query('SELECT count(*) FROM reports WHERE target_id=$1', [t])).rows[0].count); }
async saveModeration(i: ModerationItem) {
await this.db.query(
Expand Down
23 changes: 18 additions & 5 deletions apps/member/src/app/(app)/member/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function ProfileScreen() {
const [error, setError] = useState<string | null>(null);
const [big, setBig] = useState<PhotoView | undefined>();
const [safety, setSafety] = useState(false);
const [reportPhoto, setReportPhoto] = useState<PhotoView | null>(null);
const [reason, setReason] = useState('');
const [note, setNote] = useState<string | null>(null);

Expand Down Expand Up @@ -62,6 +63,12 @@ export default function ProfileScreen() {
<PhotoTile photo={big} radius={22} style={{ height: wide ? 520 : 400 }} silhouette="80%">
{big?.id === p.mainPhoto?.id ? <View style={{ position: 'absolute', left: 16, top: 16 }}><Badge label="Main photo" tone="online" /></View> : null}
</PhotoTile>
{!preview && big && !big.placeholder ? (
<Pressable accessibilityRole="button" onPress={() => { setReportPhoto(big); setReason(''); setSafety(true); }} style={{ flexDirection: 'row', alignItems: 'center', gap: 6, alignSelf: 'flex-end', minHeight: 36 }}>
<Icon name="flag" size={15} color={t.sub} />
<Txt sub size={14}>Report this photo</Txt>
</Pressable>
) : null}
{all.length > 1 ? (
<>
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
Expand Down Expand Up @@ -135,7 +142,7 @@ export default function ProfileScreen() {
style={{ width: 50, height: 50, borderRadius: 25, borderWidth: 1.5, borderColor: p.favoritedByMe ? '#D9A43A' : t.line, backgroundColor: p.favoritedByMe ? '#FFF4DC' : t.surface, alignItems: 'center', justifyContent: 'center' }}>
<Icon name="star" size={20} color={p.favoritedByMe ? '#A8740F' : t.sub} />
</Pressable>
<Pressable accessibilityLabel="Block or report" onPress={() => setSafety(!safety)} style={{ width: 50, height: 50, borderRadius: 25, borderWidth: 1.5, borderColor: t.line, backgroundColor: t.surface, alignItems: 'center', justifyContent: 'center' }}>
<Pressable accessibilityLabel="Block or report" onPress={() => { setReportPhoto(null); setSafety(!safety); }} style={{ width: 50, height: 50, borderRadius: 25, borderWidth: 1.5, borderColor: t.line, backgroundColor: t.surface, alignItems: 'center', justifyContent: 'center' }}>
<Icon name="flag" size={20} color={t.sub} />
</Pressable>
</View>
Expand All @@ -146,16 +153,22 @@ export default function ProfileScreen() {

{safety ? (
<Card style={{ gap: 12 }}>
<H size={18} level={2}>Safety</H>
<Txt sub size={14}>Reports are private. {p.displayName} won't know who reported them.</Txt>
<H size={18} level={2}>{reportPhoto ? 'Report this photo' : 'Safety'}</H>
{reportPhoto ? (
<View style={{ flexDirection: 'row', gap: 12, alignItems: 'center' }}>
<PhotoTile photo={reportPhoto} style={{ width: 64, height: 64 }} />
<Txt sub size={14} style={{ flex: 1 }}>Our safety team will see this photo with your report. {p.displayName} won't know who reported it.</Txt>
</View>
) : <Txt sub size={14}>Reports are private. {p.displayName} won't know who reported them.</Txt>}
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 8 }}>
{['Asked for money', 'Pushing to another app', 'Fake profile', 'Rude or abusive', 'Underage'].map((r) => (
{(reportPhoto ? ['Not them', 'Stolen or fake photo', 'Explicit', 'Shows someone else', 'Underage'] : ['Asked for money', 'Pushing to another app', 'Fake profile', 'Rude or abusive', 'Underage']).map((r) => (
<Chip key={r} label={r} selected={reason === r} onPress={() => setReason(r)} />
))}
</View>
<Field label="Anything else? (optional)" value={reason} onChangeText={setReason} />
<View style={{ flexDirection: 'row', gap: 10, flexWrap: 'wrap' }}>
<Btn label="Send report" kind="danger" size="sm" onPress={() => act(() => api.report(p.id, reason), 'Thanks. The safety team will review this.').then(() => setSafety(false))} />
<Btn label="Send report" kind="danger" size="sm" onPress={() => act(() => api.report(p.id, reason, reportPhoto ? { photoId: reportPhoto.id } : undefined), 'Thanks. The safety team will review this.').then(() => { setSafety(false); setReportPhoto(null); })} />
{reportPhoto ? <Btn label="Cancel" kind="secondary" size="sm" onPress={() => { setSafety(false); setReportPhoto(null); }} /> : null}
<Btn label={p.blockedByMe ? 'Unblock' : `Block ${p.displayName}`} kind="secondary" size="sm" onPress={() => act(() => api.block(p.id, !p.blockedByMe), p.blockedByMe ? 'Unblocked.' : `${p.displayName} can no longer see you or message you.`)} />
</View>
</Card>
Expand Down
32 changes: 31 additions & 1 deletion apps/member/src/app/(app)/messages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default function Conversation() {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [menu, setMenu] = useState(false);
const [reporting, setReporting] = useState<string | null>(null);
const [reportReason, setReportReason] = useState('');
const [reported, setReported] = useState<Set<string>>(new Set());
const scroll = useRef<any>(null);

const load = useCallback(async () => {
Expand Down Expand Up @@ -73,7 +76,34 @@ export default function Conversation() {
<Txt size={15} color={m.fromMe ? '#FFFFFF' : m.sealed ? t.sub : t.ink}>{m.sealed ? '🔒 ' : ''}{m.body}</Txt>
</View>
{m.notice ? <Txt size={12} sub style={{ textAlign: m.fromMe ? 'right' : 'left' }}>{m.notice}</Txt> : null}
<Txt size={11} sub style={{ textAlign: m.fromMe ? 'right' : 'left' }}>{m.fromMe && m.readAt ? `Read ${clockTime(m.readAt)}` : clockTime(m.at)}</Txt>
<View style={{ flexDirection: 'row', gap: 10, alignSelf: m.fromMe ? 'flex-end' : 'flex-start', alignItems: 'center' }}>
<Txt size={11} sub>{m.fromMe && m.readAt ? `Read ${clockTime(m.readAt)}` : clockTime(m.at)}</Txt>
{!m.fromMe && !m.sealed ? (
reported.has(m.id) ? <Txt size={11} sub>Reported</Txt> : (
<Pressable accessibilityRole="button" accessibilityLabel="Report this message" onPress={() => { setReporting(reporting === m.id ? null : m.id); setReportReason(''); }} hitSlop={8}>
<Txt size={11} sub style={{ textDecorationLine: 'underline' }}>Report</Txt>
</Pressable>
)
) : null}
</View>
{reporting === m.id ? (
<View style={{ backgroundColor: t.surface, borderWidth: 1, borderColor: t.line, borderRadius: 12, padding: 12, gap: 8 }}>
<Txt bold size={14}>Report this message</Txt>
<Txt sub size={13}>Our safety team will see it with your report. {other.displayName} won't know who reported it.</Txt>
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 6 }}>
{['Asked for money', 'Pushing to another app', 'Rude or abusive', 'Spam', 'Seems fake'].map((r) => (
<Btn key={r} size="sm" kind={reportReason === r ? 'primary' : 'secondary'} label={r} onPress={() => setReportReason(r)} />
))}
</View>
<View style={{ flexDirection: 'row', gap: 8 }}>
<Btn size="sm" kind="danger" label="Send report" disabled={!reportReason} onPress={async () => {
try { await api.report(other.id, reportReason, { messageId: m.id }); setReported(new Set([...reported, m.id])); setReporting(null); }
catch (e) { setError(e instanceof ApiError ? e.message : 'Could not send the report.'); }
}} />
<Btn size="sm" kind="secondary" label="Cancel" onPress={() => setReporting(null)} />
</View>
</View>
) : null}
</View>
))}
{meetingTalk ? (
Expand Down
Loading
Loading