Nascondi i mittenti quando il mondo lo chiede
Alcuni mondi tengono anonimi i loro membri, per esempio in una peer review, in una degustazione alla cieca o in un voto. Un mondo di questo tipo ha showsSenders: false e la tua vista allora non mostra nomi né immagini accanto ai messaggi. Il testo dei messaggi resta e i messaggi della persona si distinguono comunque da tutti gli altri. Se nell'esempio invii due volte il tuo saggio, tornano due revisioni senza i nomi dei loro autori.
jsx
import { useWorld } from './useWorld.js';
// In this fake world, two reviewers answer in turn, and the world asks
// not to show who wrote each message (`showsSenders: false`).
let turn = 0;
const review = {
name: 'Peer review',
members: [
{ name: 'Ada', role: 'reviewer' },
{ name: 'Bob', role: 'reviewer' },
],
showsSenders: false,
onMessage: () => {
turn += 1;
if (turn % 2 === 1) return { from: 'Ada', text: 'Clear and short: I liked it.' };
return { from: 'Bob', text: 'Add an example to the second part.' };
},
};
export default function App() {
// While building: the fake world. In the webapp: useWorld()
const { world, error } = useWorld({ fake: { world: review } });
if (error) return <p>Could not connect ({error.code}).</p>;
if (!world) return <p>Connecting…</p>;
// False when the world asks not to show who wrote each message.
// With an older webapp it is missing, and the view shows the names.
const showsSenders = world.showsSenders !== false;
return (
<>
{world.messages.map((message) => (
// The person's own messages sit on the right and stand apart even with no names.
<p key={message.id} style={{ textAlign: message.fromMe ? 'right' : 'left' }}>
{showsSenders && !message.fromMe ? `${message.from}: ${message.text ?? ''}` : message.text}
</p>
))}
<button onClick={() => world.send('Here is my essay.')} disabled={!world.canSend}>Send my essay</button>
</>
);
}js
import { connectToHost } from '@unaiverse/gui-kit';
// In this fake world, two reviewers answer in turn, and the world asks
// not to show who wrote each message (`showsSenders: false`).
let turn = 0;
const review = {
name: 'Peer review',
members: [
{ name: 'Ada', role: 'reviewer' },
{ name: 'Bob', role: 'reviewer' },
],
showsSenders: false,
onMessage: () => {
turn += 1;
if (turn % 2 === 1) return { from: 'Ada', text: 'Clear and short: I liked it.' };
return { from: 'Bob', text: 'Add an example to the second part.' };
},
};
// While building: the fake world. In the webapp: const world = await connectToHost();
const world = await connectToHost({ fake: { world: review } });
const list = document.createElement('div');
const sendButton = document.createElement('button');
sendButton.textContent = 'Send my essay';
sendButton.onclick = () => world.send('Here is my essay.');
document.body.append(list, sendButton);
world.subscribe((node) => {
sendButton.disabled = !node.canSend;
// False when the world asks not to show who wrote each message.
// With an older webapp it is missing, and the view shows the names.
const showsSenders = node.showsSenders !== false;
list.replaceChildren(...node.messages.map((message) => {
const line = document.createElement('p');
// The person's own messages sit on the right and stand apart even with no names.
line.style.textAlign = message.fromMe ? 'right' : 'left';
const words = message.text ?? '';
line.textContent = showsSenders && !message.fromMe ? `${message.from}: ${words}` : words;
return line;
}));
});Come funziona
showsSendersèfalsequando il mondo chiede di nascondere chi ha scritto ogni messaggio. Una webapp più vecchia non fornisce il campo e leggerlo comeworld.showsSenders !== falsemostra i nomi quando manca.- La richiesta riguarda i nomi, gli avatar e i ruoli mostrati accanto ai messaggi. I messaggi della persona possono comunque distinguersi e nell'esempio sono allineati a destra.
- La richiesta viene dal proprietario del mondo. È lo stesso proprietario che ha scritto l'indirizzo della tua vista nel campo Vista propria del mondo. I messaggi portano ancora
fromefromIde la tua vista segue la richiesta lasciandoli fuori da quello che mostra. Una lista dei membri può comunque comparire altrove nella tua vista. - Un mondo finto fa la richiesta con
showsSenders: false. In ogni sua rispostafromindica il membro che risponde.
Vedi anche
- Mostra chi ha scritto ogni messaggio
- MemberName: l'autore di un messaggio oppure niente quando il mondo chiede di nasconderlo.
- Il mondo