// Round nine: the hub's browse-by-name on the phone — Community → Buddies
// has "Look up a user": a name typed opens the peer sheet (browse their
// files, message, add buddy).
const fs = require('fs');
const root = 'F:/Coding/SoulStream/';
let p, s;
const load = (file) => { p = file; s = fs.readFileSync(root + p, 'utf8'); };
const save = () => fs.writeFileSync(root + p, s);
const once = (a) => {
const i = s.indexOf(a);
if (i < 0) throw new Error('missing in ' + p + ': ' + a.slice(0, 90));
if (s.indexOf(a, i + 1) >= 0) throw new Error('ambiguous in ' + p + ': ' + a.slice(0, 90));
return i;
};
const rep = (a, b) => { once(a); s = s.replace(a, () => b); };
const NL = String.fromCharCode(10);
const afterLine = (anchor, text) => { const i = once(anchor); const nl = s.indexOf(NL, i); s = s.slice(0, nl + 1) + text + s.slice(nl + 1); };
load('src/mobile/screens/Community.svelte');
rep(` {:else if tab === "buddies"}
{#if !buddies.length}
No buddies on this account yet.Hold a name in a room to add one.
{/if}`,
` {:else if tab === "buddies"}
{#if !buddies.length}
No buddies on this account yet.Hold a name in a room to add one, or look one up above.
{/if}`);
rep(` const buddies = $derived(slsk.buddies.map((u) => ({ u, st: slsk.buddyState[u] || {} })));`,
` const buddies = $derived(slsk.buddies.map((u) => ({ u, st: slsk.buddyState[u] || {} })));
/* the hub's browse-by-name: a typed name opens the peer sheet */
function lookUp() {
openHalf("prompt", { title: "Look up a user", placeholder: "Soulseek username", ok: "Open", onsubmit: (v) => { const u = v.trim(); if (u) openHalf("peer", { username: u }); } });
}`);
save();
load('tests/mobile/smoke.mjs');
rep(` { do: \`document.querySelector('.screen button.row').dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }))\`, name: "buddy-sheet", wait: 600 },
{ do: \`document.querySelector('.scrim').click()\`, wait: 500 },`,
` { do: \`document.querySelectorAll('.screen button.row')[1].dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }))\`, name: "buddy-sheet", wait: 600 },
{ do: \`document.querySelector('.scrim').click()\`, wait: 500 },
/* a user looked up by name: the peer sheet */
{ do: \`__click('.screen .row', 'Look up a user')\`, wait: 600 },
{ do: \`(function () { var i = document.querySelector('.halfsheet .prompt .field'); i.value = 'dusty_crates'; i.dispatchEvent(new Event('input', { bubbles: true })); })()\`, wait: 300 },
{ do: \`__click('.halfsheet .prompt-acts .btn-fill', 'Open')\`, name: "user-lookup", wait: 700 },
{ do: \`document.querySelector('.scrim').click()\`, wait: 500 },`);
rep(` "buddy-sheet": (i) => i.half.includes("up") && /Browse their files/.test(i.halfText) && /Remove buddy/.test(i.halfText),`,
` "buddy-sheet": (i) => i.half.includes("up") && /Browse their files/.test(i.halfText) && /Remove buddy/.test(i.halfText),
"user-lookup": (i) => i.half.includes("up") && /dusty_crates/.test(i.halfText) && /Browse their files/.test(i.halfText) && /Add buddy/.test(i.halfText),`);
save();
load('ANDROID.md');
rep(`— the same sheet is a buddy's on Community → Buddies (a long press):`,
`— the same sheet is a buddy's on Community → Buddies (a long press), and
"Look up a user" there opens it for any name typed (the hub's browse by
name):`);
save();
console.log('round nine wired');