Status and presence
Every member has a presence: a status (online, idle, do not disturb, or offline) and optionally an activity, what they are doing (“Playing chess”, “Listening to lofi radio”). A member can also set a custom status text with an emoji, which the host keeps until it is changed or expires. Bots have the same presence as members (bots: status and presence).
Setting your status and activity
Section titled “Setting your status and activity”Presence is set once for the whole client and goes to every community it is connected to.
client.setPresence("online", { type: "listening", name: "lofi radio", state: "ChilledCow" });client.setPresence("dnd"); // no activityclient.setPresence("invisible"); // everyone else sees you offlinesetPresence returns false, and sends nothing, when the status or the activity is not valid.
use zaun_client::presence::{activity, ActivityType, Status};
let mut listening = activity(ActivityType::Listening, "lofi radio");listening.state = Some("ChilledCow".into());client.set_presence(Status::Online, Some(listening))?;client.set_presence(Status::Dnd, None)?; // no activityclient.set_presence(Status::Invisible, None)?; // everyone else sees you offline| Status | Everyone else sees |
|---|---|
online |
online |
idle |
idle (away) |
dnd |
do not disturb |
invisible |
offline, with no activity |
An activity has a type (kind in Rust): playing, streaming, listening, watching,
competing or custom; a name; and optionally details and state (a second and third line),
started_at (ms since the epoch, to show an elapsed time), url (an https:// link, streaming
only) and emoji (custom only).
The host shows at most one change per member every 3 seconds. Call it as often as you like: the client keeps the latest, sends it when the window allows, and sends it again after each reconnection.
Custom status text
Section titled “Custom status text”The custom status is set per community, and the host keeps it (presence is live only).
await community.setStatusText("Back soon", { emoji: "☕", expiresAt: new Date(Date.now() + 3_600_000) });await community.setStatusText("Reviewing PRs"); // kept until changedawait community.setStatusText(null); // clears itcommunity.set_status_text(Some("Back soon"), Some("☕"), Some(expires_at_ms))?;community.set_status_text(Some("Reviewing PRs"), None, None)?; // kept until changedcommunity.set_status_text(None, None, None)?; // clears itWhen it is set, changed, cleared or expires, everyone else gets a member update
(memberUpdate / Event::MemberUpdate).
Showing presence
Section titled “Showing presence”const verbs = { playing: "Playing", streaming: "Streaming", listening: "Listening to", watching: "Watching", competing: "Competing in" };const line = (a) => a.type === "custom" ? `${a.emoji ?? ""} ${a.name}`.trim() : `${verbs[a.type]} ${a.name}`;
client.on("presenceUpdate", ({ member, status, activity }) => { showPresence(member, status, activity ? line(activity) : null);});
member.presence; // { status: "online" | "idle" | "dnd" | "offline", activity }member.statusText; // custom status text, or nullmember.statusEmoji; // its emoji, or nullcommunity.presences; // every member who is not offline: [{ member, status, activity }]use zaun_client::Event;use zaun_client::presence::Status;
if let Event::PresenceUpdate { community, presence } = event { let member = community.member(presence.member); let away = presence.status == Status::Idle; let line = presence.activity_line(); // "Listening to lofi radio", or the custom text}
let p = member.presence(); // offline when unknownlet text = member.status_text(); // Option<String>let emoji = member.status_emoji(); // Option<String>let online = community.presences(); // every member who is not offlineAfter a community is ready, the client loads who is online and emits presencesReady
(Event::PresencesReady); from then on each change arrives as presenceUpdate
(Event::PresenceUpdate). Invisible members look offline, and a member who goes offline leaves
community.presences.
A streaming activity’s link should open only after the reader confirms. Activities carry no pictures and no other links, so showing one never makes your app fetch anything.
Limits
Section titled “Limits”| Item | Limit |
|---|---|
| Activity name | 1–128 characters |
| Activity details, state | 0–128 characters each |
| Custom status text | 1–128 characters, plus an optional emoji |
| Emoji | one Unicode emoji, ≤ 64 bytes |
| Presence changes shown | one every 3 s per member; the latest wins |