community: a proposal on your board arrives as a toast, carried sealed through the inbox
This commit is contained in:
1 parent
4d03cf849b
commit
fd216ecd3d
6 files changed
+241
-1
No files matched your search
@@ -52,6 +52,17 @@ pub enum Cargo {
|
||||
Share(ShareCargo),
|
||||
SpaceInvite(SpaceInvite),
|
||||
SpaceKey(SpaceKeyCargo),
|
||||
ProposalPing(ProposalPing),
|
||||
}
|
||||
|
||||
/// "Someone put a proposal on your playlist's board." Carries only enough to
|
||||
/// name it in a toast — the board itself stays the truth, and this is a
|
||||
/// best-effort nudge: the proposal stands whether or not the ping lands.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProposalPing {
|
||||
pub playlist_uuid: [u8; 16],
|
||||
pub name: String,
|
||||
pub proposal_id: [u8; 16],
|
||||
}
|
||||
|
||||
/// "You are on the roster now, here is where the Space is" — and, for a
|
||||
@@ -483,6 +494,7 @@ async fn dispatch(app: &tauri::AppHandle, sender: [u8; 32], cargo: Cargo) {
|
||||
Cargo::Share(s) => crate::shared_playlists::on_inbox_share(app, sender, s).await,
|
||||
Cargo::SpaceInvite(i) => crate::spaces::on_inbox_invite(app, sender, i).await,
|
||||
Cargo::SpaceKey(k) => crate::spaces::on_inbox_space_key(app, sender, k).await,
|
||||
Cargo::ProposalPing(p) => crate::proposals::on_inbox_proposal(app, sender, p),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,4 +525,44 @@ mod tests {
|
||||
assert_eq!(inbox.code_hash, "UjK4sLZqGSE2qEXwQYMvNFsTiuLSYjMJuwzVbhAtXKR");
|
||||
assert_eq!(desc.code_hash, "B4A2nMJgSKzgo72gaDJyTpFNTmjBynLFga3EiNoSVstv");
|
||||
}
|
||||
|
||||
/// The wire is the variant ORDER: bincode writes the index, so inserting a
|
||||
/// variant renumbers every one after it and silently breaks every sealed
|
||||
/// message already in flight. New cargo goes on the END, and this pins it.
|
||||
#[test]
|
||||
fn cargo_variant_indices_are_the_wire() {
|
||||
let index = |c: &Cargo| {
|
||||
let b = bincode::serialize(c).unwrap();
|
||||
u32::from_le_bytes(b[..4].try_into().unwrap())
|
||||
};
|
||||
let share = Cargo::Share(ShareCargo {
|
||||
owner: [1u8; 32],
|
||||
playlist_uuid: [2u8; 16],
|
||||
name: "n".into(),
|
||||
entry_count: 1,
|
||||
});
|
||||
let key = Cargo::SpaceKey(SpaceKeyCargo {
|
||||
space_id: [3u8; 16],
|
||||
owner: [4u8; 32],
|
||||
epoch: 9,
|
||||
key: [5u8; 32],
|
||||
});
|
||||
let ping = Cargo::ProposalPing(ProposalPing {
|
||||
playlist_uuid: [6u8; 16],
|
||||
name: "Late Night Ambient".into(),
|
||||
proposal_id: [7u8; 16],
|
||||
});
|
||||
assert_eq!(index(&share), 3, "Share moved — sealed shares in flight are now unreadable");
|
||||
assert_eq!(index(&key), 5, "SpaceKey moved — sealed keys in flight are now unreadable");
|
||||
assert_eq!(index(&ping), 6, "a new variant must be appended, never inserted");
|
||||
|
||||
let back: Cargo = bincode::deserialize(&bincode::serialize(&ping).unwrap()).unwrap();
|
||||
match back {
|
||||
Cargo::ProposalPing(p) => {
|
||||
assert_eq!(p.name, "Late Night Ambient");
|
||||
assert_eq!(p.proposal_id, [7u8; 16]);
|
||||
}
|
||||
other => panic!("round-tripped into {other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,18 +24,21 @@ use library::{NewPlaylistItem, PlaylistItem};
|
||||
use persona_state::playlist as pl;
|
||||
use persona_state::proposals as pr;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::Manager;
|
||||
use tauri::{Emitter, Manager};
|
||||
|
||||
use crate::persona;
|
||||
use crate::pipeline::LibraryState;
|
||||
use crate::playlists;
|
||||
use crate::shared_playlists::{self, Published};
|
||||
use crate::inbox::{self, Cargo, ProposalPing};
|
||||
use crate::ledger;
|
||||
use crate::slsk_link;
|
||||
use crate::spaces;
|
||||
use crate::state::AppState;
|
||||
|
||||
const BOARD_WASM: &[u8] = include_bytes!("../assets/proposal_contract.wasm");
|
||||
/// A proposal landed on a board of ours. The UI answers with a toast.
|
||||
pub const EVENT: &str = "community:proposal";
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
struct BoardRecord {
|
||||
@@ -502,8 +505,22 @@ pub async fn propose(app: &tauri::AppHandle, space_owner_b58: &str, space_b58: &
|
||||
if !pr::proposal_valid(&p) {
|
||||
return Err("the proposal did not validate (a size or field cap)".into());
|
||||
}
|
||||
let pid = p.proposal_id;
|
||||
offer_board(app, &pin.owner, &pin.uuid, &partial(&pin.owner, &pin.uuid, None, vec![p], vec![]), false).await?;
|
||||
log::info!("proposals: offered a proposal to board {}", b58(&pin.uuid));
|
||||
// The board only gets read on open and Refresh, so tell the owner it is
|
||||
// there. Best-effort by design: it needs their published inbox, and the
|
||||
// proposal stands on the board whether or not this lands.
|
||||
if pin.owner != me {
|
||||
let ping = Cargo::ProposalPing(ProposalPing {
|
||||
playlist_uuid: pin.uuid,
|
||||
name: manifest.name.clone(),
|
||||
proposal_id: pid,
|
||||
});
|
||||
if let Err(e) = inbox::send(app, &pin.owner, &ping).await {
|
||||
log::info!("proposals: no ping to the owner ({e}) — the board still holds it");
|
||||
}
|
||||
}
|
||||
open(app, space_owner_b58, space_b58).await
|
||||
}
|
||||
|
||||
@@ -555,6 +572,25 @@ pub async fn decide(app: &tauri::AppHandle, space_owner_b58: &str, space_b58: &s
|
||||
open(app, space_owner_b58, space_b58).await
|
||||
}
|
||||
|
||||
/// Sealed cargo from inbox.rs: someone proposed against a playlist of ours.
|
||||
/// Nothing is stored — the board is the record; this only raises the toast.
|
||||
pub(crate) fn on_inbox_proposal(app: &tauri::AppHandle, sender: [u8; 32], ping: ProposalPing) {
|
||||
let key = b58(&sender);
|
||||
let who = slsk_link::username_for_key(app, &key).unwrap_or(key);
|
||||
log::info!("proposals: {who} proposed a change to {:?}", ping.name);
|
||||
let _ = app.emit(
|
||||
EVENT,
|
||||
ProposalPingEvent { from: who, playlist: ping.name, proposal_id: b58(&ping.proposal_id) },
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct ProposalPingEvent {
|
||||
from: String,
|
||||
playlist: String,
|
||||
proposal_id: String,
|
||||
}
|
||||
|
||||
/// Bring the owner's local playlist to `entries`, then publish it as the
|
||||
/// next revision. Refused when the local copy has drifted from the base
|
||||
/// revision — the exact-base rule holds on this side too.
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
import ImportToast from "./components/ImportToast.svelte";
|
||||
import ResolverToast from "./components/ResolverToast.svelte";
|
||||
import UploadToast from "./components/UploadToast.svelte";
|
||||
import ProposalToast from "./components/ProposalToast.svelte";
|
||||
import SetlistScanChip from "./components/SetlistScanChip.svelte";
|
||||
import {
|
||||
ui,
|
||||
@@ -180,6 +181,7 @@
|
||||
<ImportToast />
|
||||
<ResolverToast />
|
||||
<UploadToast />
|
||||
<ProposalToast />
|
||||
<SetlistScanChip />
|
||||
<PreviewOverlay />
|
||||
<LyricsSyncEditor />
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
<script>
|
||||
// Someone proposed a change to a playlist of ours. The board is only read
|
||||
// on open and Refresh, so without this a proposal arrives in silence.
|
||||
// Same slot, pill and motion as the other toasts; like UploadToast, a
|
||||
// second proposal for the same playlist inside the window extends the
|
||||
// hold and counts up rather than replaying the entrance.
|
||||
import Icon from "./Icon.svelte";
|
||||
import { proposalToast } from "../lib/state.svelte.js";
|
||||
|
||||
const HOLD_MS = 4200;
|
||||
const LEAVE_MS = 280;
|
||||
|
||||
let shown = $state(false);
|
||||
let leaving = $state(false);
|
||||
let holdTimer = 0;
|
||||
let leaveTimer = 0;
|
||||
|
||||
$effect(() => {
|
||||
const seq = proposalToast.seq;
|
||||
if (!seq) return;
|
||||
clearTimeout(holdTimer);
|
||||
clearTimeout(leaveTimer);
|
||||
leaving = false;
|
||||
shown = true;
|
||||
holdTimer = setTimeout(() => {
|
||||
leaving = true;
|
||||
leaveTimer = setTimeout(() => {
|
||||
shown = false;
|
||||
leaving = false;
|
||||
}, LEAVE_MS);
|
||||
}, HOLD_MS);
|
||||
return () => {
|
||||
clearTimeout(holdTimer);
|
||||
clearTimeout(leaveTimer);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if shown}
|
||||
<div class="layer" aria-live="polite">
|
||||
<div class="toast" class:leaving>
|
||||
<span class="mark"><Icon name="playlist" size={14} /></span>
|
||||
{#if proposalToast.count > 1}
|
||||
<span class="text"
|
||||
><b>{proposalToast.count} proposals</b> for {proposalToast.playlist}</span
|
||||
>
|
||||
{:else}
|
||||
<span class="text"
|
||||
><b>{proposalToast.from}</b> proposed a change to {proposalToast.playlist}</span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
/* The shared toast slot — UploadToast's geometry verbatim. */
|
||||
.layer {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: calc(var(--player-height, 62px) + 8px + 26px);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
z-index: 80;
|
||||
pointer-events: none;
|
||||
}
|
||||
.toast {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
max-width: min(70vw, 560px);
|
||||
padding: 9px 16px;
|
||||
border-radius: 99px;
|
||||
background: rgba(22, 23, 28, 0.94);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
backdrop-filter: blur(14px);
|
||||
-webkit-backdrop-filter: blur(14px);
|
||||
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
|
||||
font-size: 12.5px;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
animation: toast-in 340ms cubic-bezier(0.22, 1, 0.36, 1) both;
|
||||
}
|
||||
.toast.leaving {
|
||||
animation: toast-out 260ms ease both;
|
||||
}
|
||||
@keyframes toast-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(16px) scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
@keyframes toast-out {
|
||||
to {
|
||||
opacity: 0;
|
||||
transform: translateY(12px) scale(0.97);
|
||||
}
|
||||
}
|
||||
.mark {
|
||||
display: inline-flex;
|
||||
color: var(--accent);
|
||||
}
|
||||
.text {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
b {
|
||||
font-weight: 800;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.toast,
|
||||
.toast.leaving {
|
||||
animation-duration: 1ms;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -8,6 +8,7 @@
|
||||
// <time>", never "online"; and the adapter's states are named for what they
|
||||
// are (node stopped, incompatible, connecting), never softened.
|
||||
import * as api from "./api.js";
|
||||
import { announceProposal } from "./state.svelte.js";
|
||||
|
||||
const LS_SEEN = "community.lastSeen";
|
||||
const LS_FAVS = "community.roomFavs";
|
||||
@@ -338,6 +339,11 @@ export async function initCommunity() {
|
||||
void refreshPublished();
|
||||
});
|
||||
api.onEvent("community:overlap", () => void refreshOverlap());
|
||||
api.onEvent("community:proposal", (p) => {
|
||||
announceProposal(p.from, p.playlist);
|
||||
// If the board is already on screen, show what it is talking about.
|
||||
if (community.board && community.space) void openBoard(community.space.owner, community.space.space_id);
|
||||
});
|
||||
api.onEvent("soulseek:user-state", (p) => {
|
||||
if (p.status === 1 || p.status === 2) noteSeen(p.username);
|
||||
});
|
||||
|
||||
@@ -235,6 +235,27 @@ export function announceUpload(username, name) {
|
||||
uploadToast.seq += 1;
|
||||
}
|
||||
|
||||
/** Someone proposed a change to a playlist of ours (ProposalToast). The board
|
||||
* is only read on open and Refresh, so an arriving proposal would otherwise
|
||||
* be silent. One inbox check can dispatch several at once, so a burst on the
|
||||
* SAME playlist counts up inside one pill the way an album grab does. */
|
||||
export const proposalToast = $state({ seq: 0, from: "", playlist: "", count: 0 });
|
||||
const PROPOSAL_TOAST_WINDOW_MS = 8000;
|
||||
let proposalToastAt = 0;
|
||||
|
||||
export function announceProposal(from, playlist) {
|
||||
const now = Date.now();
|
||||
if (proposalToast.playlist === playlist && now - proposalToastAt < PROPOSAL_TOAST_WINDOW_MS) {
|
||||
proposalToast.count += 1;
|
||||
} else {
|
||||
proposalToast.playlist = playlist;
|
||||
proposalToast.count = 1;
|
||||
}
|
||||
proposalToast.from = from;
|
||||
proposalToastAt = now;
|
||||
proposalToast.seq += 1;
|
||||
}
|
||||
|
||||
/** Background-import status, read by ImportToast. The import window keeps
|
||||
* scanning/copying after it is closed (the component stays mounted, only
|
||||
* its template goes), and closed must never mean invisible: while work
|
||||
@@ -7787,6 +7808,7 @@ if (import.meta.env.DEV) {
|
||||
autoConnect, refreshSourcePrefs, _sourceAudit, sourcePrefs,
|
||||
playlistStore, refreshPlaylists, goToView, peekNextIndices,
|
||||
slsk, search, runSearch, uploadToast, announceUpload,
|
||||
proposalToast, announceProposal,
|
||||
searchTabs, selectSearchTab, closeSearchTab, filesForGroup,
|
||||
downloads, network, sendDm, openChat,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user