Skip to content

Hide senders when the world asks ​

Some worlds keep their members anonymous, for example a peer review, a blind tasting or a vote. A world of this kind has showsSenders: false and your view then renders no names or pictures next to the messages. The text of the messages stays and the messages of the person still look different from all the others. Send your essay twice in the example and two reviews come back without the names of their authors.

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;
	}));
});
Live, on a fake world
Open

How it works ​

  • showsSenders is false when the world asks to hide who wrote each message. An older webapp does not provide the field. Reading it as world.showsSenders !== false shows the names when it is missing.
  • The request covers the names, avatars and roles shown next to the messages. The messages of the person can still look different and in the example they are aligned to the right.
  • The request comes from the owner of the world. The same owner entered the address of your view in the Own view field of the world. The messages still carry from and fromId and your view follows the request by leaving them out of what it renders. A list of the members can still appear elsewhere in your view.
  • A fake world makes the request with showsSenders: false. In each of its answers from names the member who replies.

See also ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.