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
3 changes: 3 additions & 0 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ export class AdminController {
@Post('sites/:site/moderation-recheck') async recheck(@Headers('authorization') a: string, @Param('site') s: string) {
return this.p.adminRecheckModeration(await this.admin(a), s);
}
@Post('sites/:site/niche-checks') async nicheChecks(@Headers('authorization') a: string, @Param('site') s: string) {
return this.p.adminRunNicheChecks(await this.admin(a), s);
}
@Get('sites/:site/members') async members(@Headers('authorization') a: string, @Param('site') s: string, @Query('search') q?: string, @Query('page') page?: string) {
return this.p.adminMembers(await this.admin(a), s, { search: q || undefined, page: Number(page) || 1 });
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/import/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function extractLegacy(site: LegacySite, connectionString: string,
const set = (k: string, v: string | string[] | number | undefined) => { if (v !== undefined) fields[k] = v; };
if (site === 'afterh') set('hsv_status', legacyStatus(a.get(Q.q20)));
if (site === 'hfriends') set('accessibility', legacyAccessibility(a.get(Q.q20), a.get(Q.q21)));
if (site === 'datealittle') set('stature', legacyStature(a.get(Q.q20)));
if (site === 'datealittle') { const st = legacyStature(a.get(Q.q20)); set('stature', st.stature); set('dwarfism_type', st.type); }
set('relationship_goal', legacyGoal(a.get(Q.lookingFor)));
set('height', legacyHeight(a.get(Q.height)));
set('kids', legacyKids(a.get(Q.haveKids), a.get(Q.wantKids)));
Expand Down
10 changes: 8 additions & 2 deletions apps/api/src/import/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import {
findContactInfo, type Gender, type MemberNetwork, riskFlags, riskKey, riskReasons, type GeoPlace, type GeoProvider, isGender, type Member, type ModerationItem, type Photo, type PhotoKind,
findContactInfo, flagMember, type Gender, memberFlags, type MemberNetwork, type NicheFlag, riskFlags, riskKey, riskReasons, type GeoPlace, type GeoProvider, isGender, type Member, type ModerationItem, type Photo, type PhotoKind,
type PhotoStore, type ProfileFieldDef, type Site, type SiteCrypto, type SiteRepo, PHOTO_LIMITS, unitsForCountry,
} from '@whatbox/core';
import { type Bundle, bump, photoPath, type SrcLocation, type SrcMember, type SrcPhoto } from './bundle';
Expand Down Expand Up @@ -121,6 +121,8 @@ export interface LoadReport {
photos: Record<string, number>;
relations: Record<string, number>;
moderation: number;
/** Niche review flags by reason (DateALittle, HFriends). */
niche: Record<string, number>;
}

const short = (s: string) => createHash('sha256').update(s).digest('hex').slice(0, 24);
Expand All @@ -133,10 +135,11 @@ export async function loadBundles(bundles: Bundle[], d: LoadDeps): Promise<LoadR
const year = d.now.getUTCFullYear();
const report: LoadReport = {
site: d.site.slug, dryRun: d.dryRun, bundles: bundles.map((b) => ({ source: b.info.source, members: b.members.length })),
members: {}, photos: {}, relations: {}, moderation: 0,
members: {}, photos: {}, relations: {}, moderation: 0, niche: {},
};
const idByKey = new Map<string, string>();
const moderation: ModerationItem[] = [];
const niche: { memberId: string; f: NicheFlag }[] = [];
const flagItem = (memberId: string, refId: string, kind: ModerationItem['kind'], summary: string, reason: string, createdAt = at) =>
moderation.push({ id: 'mod_imp_' + short(`${kind}:${refId}:${reason}`), kind, refId, memberId, summary, reasons: [reason], status: 'pending', createdAt });

Expand Down Expand Up @@ -203,6 +206,8 @@ export async function loadBundles(bundles: Bundle[], d: LoadDeps): Promise<LoadR
if (src.flags.includes('spam_suspected')) flagItem(id, id, 'profile', 'Imported member: flagged as possible spam on the old site', 'spam suspected on the old site');
if (src.flags.includes('suspended')) flagItem(id, id, 'profile', 'Imported member: was suspended on the old site', 'suspended on the old site');
if (member.about && findContactInfo(member.about).length) flagItem(id, id, 'profile', member.about.slice(0, 280), 'contact info in profile');
// Niche sites: answers that don't add up (e.g. "no dwarfism" at 3'4"), fetish or "third" wording. Review only.
for (const f of memberFlags(d.site, member)) { niche.push({ memberId: id, f }); bump(report.niche, f.reason); }

// Photos
const withHash: { bundle: Bundle; photo: SrcPhoto; hash: string; data: Buffer }[] = [];
Expand Down Expand Up @@ -265,6 +270,7 @@ export async function loadBundles(bundles: Bundle[], d: LoadDeps): Promise<LoadR
const prior = await d.repo.getModeration(item.id);
if (!prior) await d.repo.saveModeration(item); // a moderator's earlier decision stays
}
if (!d.dryRun) for (const n of niche) await flagMember(d.repo, n.memberId, n.f, at);
return report;
}

Expand Down
58 changes: 47 additions & 11 deletions apps/api/src/import/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,62 @@ export const isoDate = (d: Date | string | number | null | undefined): string |

// ---------- Site-specific question 20 (and 21) on the old sites ----------

/** HFriends "Type of Disability" (q20) and "Type of Disorder" (q21) to "About my disability". */
/** HFriends "Type of Disability" (q20) and "Type of Disorder" (q21) to the broad "About my disability" categories.
* "No Disability" (q20) becomes "No disability"; picking it with other disabilities is kept as-is
* so the review check can flag it (the old form let people tick every box). */
export function legacyAccessibility(disability: string | undefined, disorder: string | undefined): string[] | undefined {
const out: string[] = [];
for (const raw of [...(disability ?? '').split(':'), ...(disorder ?? '').split(':')]) {
let none = false;
const parts = [...(disability ?? '').split(':').map((x) => ['q20', x] as const), ...(disorder ?? '').split(':').map((x) => ['q21', x] as const)];
for (const [q, raw] of parts) {
const s = raw.trim().toLowerCase();
if (!s || s === 'none' || s === 'no disability') continue;
if (/paraplegic|quadriplegic|spinal|spina bifida/.test(s)) out.push('Wheelchair user');
else if (/mobility|physically|amputee|hemiplegic|polio|muscular dystrophy|arthrogryposis|brittle bone|osteogenesis|cerebral palsy|charcot/.test(s)) out.push('Uses a mobility aid');
if (!s) continue;
// "None" under Type of Disorder only means no disorder; "No Disability" is the real "none"
if (s === 'none' || s === 'no disability') { if (q === 'q20') none = true; continue; }
if (/paraplegic|quadriplegic|hemiplegic|spinal|spina bifida/.test(s)) out.push('Wheelchair user');
else if (/mobility|polio|muscular dystrophy|arthrogryposis|charcot|cerebral palsy/.test(s)) out.push('Uses a mobility aid');
else if (/amputee/.test(s)) out.push('Limb difference or amputee');
else if (/physically|brittle bone|osteogenesis/.test(s)) out.push('Other physical disability');
else if (/hearing/.test(s)) out.push('Deaf or hard of hearing');
else if (/vision/.test(s)) out.push('Blind or low vision');
else if (/learning|asperger/.test(s)) out.push('Neurodivergent');
else if (/speech|other/.test(s)) continue; // no matching option; the member can add it after signing in
else if (/speech/.test(s)) out.push('Speech or communication');
else if (/learning/.test(s)) out.push('Learning or intellectual disability');
else if (/asperger/.test(s)) out.push('Neurodivergent');
else if (/bi ?polar|depression|anxiety|schizophrenia|personality/.test(s)) out.push('Mental health');
else if (/^other$/.test(s)) out.push('Other');
else out.push('Chronic illness');
}
if (none) out.push('No disability');
return out.length ? uniq(out) : undefined;
}

/** DateALittle "Dwarfism Type" (q20) to "Stature". The exact type isn't carried over (no matching field yet). */
export function legacyStature(answer: string | undefined): string | undefined {
/** DateALittle "Dwarfism Type" (q20, one answer) to "Stature" and "Type of dwarfism". */
export function legacyStature(answer: string | undefined): { stature?: string; type?: string } {
const s = (answer ?? '').trim();
if (!s) return undefined;
return /^none$/i.test(s) ? 'Average height' : 'Little person';
if (!s) return {};
if (/^none$/i.test(s)) return { stature: 'Average height' };
if (/^short stature$/i.test(s)) return { stature: 'Short stature', type: 'Not sure / no diagnosis' };
return { stature: 'Little person', type: legacyDwarfismType(s) };
}

/** Old DateALittle type names to the new list (rare or lethal types become "Another type"). */
export function legacyDwarfismType(s: string): string {
const t = s.toLowerCase();
const rules: [RegExp, string][] = [
[/^hypochondroplasia/, 'Hypochondroplasia'], [/^pseudoachondroplasia/, 'Pseudoachondroplasia'],
[/^achondroplasia|saddan/, 'Achondroplasia'], [/diastrophic/, 'Diastrophic dysplasia'],
[/corner fracture|\(smd|kozlowski/, 'Spondylometaphyseal dysplasia (SMD)'],
[/strudwick|spondyloepimetaphyseal dysplasias$/, 'Spondyloepimetaphyseal dysplasia (SEMD)'],
[/\(sed|sedc|sedt|spondyloepimetaphyseal/, 'Spondyloepiphyseal dysplasia (SED)'],
[/multiple epiphyseal/, 'Multiple epiphyseal dysplasia (MED)'], [/^metaphyseal/, 'Metaphyseal chondrodysplasia'],
[/acromesomelic/, 'Acromesomelic dysplasia'], [/^mesomelic/, 'Mesomelic dysplasia'], [/campomelic/, 'Campomelic dysplasia'],
[/chondrodysplasia punctata|conradi/, 'Chondrodysplasia punctata'], [/cleidocranial/, 'Cleidocranial dysplasia'],
[/ellis van creveld/, 'Ellis-van Creveld syndrome'], [/kniest/, 'Kniest dysplasia'], [/larsen/, 'Larsen syndrome'],
[/weill/, 'Leri-Weill dyschondrosteosis'], [/metatropic/, 'Metatropic dysplasia'], [/osteogenesis imperfecta/, 'Osteogenesis imperfecta (OI)'],
[/morquio/, 'Morquio syndrome (MPS IV)'], [/mps|mucopolysacchar|hurler|hunter/, 'Other mucopolysaccharidosis (MPS)'],
[/primordial|seckel/, 'Primordial dwarfism (MOPD, Seckel)'], [/russell-silver/, 'Russell-Silver syndrome'], [/turner/, 'Turner syndrome'],
[/growth hormone/, 'Growth hormone deficiency'], [/laron/, 'Laron syndrome'],
[/pituitary|hypopituitary|hypothyroid|precocious/, 'Pituitary or hormonal'], [/hypophosphat|rickets/, 'Hypophosphatemia or rickets'],
];
return rules.find(([re]) => re.test(t))?.[1] ?? 'Another type';
}
12 changes: 9 additions & 3 deletions apps/api/test/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ test('profile answers', () => {
assert.equal(legacyKids('Yes - but not at home', 'Yes'), 'Have kids, want more');
assert.deepEqual(skadateInterests(1 | 2048 | 1048576), ['Reading', 'Travel']);
assert.deepEqual(legacyAccessibility('Paraplegic:Hearing Impaired', 'Multiple Sclerosis'), ['Wheelchair user', 'Deaf or hard of hearing', 'Chronic illness']);
assert.equal(legacyAccessibility('No Disability', 'None'), undefined);
assert.equal(legacyStature('Achondroplasia'), 'Little person');
assert.equal(legacyStature('None'), 'Average height');
assert.deepEqual(legacyAccessibility('No Disability', 'None'), ['No disability']);
assert.deepEqual(legacyAccessibility('Hearing Impaired', 'None'), ['Deaf or hard of hearing']);
assert.deepEqual(legacyAccessibility('Amputee:Speech Impaired:No Disability', 'Depression / Anxiety'), ['Limb difference or amputee', 'Speech or communication', 'Mental health', 'No disability']);
assert.deepEqual(legacyStature('Achondroplasia'), { stature: 'Little person', type: 'Achondroplasia' });
assert.deepEqual(legacyStature('Short Stature'), { stature: 'Short stature', type: 'Not sure / no diagnosis' });
assert.deepEqual(legacyStature('None'), { stature: 'Average height' });
assert.equal(legacyStature('Spondyloepimetaphyseal Dysplasia Congenita (SEDC)').type, 'Spondyloepiphyseal dysplasia (SED)');
assert.equal(legacyStature('Hurler-Scheie Syndrome (MPS I)').type, 'Other mucopolysaccharidosis (MPS)');
assert.equal(legacyStature('Thanatophoric Dysplasia').type, 'Another type');
assert.deepEqual(skadateGenders(1 | 4), ['man', 'couple']);
assert.deepEqual(seekingFor('man', ['couple']), ['woman']);
assert.equal(countryCode('United States'), 'US');
Expand Down
12 changes: 10 additions & 2 deletions apps/member/src/app/(app)/browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const SORTS: { label: string; value: NonNullable<SearchFilters['sort']> }[] = [
];

export default function Browse() {
const { api, me, site } = useSession();
const { api, me, site, refreshMe } = useSession();
const t = useTheme();
const wide = useWide(980);
const { height } = useWindowDimensions();
const units = me!.member.unitsResolved;
const defaults = useCallback((): SearchFilters => ({
seeking: me!.member.seeking, ageMin: me!.member.ageMin, ageMax: me!.member.ageMax, withinMiles: me!.member.maxMiles === undefined ? 50 : me!.member.maxMiles, withPhoto: true, onlineNow: false, sort: 'recent', page: 1, pageSize: 12, fields: {},
seeking: me!.member.seeking, ageMin: me!.member.ageMin, ageMax: me!.member.ageMax, withinMiles: me!.member.maxMiles === undefined ? 50 : me!.member.maxMiles, withPhoto: true, onlineNow: false, everyone: !!me!.member.showEveryone, sort: 'recent', page: 1, pageSize: 12, fields: {},
}), [me]);
const [filters, setFilters] = useState<SearchFilters>(defaults);
const [draft, setDraft] = useState(filters);
Expand All @@ -42,6 +42,8 @@ export default function Browse() {
useEffect(() => { load(filters); }, [filters, load]);

const apply = () => {
// Remember "include everyone" so Discover and the next visit follow it too.
if (site.nicheIncludeLabel && !!draft.everyone !== !!me!.member.showEveryone) api.updateMe({ showEveryone: !!draft.everyone }).then(() => refreshMe()).catch(() => {});
const clamp = (v: string, fallback: number) => Math.min(99, Math.max(18, Number(v) || fallback));
let lo = clamp(ageFrom, 18), hi = clamp(ageTo, 99);
if (lo > hi) [lo, hi] = [hi, lo];
Expand Down Expand Up @@ -84,6 +86,12 @@ export default function Browse() {
<Check label="With a photo" value={!!draft.withPhoto} onChange={(v) => setDraft({ ...draft, withPhoto: v })} />
<Check label="Online now" value={!!draft.onlineNow} onChange={(v) => setDraft({ ...draft, onlineNow: v })} />
</View>
{site.nicheIncludeLabel ? (
<View style={{ gap: 4 }}>
<Check label={site.nicheIncludeLabel} value={!!draft.everyone} onChange={(v) => setDraft({ ...draft, everyone: v })} />
<Txt sub size={12}>By default, {site.name} shows members who share the site's focus. Tick this to see everyone.</Txt>
</View>
) : null}
{filterable.length ? (
<Pressable accessibilityRole="button" accessibilityState={{ expanded: showMore }} onPress={() => setShowMore(!showMore)}
style={{ flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingVertical: 6, borderTopWidth: 1, borderColor: t.line, paddingTop: 14 }}>
Expand Down
Loading
Loading