The home page drew its banner, the sidebar's picture and the cards from rectangles and dots, far from the night landscapes of the design. They are SVG pictures now (assets/art: a banner with a moon and a cabin, a mountain range for the sidebar, three scenes for the server and stream cards), drawn at their own aspect ratio: with `image-fit: cover` the software renderer draws an SVG at another size and stretches it, which looks jagged. The banner's arrows sit by its dots as in the design, and the phone swipes between its slides. On the phone the recent chats are rows with the time, unread count and a chevron, and the servers a row to swipe through. Voice & Video's two columns are of the same width (a long device name widened the left one) and the bitrate slider takes the free space. An event's title, times and answers wrap instead of being cut on the phone, where the page and the Library no longer repeat the top bar's title. The sample data has three live streams, so the home's live row and friend activity look as they would on a busy server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1345 lines
40 KiB
Rust
1345 lines
40 KiB
Rust
//! Development switches (environment variables), for trying screens and
|
|
//! taking screenshots without a server:
|
|
//!
|
|
//! - `VOELIN_DATA_DIR=<dir>`: the database (app.rs).
|
|
//! - `VOELIN_AUTOCONNECT=voice|observe`: connect the first bookmark on start.
|
|
//! - `VOELIN_SCREENSHOT=<png>`: save the window after
|
|
//! `VOELIN_SCREENSHOT_DELAY` seconds (default 4) and exit.
|
|
//! - `VOELIN_WINDOW_SIZE=<w>x<h>`: the window's size (e.g. `390x844` for the
|
|
//! phone layout).
|
|
//! - `VOELIN_DEMO_UI=1`: sample servers, channels, chat and streams, no
|
|
//! server needed (nothing is stored).
|
|
//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer.
|
|
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
|
|
//! `server`, `settings[:<section>]` (voice, keybinds, streaming, privacy,
|
|
//! appearance, or 0-4), `about`, `share`, `bookmark` (add a server),
|
|
//! `emoji` (the picker), `client` (the volume dialog of the first other
|
|
//! client once connected), `panel` / `no-panel` (the members panel),
|
|
//! `voice` (the voice channel view), `pins`, `topics` (the drawers),
|
|
//! `topic:<id>` (a topic's messages), `member` (the member card of the
|
|
//! first other client), `watch` (the first stream; with sample data the
|
|
//! local test pattern in its place), `popout` (the same, popped out),
|
|
//! `tab:<home|servers|chat|activity|you>` (phone layout); `friends[:<uid>]`,
|
|
//! `messages[:<uid>]` (a private chat), `inbox` (offline messages),
|
|
//! `library`, `events`, `event-form`, `search[:<text>]`,
|
|
//! `notifications` (the bell), `join` (join by address), `offline` (an
|
|
//! offline message), `picture` (a chat picture opened large), `camera`
|
|
//! (the settings' camera preview); settings sections also `account`,
|
|
//! `profiles`, `devices`, `notifications`, `integrations`, `advanced`;
|
|
//! `studio[:<what>]`: the Stream Studio (with `VOELIN_DEMO_UI` a demo
|
|
//! studio from synthetic sources), `studio:window` in a window of its own,
|
|
//! `studio:live` going live, `studio:record`, or a dialog: `studio:source`,
|
|
//! `studio:audio`, `studio:camera`, `studio:scene`, `studio:settings`.
|
|
//! A screenshot also saves the studio's window (`<name>-window.png`) and
|
|
//! draws it over the main window.
|
|
//! - `VOELIN_AUTOWATCH=1`: watch the first stream that shows up.
|
|
//! - `VOELIN_AUTOSHARE=test-pattern`: share the test pattern (accepting
|
|
//! everyone) once connected to a TeamSpeak 6 server.
|
|
|
|
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
use anyhow::Result;
|
|
use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer};
|
|
use voelin_core::gateway::Pin;
|
|
use voelin_core::stream::{StreamInfo, StreamKind};
|
|
use voelin_core::{
|
|
Contact, Event, GatewayUpdate, HistoryMessage, HistorySource, ObserveState, Relation,
|
|
SessionState, Source, VoiceState,
|
|
};
|
|
use voelin_gateway_proto::{
|
|
Action, Attendee, ConfigEntry, ConfigSource, EventInfo, EventKind, EventSpec, PermRule,
|
|
PermRuleInfo, ReactionCount, RsvpStatus, StreamEntry, StreamSource, TopicInfo, UserRef,
|
|
feature,
|
|
};
|
|
use voelin_model::{
|
|
ChannelInfo, ChatMessage, ChatTarget, ClientInfo, GroupInfo, Presence, ServerFlavor,
|
|
};
|
|
use voelin_store::{Bookmark, MessageSource};
|
|
|
|
use crate::app::{
|
|
App, Bridge, MainWindow, MobileTab, Nav, Page, RecordingItem, SettingsSection, with_app,
|
|
};
|
|
|
|
/// The switches read at start.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub(crate) struct Switches {
|
|
pub demo_stream: bool,
|
|
pub demo_ui: bool,
|
|
pub autoshare: bool,
|
|
pub open_client: bool,
|
|
open: Vec<String>,
|
|
autoconnect: Option<String>,
|
|
screenshot: Option<std::path::PathBuf>,
|
|
screenshot_delay: u64,
|
|
window_size: Option<(f32, f32)>,
|
|
}
|
|
|
|
fn flag(name: &str) -> bool {
|
|
std::env::var(name).is_ok_and(|v| v == "1")
|
|
}
|
|
|
|
/// `390x844` → (390, 844).
|
|
fn parse_size(text: &str) -> Option<(f32, f32)> {
|
|
let (w, h) = text.split_once(['x', 'X'])?;
|
|
Some((w.trim().parse().ok()?, h.trim().parse().ok()?))
|
|
}
|
|
|
|
impl Switches {
|
|
pub fn from_env() -> Self {
|
|
let open: Vec<String> = std::env::var("VOELIN_OPEN")
|
|
.unwrap_or_default()
|
|
.split(',')
|
|
.map(|s| s.trim().to_owned())
|
|
.filter(|s| !s.is_empty())
|
|
.collect();
|
|
Self {
|
|
demo_stream: flag("VOELIN_DEMO_STREAM"),
|
|
demo_ui: flag("VOELIN_DEMO_UI"),
|
|
autoshare: std::env::var("VOELIN_AUTOSHARE").is_ok_and(|v| v == "test-pattern"),
|
|
open_client: open.iter().any(|o| o == "client"),
|
|
open,
|
|
autoconnect: std::env::var("VOELIN_AUTOCONNECT").ok(),
|
|
screenshot: std::env::var_os("VOELIN_SCREENSHOT").map(Into::into),
|
|
screenshot_delay: std::env::var("VOELIN_SCREENSHOT_DELAY")
|
|
.ok()
|
|
.and_then(|d| d.parse().ok())
|
|
.unwrap_or(4),
|
|
window_size: std::env::var("VOELIN_WINDOW_SIZE").ok().as_deref().and_then(parse_size),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn section(name: &str) -> SettingsSection {
|
|
match name {
|
|
"1" | "keybinds" | "ptt" => SettingsSection::Keybinds,
|
|
"2" | "streaming" => SettingsSection::Streaming,
|
|
"3" | "privacy" => SettingsSection::Privacy,
|
|
"4" | "appearance" => SettingsSection::Appearance,
|
|
"5" | "account" => SettingsSection::Account,
|
|
"6" | "profiles" => SettingsSection::Profiles,
|
|
"7" | "devices" => SettingsSection::Devices,
|
|
"8" | "notifications" => SettingsSection::Notifications,
|
|
"9" | "integrations" => SettingsSection::Integrations,
|
|
"10" | "advanced" => SettingsSection::Advanced,
|
|
_ => SettingsSection::Voice,
|
|
}
|
|
}
|
|
|
|
fn mobile_tab(name: &str) -> MobileTab {
|
|
match name {
|
|
"home" => MobileTab::Home,
|
|
"servers" => MobileTab::Servers,
|
|
"activity" => MobileTab::Activity,
|
|
"you" => MobileTab::You,
|
|
_ => MobileTab::Chat,
|
|
}
|
|
}
|
|
|
|
/// Timers that must live while the window runs.
|
|
pub(crate) struct Running {
|
|
_screenshot: Option<slint::Timer>,
|
|
_resize: Option<slint::Timer>,
|
|
}
|
|
|
|
/// Apply the switches once the app is set up.
|
|
pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
|
if let Some((w, h)) = switches.window_size {
|
|
ui.window().set_size(slint::LogicalSize::new(w, h));
|
|
}
|
|
if switches.demo_ui {
|
|
with_app(demo_ui);
|
|
}
|
|
match switches.autoconnect.as_deref() {
|
|
Some("voice") => {
|
|
with_app(|app| app.connect_voice());
|
|
}
|
|
Some("observe") => {
|
|
with_app(|app| app.toggle_observe());
|
|
}
|
|
_ => {}
|
|
}
|
|
let nav = ui.global::<Nav>();
|
|
for open in &switches.open {
|
|
let (what, arg) = open.split_once(':').unwrap_or((open.as_str(), ""));
|
|
match what {
|
|
"home" => nav.invoke_show(Page::Home),
|
|
"server" => nav.invoke_show(Page::Server),
|
|
"settings" => nav.invoke_open_settings(section(arg)),
|
|
"about" => nav.invoke_open_about(),
|
|
"share" => nav.invoke_open_share(),
|
|
"bookmark" => nav.invoke_add_server(),
|
|
"emoji" => nav.set_emoji_open(true),
|
|
"panel" => nav.set_right_panel_open(true),
|
|
"no-panel" => nav.set_right_panel_open(false),
|
|
"tab" => nav.set_mobile_tab(mobile_tab(arg)),
|
|
"voice" => nav.invoke_show_voice(true),
|
|
"pins" => nav.invoke_show_pins(true),
|
|
"topics" => nav.invoke_show_topics(true),
|
|
"topic" => {
|
|
with_app(|app| {
|
|
app.open_topic(arg.parse().unwrap_or(1));
|
|
// No gateway answers in demo mode.
|
|
if switches.demo_ui {
|
|
demo_topic(app);
|
|
}
|
|
});
|
|
}
|
|
"member" => {
|
|
with_app(|app| app.open_first_member());
|
|
}
|
|
"watch" | "popout" => {
|
|
with_app(|app| {
|
|
if switches.demo_ui { app.demo_watch() } else { app.watch_first_stream() }
|
|
});
|
|
ui.global::<Bridge>().set_viewer_popped(what == "popout");
|
|
}
|
|
// Home, friends, messages, events, the bell, the search.
|
|
"friends" => {
|
|
with_app(|app| app.select_contact(arg.to_owned()));
|
|
nav.invoke_show(Page::Friends);
|
|
}
|
|
"messages" | "dm" => {
|
|
let uid = if arg.is_empty() { "demo-3" } else { arg };
|
|
with_app(|app| app.open_dm_with(Some(DEMO), uid));
|
|
nav.invoke_show(Page::Messages);
|
|
}
|
|
"inbox" => {
|
|
nav.set_dm_tab(2);
|
|
with_app(|app| app.dm_tab(2));
|
|
nav.invoke_show(Page::Messages);
|
|
}
|
|
"library" => nav.invoke_show(Page::Library),
|
|
"events" => nav.invoke_show(Page::Events),
|
|
"event-form" => nav.invoke_create_event(),
|
|
"search" => nav.invoke_open_search(arg.into()),
|
|
"notifications" => nav.set_notifications_open(true),
|
|
"join" => nav.invoke_join_server(),
|
|
"offline" => nav.invoke_write_offline("demo-ari".into(), "Ari".into()),
|
|
"picture" => {
|
|
let picture = demo_picture(1280, 720, 16);
|
|
let image = crate::images::picture("demo:lightbox", &picture);
|
|
nav.set_lightbox(image);
|
|
nav.set_lightbox_open(true);
|
|
}
|
|
// The camera preview of the settings (the test pattern).
|
|
"camera" => {
|
|
with_app(|app| {
|
|
app.start_camera();
|
|
app.refresh_pages();
|
|
});
|
|
}
|
|
"studio" => {
|
|
if arg != "window" {
|
|
nav.invoke_open_studio();
|
|
}
|
|
with_app(|app| app.studio_dev(arg));
|
|
}
|
|
// Opened once connected (settings_page.rs).
|
|
"client" => {}
|
|
other => eprintln!("VOELIN_OPEN: unknown screen {other:?}"),
|
|
}
|
|
}
|
|
// A window manager can refuse the size set before the window opened,
|
|
// so ask again once it is up. (Under `xvfb-run` in a Wayland session,
|
|
// remove WAYLAND_DISPLAY, or winit opens the window on the desktop.)
|
|
let resize = switches.window_size.map(|(w, h)| {
|
|
let weak = ui.as_weak();
|
|
let timer = slint::Timer::default();
|
|
timer.start(
|
|
slint::TimerMode::SingleShot,
|
|
Duration::from_millis(switches.screenshot_delay * 1000 / 2),
|
|
move || {
|
|
if let Some(ui) = weak.upgrade() {
|
|
ui.window().set_size(slint::LogicalSize::new(w, h));
|
|
}
|
|
},
|
|
);
|
|
timer
|
|
});
|
|
let screenshot = switches.screenshot.clone().map(|path| {
|
|
let weak = ui.as_weak();
|
|
let timer = slint::Timer::default();
|
|
timer.start(
|
|
slint::TimerMode::SingleShot,
|
|
Duration::from_secs(switches.screenshot_delay),
|
|
move || {
|
|
if let Some(ui) = weak.upgrade() {
|
|
if let Err(e) = save_screenshot(&ui, &path) {
|
|
eprintln!("screenshot failed: {e}");
|
|
}
|
|
let _ = ui.hide();
|
|
// Also when the studio's own window is open.
|
|
let _ = slint::quit_event_loop();
|
|
}
|
|
},
|
|
);
|
|
timer
|
|
});
|
|
Running { _screenshot: screenshot, _resize: resize }
|
|
}
|
|
|
|
fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> {
|
|
let mut image = ui.window().take_snapshot()?;
|
|
if let Some(studio) = with_app(|app| app.studio_snapshot()).flatten() {
|
|
let stem = path.file_stem().unwrap_or_default().to_string_lossy();
|
|
save_png(&studio, &path.with_file_name(format!("{stem}-window.png")))?;
|
|
paste(&mut image, &studio);
|
|
}
|
|
save_png(&image, path)
|
|
}
|
|
|
|
/// Draw `top` over the bottom right of `image` with a border, as a second
|
|
/// window sits on a desktop.
|
|
fn paste(image: &mut SharedPixelBuffer<Rgba8Pixel>, top: &SharedPixelBuffer<Rgba8Pixel>) {
|
|
let (w, h) = (image.width() as usize, image.height() as usize);
|
|
let (tw, th) = (top.width() as usize, top.height() as usize);
|
|
let (x0, y0) = (w.saturating_sub(tw + 24), h.saturating_sub(th + 24));
|
|
let border = Rgba8Pixel { r: 0x3f, g: 0x7b, b: 0xff, a: 0xff };
|
|
let pixels = image.make_mut_slice();
|
|
for y in y0.saturating_sub(1)..(y0 + th + 1).min(h) {
|
|
for x in x0.saturating_sub(1)..(x0 + tw + 1).min(w) {
|
|
let (ty, tx) = (y.wrapping_sub(y0), x.wrapping_sub(x0));
|
|
pixels[y * w + x] =
|
|
if ty < th && tx < tw { top.as_slice()[ty * tw + tx] } else { border };
|
|
}
|
|
}
|
|
}
|
|
|
|
fn save_png(image: &SharedPixelBuffer<Rgba8Pixel>, path: &std::path::Path) -> Result<()> {
|
|
let file = std::io::BufWriter::new(std::fs::File::create(path)?);
|
|
let mut encoder = png::Encoder::new(file, image.width(), image.height());
|
|
encoder.set_color(png::ColorType::Rgba);
|
|
encoder.set_depth(png::BitDepth::Eight);
|
|
encoder.write_header()?.write_image_data(image.as_bytes())?;
|
|
Ok(())
|
|
}
|
|
|
|
const DEMO: i64 = 9001;
|
|
|
|
fn channel(id: u64, parent: u64, order: u64, name: &str) -> ChannelInfo {
|
|
ChannelInfo { id, parent, order, name: name.into(), ..Default::default() }
|
|
}
|
|
|
|
fn client(id: u16, channel: u64, name: &str) -> ClientInfo {
|
|
ClientInfo {
|
|
id,
|
|
channel,
|
|
nickname: name.into(),
|
|
uid: Some(format!("demo-{id}")),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
/// Sample data through the same events a server would send.
|
|
fn demo_ui(app: &mut App) {
|
|
let bookmark = |id: i64, name: &str, address: &str| Bookmark {
|
|
id,
|
|
name: name.into(),
|
|
address: address.into(),
|
|
nickname: "Nova".into(),
|
|
identity: None,
|
|
default_channel: None,
|
|
gateway_url: None,
|
|
query: None,
|
|
client_version: None,
|
|
};
|
|
app.bookmarks = vec![
|
|
Bookmark {
|
|
gateway_url: Some("wss://gw.nightfall.example/v1".into()),
|
|
..bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987")
|
|
},
|
|
bookmark(DEMO + 1, "Pixel Lounge", "pixel.example"),
|
|
bookmark(DEMO + 2, "Dev TS3", "127.0.0.1:9987"),
|
|
];
|
|
app.current = Some(DEMO);
|
|
let session = DEMO as u64;
|
|
|
|
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
|
p.server.welcome_message =
|
|
"Welcome to [b]Nightfall Guild[/b]! Raids on Tuesdays and Fridays, all levels welcome."
|
|
.into();
|
|
let mut chill = channel(2, 0, 1, "Chill Zone");
|
|
chill.max_clients = Some(50);
|
|
chill.topic = Some("Hang out, chat, and explore the worlds beyond.".into());
|
|
let mut locked = channel(7, 0, 6, "Officers");
|
|
locked.has_password = true;
|
|
for c in [
|
|
channel(1, 0, 0, "Lobby"),
|
|
chill,
|
|
channel(3, 0, 2, "Gaming"),
|
|
channel(4, 3, 0, "Raid Night"),
|
|
channel(5, 0, 3, "Music"),
|
|
channel(6, 0, 5, "AFK"),
|
|
locked,
|
|
] {
|
|
p.channels.insert(c.id, c);
|
|
}
|
|
let mut clients = vec![
|
|
client(1, 2, "Nova"),
|
|
client(2, 2, "Lumen"),
|
|
client(3, 2, "Kairo"),
|
|
client(4, 2, "Mira"),
|
|
client(5, 2, "dex"),
|
|
client(6, 3, "Talon"),
|
|
client(7, 4, "Zeph"),
|
|
client(8, 6, "Blaze"),
|
|
client(9, 1, "Rin"),
|
|
];
|
|
clients[1].streaming = Some(true);
|
|
// Live in other channels (the gateway's directory has their streams).
|
|
clients[5].streaming = Some(true);
|
|
clients[6].streaming = Some(true);
|
|
clients[4].input_muted = true;
|
|
clients[7].away = Some("brb".into());
|
|
clients[8].output_muted = true;
|
|
// Groups, badges and descriptions, as the members panel shows them.
|
|
clients[0].server_groups = vec![GROUP_MOD];
|
|
clients[0].talk_power = 75;
|
|
clients[0].description = Some("Raid lead. Ask me about the Tuesday runs.".into());
|
|
clients[1].server_groups = vec![GROUP_ADMIN];
|
|
clients[1].talk_power = 100;
|
|
clients[1].priority_speaker = true;
|
|
clients[1].description = Some("Streaming most evenings.".into());
|
|
clients[2].server_groups = vec![GROUP_MOD];
|
|
clients[2].channel_commander = true;
|
|
clients[2].talk_power = 75;
|
|
clients[3].server_groups = vec![GROUP_MEMBER];
|
|
clients[3].recording = true;
|
|
clients[4].server_groups = vec![GROUP_MEMBER];
|
|
clients[5].server_groups = vec![GROUP_MEMBER];
|
|
clients[6].server_groups = vec![GROUP_GUEST];
|
|
clients[7].server_groups = vec![GROUP_GUEST];
|
|
for c in clients {
|
|
p.clients.insert(c.id, c);
|
|
}
|
|
|
|
let group = |id: u64, sort_id: i32, name: &str| GroupInfo {
|
|
id,
|
|
name: name.into(),
|
|
icon: 0,
|
|
sort_id,
|
|
..Default::default()
|
|
};
|
|
let flavor = ServerFlavor::from_version_string("6.0.0-beta13.1 [Build: 1]");
|
|
let capabilities = flavor.capabilities();
|
|
let events = [
|
|
Event::ServerInfo { session, name: "Nightfall Guild".into(), flavor, capabilities },
|
|
Event::Groups {
|
|
session,
|
|
server_groups: Arc::new(vec![
|
|
group(GROUP_ADMIN, 10, "Server Admin"),
|
|
group(GROUP_MOD, 20, "Moderator"),
|
|
group(GROUP_MEMBER, 30, "Member"),
|
|
group(GROUP_GUEST, 40, "Guest"),
|
|
]),
|
|
channel_groups: Arc::new(Vec::new()),
|
|
},
|
|
Event::Presence { session, presence: Arc::new(p) },
|
|
Event::State {
|
|
session,
|
|
state: SessionState {
|
|
voice: VoiceState::Connected,
|
|
presence_source: Some(Source::Voice),
|
|
own_channel: Some(2),
|
|
own_client: Some(1),
|
|
// The engine keeps history for a server it knows, so the
|
|
// chat is driven by `Event::ChatHistory` like a real one.
|
|
server_uid: Some("demo-server".into()),
|
|
..Default::default()
|
|
},
|
|
},
|
|
// A gateway with everything the chat screens need.
|
|
Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Connected {
|
|
gateway_id: "demo".into(),
|
|
server_uid: "demo-server".into(),
|
|
server_name: "Nightfall Guild".into(),
|
|
uid: "demo-1".into(),
|
|
capabilities: vec![
|
|
feature::HISTORY.into(),
|
|
feature::PINS.into(),
|
|
feature::REACTIONS.into(),
|
|
feature::TOPICS.into(),
|
|
feature::EVENTS.into(),
|
|
feature::STREAMS.into(),
|
|
feature::ACTIVITY.into(),
|
|
feature::ADMIN.into(),
|
|
],
|
|
},
|
|
},
|
|
Event::Talking { session, client: 3, talking: true },
|
|
Event::StreamsChanged {
|
|
session,
|
|
streams: vec![StreamInfo {
|
|
id: "demo-stream".into(),
|
|
streamer: tsclientlib::ClientId(2),
|
|
name: "Exploring the Lands Between".into(),
|
|
kind: StreamKind::Screen,
|
|
bitrate: 8000,
|
|
viewer_limit: 0,
|
|
audio: true,
|
|
}],
|
|
},
|
|
Event::State {
|
|
session: session + 1,
|
|
state: SessionState { observe: ObserveState::Observing, ..Default::default() },
|
|
},
|
|
];
|
|
for event in events {
|
|
app.handle_event(event);
|
|
}
|
|
demo_chat(app, session);
|
|
demo_social(app);
|
|
// No toast over the screenshots.
|
|
app.set_status("");
|
|
app.refresh_all();
|
|
}
|
|
|
|
/// Sample people, private chats, pokes, notifications, events, a picture
|
|
/// and recordings for the home, friends, messages, events and settings
|
|
/// screens (`VOELIN_DEMO_UI`).
|
|
fn demo_social(app: &mut App) {
|
|
let session = DEMO as u64;
|
|
let now = chrono::Utc::now().timestamp_millis();
|
|
let min = 60_000;
|
|
// The second sample server is observed: a few people there.
|
|
let mut lounge = Presence { server_name: "Pixel Lounge".into(), ..Default::default() };
|
|
for c in [channel(1, 0, 0, "Lobby"), channel(2, 0, 1, "Art Corner"), channel(3, 0, 2, "Music")]
|
|
{
|
|
lounge.channels.insert(c.id, c);
|
|
}
|
|
let mut ivy = client(21, 2, "Ivy");
|
|
ivy.uid = Some("demo-ivy".into());
|
|
let mut sora = client(22, 3, "Sora");
|
|
sora.uid = Some("demo-sora".into());
|
|
sora.away = Some("painting".into());
|
|
let mut pixel = client(23, 1, "Pixel");
|
|
pixel.uid = Some("demo-pixel".into());
|
|
for c in [ivy, sora, pixel] {
|
|
lounge.clients.insert(c.id, c);
|
|
}
|
|
app.handle_event(Event::Presence { session: session + 1, presence: Arc::new(lounge) });
|
|
app.handle_event(Event::State {
|
|
session: session + 1,
|
|
state: SessionState {
|
|
observe: ObserveState::Observing,
|
|
presence_source: Some(Source::Gateway),
|
|
server_uid: Some("demo-lounge".into()),
|
|
..Default::default()
|
|
},
|
|
});
|
|
app.handle_event(Event::ServerInfo {
|
|
session: session + 1,
|
|
name: "Pixel Lounge".into(),
|
|
flavor: ServerFlavor::from_version_string("3.13.8 [Build: 1]"),
|
|
capabilities: Default::default(),
|
|
});
|
|
|
|
// Contacts: friends here and there, some offline, one blocked.
|
|
let contact =
|
|
|uid: &str, nick: &str, relation: Relation, seen_min: i64, server: &str| Contact {
|
|
uid: uid.into(),
|
|
nickname: nick.into(),
|
|
relation,
|
|
note: String::new(),
|
|
muted: false,
|
|
volume: 1.0,
|
|
added_ms: now - 400 * 86_400_000,
|
|
last_seen_ms: if seen_min > 0 { now - seen_min * min } else { 0 },
|
|
last_server: (!server.is_empty()).then(|| server.to_owned()),
|
|
};
|
|
let mut kairo = contact("demo-3", "Kairo", Relation::Friend, 1, "Nightfall Guild");
|
|
kairo.note = "Tank on Tuesday raids. Always down for co-op.".into();
|
|
let contacts = vec![
|
|
contact("demo-2", "Lumen", Relation::Friend, 1, "Nightfall Guild"),
|
|
kairo,
|
|
contact("demo-4", "Mira", Relation::Friend, 1, "Nightfall Guild"),
|
|
contact("demo-5", "dex", Relation::Friend, 1, "Nightfall Guild"),
|
|
contact("demo-6", "Talon", Relation::Friend, 1, "Nightfall Guild"),
|
|
contact("demo-7", "Zeph", Relation::Friend, 1, "Nightfall Guild"),
|
|
contact("demo-ivy", "Ivy", Relation::Friend, 1, "Pixel Lounge"),
|
|
contact("demo-sora", "Sora", Relation::Friend, 1, "Pixel Lounge"),
|
|
contact("demo-ari", "Ari", Relation::Friend, 130, "Nightfall Guild"),
|
|
contact("demo-neon", "Neon", Relation::Friend, 26 * 60, "Dev TS3"),
|
|
contact("demo-9", "Rin", Relation::Neutral, 1, "Nightfall Guild"),
|
|
contact("demo-spam", "FreeSkinsBot", Relation::Blocked, 3 * 24 * 60, "Pixel Lounge"),
|
|
];
|
|
app.handle_event(Event::ContactsChanged { contacts: Arc::new(contacts) });
|
|
for (uid, ago) in [
|
|
("demo-2", 12),
|
|
("demo-3", 28),
|
|
("demo-4", 42),
|
|
("demo-5", 64),
|
|
("demo-6", 95),
|
|
("demo-7", 130),
|
|
("demo-ivy", 8),
|
|
("demo-sora", 50),
|
|
] {
|
|
app.social.online_since.insert(uid.into(), now - ago * min);
|
|
}
|
|
|
|
// Private chats: with Kairo (a picture, a file), Mira, Lumen, dex,
|
|
// and Ivy on the other server; Neon's is only stored.
|
|
let picture = file_link(2, "night-castle.png", 412_331);
|
|
let private =
|
|
|id: i64, peer: &str, from_me: bool, author: (&str, u16), text: String, ago: i64| {
|
|
HistoryMessage {
|
|
id,
|
|
message: ChatMessage {
|
|
target: ChatTarget::Private(peer.into()),
|
|
author_name: author.0.into(),
|
|
author_uid: Some(if from_me { "demo-1".into() } else { peer.into() }),
|
|
author_id: (author.1 > 0).then_some(author.1),
|
|
text,
|
|
ts_ms: now - ago * min,
|
|
via_relay: false,
|
|
blocked: false,
|
|
},
|
|
source: MessageSource::Voice,
|
|
remote_id: None,
|
|
topic_id: None,
|
|
reactions: Vec::new(),
|
|
pinned: false,
|
|
rev: 0,
|
|
}
|
|
};
|
|
let nova = ("Nova", 1);
|
|
let kairo = ("Kairo", 3);
|
|
let lines = vec![
|
|
private(
|
|
300,
|
|
"demo-3",
|
|
true,
|
|
nova,
|
|
format!("Hey! Check out this shot I got last night while exploring 👀 {picture}"),
|
|
95,
|
|
),
|
|
private(301, "demo-3", false, kairo, "That looks incredible! Where was this?".into(), 93),
|
|
private(
|
|
302,
|
|
"demo-3",
|
|
true,
|
|
nova,
|
|
"In the northern region. The lighting was perfect.".into(),
|
|
91,
|
|
),
|
|
private(
|
|
303,
|
|
"demo-3",
|
|
false,
|
|
kairo,
|
|
"We should explore together this weekend! I found some cool locations too.".into(),
|
|
89,
|
|
),
|
|
private(
|
|
304,
|
|
"demo-3",
|
|
false,
|
|
kairo,
|
|
format!(
|
|
"Here are the spots I marked. {}",
|
|
file_link(2, "exploration-routes.pdf", 2_516_582)
|
|
),
|
|
88,
|
|
),
|
|
private(305, "demo-3", true, nova, "That sunset looks unreal. Let's do it! 🙌".into(), 6),
|
|
private(
|
|
310,
|
|
"demo-4",
|
|
false,
|
|
("Mira", 4),
|
|
"Working on a new video today, want to see a sneak peek?".into(),
|
|
70,
|
|
),
|
|
private(311, "demo-2", false, ("Lumen", 2), "Let's run it tonight!".into(), 120),
|
|
private(312, "demo-5", false, ("dex", 5), file_link(2, "map-notes.png", 96_120), 26 * 60),
|
|
];
|
|
for m in lines {
|
|
let target = m.message.target.clone();
|
|
app.handle_event(Event::ChatHistory {
|
|
session,
|
|
target,
|
|
messages: vec![m],
|
|
source: HistorySource::Gateway,
|
|
complete: true,
|
|
});
|
|
}
|
|
app.handle_event(Event::ChatHistory {
|
|
session: session + 1,
|
|
target: ChatTarget::Private("demo-ivy".into()),
|
|
messages: vec![HistoryMessage {
|
|
message: ChatMessage {
|
|
target: ChatTarget::Private("demo-ivy".into()),
|
|
author_name: "Ivy".into(),
|
|
author_uid: Some("demo-ivy".into()),
|
|
author_id: Some(21),
|
|
text: "Same here! The new channel is great.".into(),
|
|
ts_ms: now - 30 * min,
|
|
via_relay: true,
|
|
blocked: false,
|
|
},
|
|
..private(320, "demo-ivy", false, ("Ivy", 21), String::new(), 30)
|
|
}],
|
|
source: HistorySource::Gateway,
|
|
complete: true,
|
|
});
|
|
let mut neon = private(
|
|
330,
|
|
"demo-neon",
|
|
false,
|
|
("Neon", 0),
|
|
"Sent you the config, check the server folder.".into(),
|
|
3 * 24 * 60,
|
|
);
|
|
neon.message.author_id = None;
|
|
app.social.dm.stored.push(("demo-dev".into(), neon));
|
|
app.social.dm.bookmark_of.insert("demo-dev".into(), DEMO + 2);
|
|
// Unread: Mira's and Lumen's messages came while away.
|
|
if let Some(view) = app.sessions.get_mut(&DEMO) {
|
|
for tab in &mut view.tabs {
|
|
match &tab.target {
|
|
ChatTarget::Private(uid) if uid == "demo-4" => tab.unread = 1,
|
|
ChatTarget::Private(uid) if uid == "demo-2" => tab.unread = 2,
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
// A poke from Kairo, shown among the messages and in the bell.
|
|
app.handle_event(Event::Poke {
|
|
session,
|
|
from: 3,
|
|
from_uid: Some("demo-3".into()),
|
|
from_name: "Kairo".into(),
|
|
message: "raid in 5?".into(),
|
|
blocked: false,
|
|
});
|
|
if let Some(p) = app.social.pokes.last_mut() {
|
|
p.ts_ms = now - 7 * min;
|
|
}
|
|
|
|
// The pictures of the links, as if downloaded.
|
|
if let Some(view) = app.sessions.get_mut(&DEMO) {
|
|
for (channel, name) in
|
|
[(2, "night-castle.png"), (2, "guild-banner.png"), (2, "map-notes.png")]
|
|
{
|
|
let file = voelin_model::FileRef {
|
|
channel,
|
|
path: "/".into(),
|
|
name: name.into(),
|
|
..Default::default()
|
|
};
|
|
view.extra.previews.insert(
|
|
crate::previews::link_key(&file),
|
|
crate::previews::Preview::Ready(voelin_core::Bytes(
|
|
demo_picture(640, 360, name.len() as u32).into(),
|
|
)),
|
|
);
|
|
}
|
|
}
|
|
|
|
// The gateway's events (one is live), its configuration and rules.
|
|
let by = |name: &str, uid: &str| UserRef { uid: uid.into(), name: name.into() };
|
|
let event =
|
|
|id: i64, title: &str, start: i64, hours: i64, channel: Option<u64>, stream: bool| {
|
|
EventInfo {
|
|
id,
|
|
spec: EventSpec {
|
|
title: title.into(),
|
|
description: String::new(),
|
|
start_ms: start,
|
|
end_ms: Some(start + hours * 3_600_000),
|
|
channel,
|
|
kind: if stream { EventKind::Stream } else { EventKind::General },
|
|
stream_title: None,
|
|
stream_game: None,
|
|
host_uid: None,
|
|
},
|
|
creator: by("Nova", "demo-1"),
|
|
created_ms: now - 86_400_000,
|
|
updated_ms: now - 86_400_000,
|
|
going: 0,
|
|
maybe: 0,
|
|
not_going: 0,
|
|
my_rsvp: None,
|
|
attendees: Vec::new(),
|
|
live_stream: None,
|
|
}
|
|
};
|
|
let hour = 3_600_000;
|
|
let tomorrow = (now / 86_400_000 + 1) * 86_400_000 + 18 * hour;
|
|
let mut raid = event(1, "Raid Night: The Frozen Citadel", tomorrow, 3, Some(4), false);
|
|
raid.spec.description = "Bring elixirs and fire resistance. Voice in Raid Night.".into();
|
|
raid.going = 12;
|
|
raid.maybe = 4;
|
|
raid.not_going = 1;
|
|
raid.my_rsvp = Some(RsvpStatus::Going);
|
|
raid.attendees = vec![
|
|
Attendee { user: by("Nova", "demo-1"), status: RsvpStatus::Going, ts_ms: now },
|
|
Attendee { user: by("Kairo", "demo-3"), status: RsvpStatus::Going, ts_ms: now },
|
|
Attendee { user: by("Mira", "demo-4"), status: RsvpStatus::Maybe, ts_ms: now },
|
|
Attendee { user: by("dex", "demo-5"), status: RsvpStatus::NotGoing, ts_ms: now },
|
|
];
|
|
let mut live = event(2, "Exploring the Lands Between", now - 12 * min, 2, Some(2), true);
|
|
live.spec.stream_title = Some("Exploring the Lands Between".into());
|
|
live.spec.stream_game = Some("Elden Ring".into());
|
|
live.creator = by("Lumen", "demo-2");
|
|
live.going = 8;
|
|
live.live_stream = Some("demo-stream".into());
|
|
let mut night = event(3, "Community Game Night", tomorrow + 2 * 86_400_000, 3, None, false);
|
|
night.spec.description = "Party games for everyone: drop in any time.".into();
|
|
night.creator = by("Talon", "demo-6");
|
|
night.going = 23;
|
|
night.maybe = 9;
|
|
let mut lofi = event(4, "Late Night Lofi & Chat", now + 50 * min, 2, Some(5), true);
|
|
lofi.spec.stream_title = Some("Lofi beats to raid to".into());
|
|
lofi.creator = by("Mira", "demo-4");
|
|
lofi.going = 5;
|
|
lofi.maybe = 2;
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Events { events: vec![raid, live, night, lofi] },
|
|
});
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Permissions {
|
|
channel: None,
|
|
actions: vec![
|
|
Action::React,
|
|
Action::Pin,
|
|
Action::CreateEvent,
|
|
Action::Rsvp,
|
|
Action::Moderate,
|
|
Action::Admin,
|
|
],
|
|
},
|
|
});
|
|
let config = |key: &str, value: serde_json::Value, source: ConfigSource, description: &str| {
|
|
ConfigEntry {
|
|
key: key.into(),
|
|
default: value.clone(),
|
|
value,
|
|
source,
|
|
value_type: "int".into(),
|
|
description: description.into(),
|
|
bootstrap: false,
|
|
}
|
|
};
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Config {
|
|
entries: vec![
|
|
config(
|
|
"history.retention_days",
|
|
serde_json::json!(90),
|
|
ConfigSource::Db,
|
|
"Days of chat history the gateway keeps.",
|
|
),
|
|
config(
|
|
"events.reminders_min",
|
|
serde_json::json!([60, 15, 0]),
|
|
ConfigSource::File,
|
|
"Minutes before an event when reminders go out.",
|
|
),
|
|
config(
|
|
"streams.directory",
|
|
serde_json::json!(true),
|
|
ConfigSource::Default,
|
|
"Keep a directory of the server's streams.",
|
|
),
|
|
],
|
|
},
|
|
});
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::PermRules {
|
|
rules: vec![
|
|
PermRuleInfo {
|
|
action: Action::CreateEvent,
|
|
rule: Some(PermRule {
|
|
everyone: false,
|
|
server_groups: vec![GROUP_ADMIN, GROUP_MOD],
|
|
channel_groups: vec![],
|
|
}),
|
|
source: ConfigSource::Db,
|
|
default: "server admins".into(),
|
|
},
|
|
PermRuleInfo {
|
|
action: Action::Pin,
|
|
rule: None,
|
|
source: ConfigSource::Default,
|
|
default: "moderators".into(),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
// Notifications: a mention, a message, an event, a friend online (and
|
|
// the poke above).
|
|
use crate::social::{NoticeKind, NoticeTarget};
|
|
app.notify(
|
|
NoticeKind::Mention,
|
|
"Talon mentioned you".into(),
|
|
"Nova, can you open the raid at 20:00? — #Chill Zone · Nightfall Guild".into(),
|
|
NoticeTarget::Chat(DEMO, ChatTarget::Channel(2)),
|
|
"Talon".into(),
|
|
Some("demo-6".into()),
|
|
);
|
|
app.notify(
|
|
NoticeKind::Event,
|
|
"Late Night Lofi & Chat starts in 50 min".into(),
|
|
"on Nightfall Guild".into(),
|
|
NoticeTarget::Event(DEMO, 4),
|
|
"Mira".into(),
|
|
Some("demo-4".into()),
|
|
);
|
|
app.notify(
|
|
NoticeKind::Friend,
|
|
"Ivy is online".into(),
|
|
"on Pixel Lounge · #Art Corner".into(),
|
|
NoticeTarget::Contact("demo-ivy".into()),
|
|
"Ivy".into(),
|
|
Some("demo-ivy".into()),
|
|
);
|
|
app.notify(
|
|
NoticeKind::Message,
|
|
"Mira".into(),
|
|
"Working on a new video today, want to see a sneak peek?".into(),
|
|
NoticeTarget::Dm(DEMO, "demo-4".into()),
|
|
"Mira".into(),
|
|
Some("demo-4".into()),
|
|
);
|
|
for (i, n) in app.social.notices.iter_mut().enumerate() {
|
|
n.ts_ms = now - (i as i64 * 9 + 2) * min;
|
|
n.unread = i < 3;
|
|
}
|
|
app.refresh_notices();
|
|
|
|
// Recordings and clips of the Studio.
|
|
let recording = |name: &str, detail: &str| RecordingItem {
|
|
name: name.into(),
|
|
detail: detail.into(),
|
|
clip: name.contains("clip"),
|
|
path: format!("/tmp/{name}").into(),
|
|
};
|
|
crate::vm::list::sync(
|
|
&app.models.social.recordings,
|
|
&[
|
|
recording("raid-night-2026-10-02.webm", "1.2 GB · 2 Oct 22:41"),
|
|
recording("clip-boss-down.mkv", "38.4 MB · 2 Oct 21:57"),
|
|
recording("lands-between-stream.mkv", "2.8 GB · 28 Sep 20:12"),
|
|
recording("clip-lucky-parry.mkv", "12.1 MB · 28 Sep 19:40"),
|
|
],
|
|
);
|
|
app.refresh_chats();
|
|
app.refresh_people();
|
|
app.refresh_home();
|
|
}
|
|
|
|
/// A painted night: sky, moon, stars, hills and a castle; PNG bytes.
|
|
fn demo_picture(width: u32, height: u32, seed: u32) -> Vec<u8> {
|
|
let mut rgba = Vec::with_capacity((width * height * 4) as usize);
|
|
let (w, h) = (width as f32, height as f32);
|
|
let (mx, my, mr) = (w * 0.68, h * 0.3, h * 0.17);
|
|
let hash = |x: u32, y: u32| {
|
|
let mut v = x.wrapping_mul(374_761_393)
|
|
^ y.wrapping_mul(668_265_263)
|
|
^ seed.wrapping_mul(2_654_435_761);
|
|
v = (v ^ (v >> 13)).wrapping_mul(1_274_126_177);
|
|
v ^ (v >> 16)
|
|
};
|
|
for y in 0..height {
|
|
for x in 0..width {
|
|
let (fx, fy) = (x as f32, y as f32);
|
|
let t = fy / h;
|
|
// Sky: deep blue to violet at the horizon.
|
|
let mut c = [12.0 + 50.0 * t, 18.0 + 30.0 * t, 60.0 + 90.0 * t];
|
|
// Moon and its glow.
|
|
let d = ((fx - mx).powi(2) + (fy - my).powi(2)).sqrt();
|
|
if d < mr {
|
|
let shade = 1.0 - 0.25 * ((fx - mx + mr * 0.3) / mr).max(0.0);
|
|
c = [200.0 * shade, 210.0 * shade, 245.0 * shade];
|
|
} else {
|
|
let glow = (1.0 - (d - mr) / (mr * 2.5)).max(0.0) * 60.0;
|
|
c = [c[0] + glow, c[1] + glow, c[2] + glow * 1.2];
|
|
}
|
|
if hash(x, y) % 900 == 0 && t < 0.6 {
|
|
c = [235.0, 235.0, 255.0];
|
|
}
|
|
// Hills, then a castle on the middle one.
|
|
let far = h * 0.62 + (fx / w * 9.0 + seed as f32).sin() * h * 0.05;
|
|
let near = h * 0.78 + (fx / w * 5.0 + 1.3).sin() * h * 0.06;
|
|
let castle = (fx > w * 0.36
|
|
&& fx < w * 0.52
|
|
&& fy > h * 0.38
|
|
&& ((((fx - w * 0.36) / (w * 0.02)) as u32).is_multiple_of(2) || fy > h * 0.45))
|
|
|| (fx > w * 0.42 && fx < w * 0.46 && fy > h * 0.24);
|
|
if fy > near {
|
|
c = [6.0, 10.0, 26.0];
|
|
} else if fy > far || castle {
|
|
c = [16.0, 20.0, 52.0];
|
|
// Lit windows.
|
|
if castle && hash(x / 6, y / 8) % 7 == 0 && (x % 6) < 3 && (y % 8) < 4 {
|
|
c = [255.0, 190.0, 90.0];
|
|
}
|
|
}
|
|
rgba.extend([c[0].min(255.0) as u8, c[1].min(255.0) as u8, c[2].min(255.0) as u8, 255]);
|
|
}
|
|
}
|
|
let mut out = Vec::new();
|
|
let mut encoder = png::Encoder::new(&mut out, width, height);
|
|
encoder.set_color(png::ColorType::Rgba);
|
|
encoder.set_depth(png::BitDepth::Eight);
|
|
if let Ok(mut writer) = encoder.write_header() {
|
|
let _ = writer.write_image_data(&rgba);
|
|
}
|
|
out
|
|
}
|
|
|
|
/// Server group ids of the sample server.
|
|
const GROUP_ADMIN: u64 = 6;
|
|
const GROUP_MOD: u64 = 7;
|
|
const GROUP_MEMBER: u64 = 8;
|
|
const GROUP_GUEST: u64 = 9;
|
|
|
|
/// A file link as TeamSpeak clients post it.
|
|
fn file_link(channel: u64, name: &str, size: u64) -> String {
|
|
voelin_model::FileRef {
|
|
channel,
|
|
path: "/".into(),
|
|
name: name.into(),
|
|
size: Some(size),
|
|
..Default::default()
|
|
}
|
|
.to_bbcode()
|
|
}
|
|
|
|
/// One sample message: chat, author, its client, text, how many minutes
|
|
/// ago, relayed, reactions, pinned, and the topic it belongs to.
|
|
type SampleLine =
|
|
(i64, &'static str, u16, String, i64, bool, Vec<ReactionCount>, bool, Option<i64>);
|
|
|
|
/// The sample chats, as stored messages with reactions, pins and topics.
|
|
fn demo_chat(app: &mut App, session: u64) {
|
|
let now = chrono::Utc::now().timestamp_millis();
|
|
let react =
|
|
|emoji: &str, count: u32, me: bool| ReactionCount { emoji: emoji.into(), count, me };
|
|
let lines: Vec<SampleLine> = vec![
|
|
(
|
|
DEMO,
|
|
"Nova",
|
|
1,
|
|
"Beautiful morning for a game. Who's up for a session later? ☀️".into(),
|
|
60,
|
|
false,
|
|
vec![react("👍", 3, false), react("☀️", 1, true)],
|
|
false,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Kairo",
|
|
3,
|
|
"Definitely! I'll be on after lunch.".into(),
|
|
56,
|
|
false,
|
|
Vec::new(),
|
|
false,
|
|
None,
|
|
),
|
|
(DEMO, "Kairo", 3, "Bringing snacks 🍕🍩".into(), 56, false, Vec::new(), false, None),
|
|
(
|
|
DEMO,
|
|
"Mira",
|
|
4,
|
|
format!(
|
|
"Route for tonight, print it out: {}",
|
|
file_link(2, "raid-route.pdf", 2_411_724)
|
|
),
|
|
40,
|
|
false,
|
|
vec![react("🎉", 5, true)],
|
|
true,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Nova",
|
|
1,
|
|
"Reminder: raid starts 20:00 sharp, bring elixirs.".into(),
|
|
30,
|
|
false,
|
|
Vec::new(),
|
|
true,
|
|
Some(1),
|
|
),
|
|
(
|
|
DEMO,
|
|
"dex",
|
|
5,
|
|
"Can somebody look at the wiki page? The old link is dead.".into(),
|
|
26,
|
|
false,
|
|
Vec::new(),
|
|
false,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Kairo",
|
|
3,
|
|
"Fixed, it points at the new host now.".into(),
|
|
24,
|
|
false,
|
|
vec![react("👍", 2, false)],
|
|
false,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Mira",
|
|
4,
|
|
format!("And the banner I promised: {}", file_link(2, "guild-banner.png", 486_912)),
|
|
20,
|
|
false,
|
|
Vec::new(),
|
|
false,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Talon",
|
|
6,
|
|
"That looks great. Putting it on the site tonight.".into(),
|
|
17,
|
|
false,
|
|
vec![react("❤️", 4, true)],
|
|
false,
|
|
None,
|
|
),
|
|
(
|
|
DEMO,
|
|
"Lumen",
|
|
2,
|
|
"Going live in Chill Zone — exploring the Lands Between. Come hang! 🔥🗡️".into(),
|
|
12,
|
|
false,
|
|
vec![react("🔥", 8, false)],
|
|
false,
|
|
None,
|
|
),
|
|
(DEMO, "dex", 5, "🎉🎉".into(), 10, false, Vec::new(), false, None),
|
|
(
|
|
DEMO,
|
|
"Ari",
|
|
0,
|
|
"Anyone want to run some co-op later? 👀 Posting from the web.".into(),
|
|
5,
|
|
true,
|
|
Vec::new(),
|
|
false,
|
|
None,
|
|
),
|
|
(DEMO + 1, "Ivy", 0, "Welcome to the lounge!".into(), 30, false, Vec::new(), false, None),
|
|
(
|
|
DEMO + 1,
|
|
"Ivy",
|
|
0,
|
|
"New channel for artists 🎨".into(),
|
|
29,
|
|
false,
|
|
Vec::new(),
|
|
false,
|
|
None,
|
|
),
|
|
];
|
|
let mut id = 1;
|
|
let mut pinned: Vec<HistoryMessage> = Vec::new();
|
|
for (chat, author, client, text, ago, relay, reactions, pin, topic) in lines {
|
|
let target = if chat == DEMO { ChatTarget::Channel(2) } else { ChatTarget::Server };
|
|
let message = HistoryMessage {
|
|
id,
|
|
message: ChatMessage {
|
|
target: target.clone(),
|
|
author_name: author.into(),
|
|
author_uid: Some(format!("demo-{client}")),
|
|
author_id: (client > 0).then_some(client),
|
|
text,
|
|
ts_ms: now - ago * 60_000,
|
|
via_relay: relay,
|
|
blocked: false,
|
|
},
|
|
source: MessageSource::Voice,
|
|
remote_id: Some(id),
|
|
topic_id: topic,
|
|
reactions,
|
|
pinned: pin,
|
|
rev: 1,
|
|
};
|
|
if pin {
|
|
pinned.push(message.clone());
|
|
}
|
|
app.handle_event(Event::ChatHistory {
|
|
session: if chat == DEMO { session } else { session + 1 },
|
|
target,
|
|
messages: vec![message],
|
|
source: HistorySource::Gateway,
|
|
complete: false,
|
|
});
|
|
id += 1;
|
|
}
|
|
// A server chat besides the channel chat.
|
|
app.handle_event(Event::ChatHistory {
|
|
session,
|
|
target: ChatTarget::Server,
|
|
messages: vec![HistoryMessage {
|
|
id: 100,
|
|
message: ChatMessage {
|
|
target: ChatTarget::Server,
|
|
author_name: "Talon".into(),
|
|
author_uid: Some("demo-6".into()),
|
|
author_id: Some(6),
|
|
text: "Server restart tonight at 23:00.".into(),
|
|
ts_ms: now - 40 * 60_000,
|
|
via_relay: false,
|
|
blocked: false,
|
|
},
|
|
source: MessageSource::Voice,
|
|
remote_id: Some(100),
|
|
topic_id: None,
|
|
reactions: Vec::new(),
|
|
pinned: false,
|
|
rev: 1,
|
|
}],
|
|
source: HistorySource::Gateway,
|
|
complete: true,
|
|
});
|
|
// The gateway's answers (no gateway runs in demo mode): the stream
|
|
// directory, and the pins and topics for the drawers.
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Streams {
|
|
streams: vec![
|
|
StreamEntry {
|
|
id: "demo-stream".into(),
|
|
stream_id: Some("demo-stream".into()),
|
|
streamer: UserRef { uid: "demo-2".into(), name: "Lumen".into() },
|
|
client_id: Some(2),
|
|
channel: Some(2),
|
|
title: "Exploring the Lands Between".into(),
|
|
kind: "screen".into(),
|
|
started_ms: now - 12 * 60_000,
|
|
viewers: Some(12),
|
|
source: StreamSource::Registered,
|
|
event_id: None,
|
|
},
|
|
StreamEntry {
|
|
id: "demo-stream-2".into(),
|
|
stream_id: Some("demo-stream-2".into()),
|
|
streamer: UserRef { uid: "demo-6".into(), name: "Talon".into() },
|
|
client_id: Some(6),
|
|
channel: Some(3),
|
|
title: "Ranked Grind & Vibes".into(),
|
|
kind: "screen".into(),
|
|
started_ms: now - 41 * 60_000,
|
|
viewers: Some(38),
|
|
source: StreamSource::Registered,
|
|
event_id: None,
|
|
},
|
|
StreamEntry {
|
|
id: "demo-stream-3".into(),
|
|
stream_id: Some("demo-stream-3".into()),
|
|
streamer: UserRef { uid: "demo-7".into(), name: "Zeph".into() },
|
|
client_id: Some(7),
|
|
channel: Some(4),
|
|
title: "Raid prep: gear check".into(),
|
|
kind: "camera".into(),
|
|
started_ms: now - 8 * 60_000,
|
|
viewers: Some(9),
|
|
source: StreamSource::Registered,
|
|
event_id: None,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
let by = |name: &str| UserRef { uid: format!("demo-{name}"), name: name.into() };
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Pins {
|
|
target: ChatTarget::Channel(2),
|
|
pins: pinned
|
|
.into_iter()
|
|
.map(|message| Pin {
|
|
ts_ms: message.message.ts_ms + 60_000,
|
|
by: by("Nova"),
|
|
message,
|
|
})
|
|
.collect(),
|
|
},
|
|
});
|
|
let topic = |id: i64, title: &str, count: u64, ago: i64| TopicInfo {
|
|
id,
|
|
target: ChatTarget::Channel(2),
|
|
title: title.into(),
|
|
creator: by("Nova"),
|
|
created_ms: now - 5 * 86_400_000,
|
|
root_message_id: Some(5),
|
|
last_activity_ms: now - ago * 60_000,
|
|
message_count: count,
|
|
archived: false,
|
|
};
|
|
app.handle_event(Event::Gateway {
|
|
session,
|
|
update: GatewayUpdate::Topics {
|
|
target: ChatTarget::Channel(2),
|
|
topics: vec![
|
|
topic(1, "Tonight's raid", 14, 3),
|
|
topic(2, "Build ideas for the new patch", 42, 95),
|
|
topic(3, "Server rules", 6, 2880),
|
|
],
|
|
},
|
|
});
|
|
}
|
|
|
|
/// The messages of the sample topic, as the gateway answers when it is
|
|
/// opened.
|
|
fn demo_topic(app: &mut App) {
|
|
let now = chrono::Utc::now().timestamp_millis();
|
|
app.handle_event(Event::Gateway {
|
|
session: DEMO as u64,
|
|
update: GatewayUpdate::TopicHistory {
|
|
target: ChatTarget::Channel(2),
|
|
topic: 1,
|
|
messages: (0..4)
|
|
.map(|i| HistoryMessage {
|
|
id: 200 + i,
|
|
message: ChatMessage {
|
|
target: ChatTarget::Channel(2),
|
|
author_name: ["Nova", "Kairo", "Mira", "dex"][i as usize].into(),
|
|
author_uid: Some(format!("demo-{}", [1, 3, 4, 5][i as usize])),
|
|
author_id: Some([1, 3, 4, 5][i as usize]),
|
|
text: [
|
|
"Reminder: raid starts 20:00 sharp, bring elixirs.",
|
|
"I can tank if nobody else wants to.",
|
|
"Recording it again, say if you would rather not be in it.",
|
|
"Bringing the good soup 🍲",
|
|
][i as usize]
|
|
.into(),
|
|
ts_ms: now - (20 - i * 4) * 60_000,
|
|
via_relay: false,
|
|
blocked: false,
|
|
},
|
|
source: MessageSource::Gateway,
|
|
remote_id: Some(200 + i),
|
|
topic_id: Some(1),
|
|
reactions: Vec::new(),
|
|
pinned: false,
|
|
rev: 1,
|
|
})
|
|
.collect(),
|
|
has_more: false,
|
|
},
|
|
});
|
|
}
|