Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,7 @@ async fn team_leave(app: tauri::AppHandle, team_id: String) -> Result<team::Spac
// Its profiles open here go back first: once it is left, nothing reaches it.
space::open::close_team_and_wait(&team_id, space::open::QUIT_WAIT).await;
team::leave(&team_id).map_err(|e| e.to_string())?;
space::open::discard_unowned_team(&team_id);
space::perm::forget(&team_id);
space::cache::forget(&team_id);
space::secrets::forget(&team_id);
Expand Down
14 changes: 11 additions & 3 deletions src-tauri/src/space/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ impl TeamClient {

/// The client for a team this launcher has joined, held to the key kept for it.
pub fn for_team(team_id: &str) -> anyhow::Result<Self> {
let reach = crate::team::reach(team_id)?;
Ok(Self::for_saved_team(team_id, crate::team::reach(team_id)?))
}

/// A shared session can use only the membership that opened it.
pub fn for_team_session(team_id: &str, owner: &str) -> anyhow::Result<Self> {
Ok(Self::for_saved_team(team_id, crate::team::session_reach(team_id, owner)?))
}

fn for_saved_team(team_id: &str, reach: crate::team::Reach) -> Self {
let mut c = TeamClient::reaching(&reach.server, &reach.token, &reach.device_id, team_wire::key_from_text(&reach.key));
c.team_id = Some(team_id.to_string());
// A reaper leaves a lost token to the launcher: it writes nothing of the team's.
c.report_lost = !super::reap::in_reaper();
Ok(c)
c
}

/// The client for the server holding the person's own space for sync. A
Expand Down Expand Up @@ -1543,7 +1551,7 @@ mod tests {
}
}
// The team token, and sync's, are handed out only to the client.
let hands_out = line.contains("team::reach(") || line.contains("sync_reach(");
let hands_out = line.contains("team::reach(") || line.contains("session_reach(") || line.contains("sync_reach(");
if (hands_out && rel != "team.rs") || (rel != "team.rs" && line.contains("fn reach(")) {
bad.push(format!("{rel}:{}: {}", n + 1, line.trim()));
}
Expand Down
14 changes: 10 additions & 4 deletions src-tauri/src/space/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,20 @@ fn close_team_profile(team_id: &str, id: &str) {
fn revoke(team_id: &str, lost: impl Fn(&str, &str) -> bool, tell: &Tell) {
let name = crate::team::link(team_id).ok().flatten().map(|t| t.name);
let Some(saved) = crate::team::revoke(team_id, lost).transpose() else { return };
close_and_wipe_open_team_profiles(team_id);
perm::forget(team_id);
super::cache::forget(team_id);
super::secrets::forget(team_id);
match saved {
Ok(st) => {
super::open::discard_unowned_team(team_id);
tell("space-changed", serde_json::to_value(&st.space).unwrap_or_default());
let name = name.unwrap_or_else(|| "A team".into());
crate::notify_warning(format!("{name} withdrew this launcher's access."));
}
Err(e) => eprintln!("[launcher] team {team_id} withdrew access, and saving that failed: {e:#}"),
Err(e) => {
close_and_wipe_open_team_profiles(team_id);
eprintln!("[launcher] team {team_id} withdrew access, and saving that failed: {e:#}");
}
}
}

Expand All @@ -448,16 +451,19 @@ fn close_and_wipe_open_team_profiles(team_id: &str) {
fn replaced(team_id: &str, lost: impl Fn(&str, &str) -> bool, tell: &Tell) {
let name = crate::team::link(team_id).ok().flatten().map(|t| t.name);
let Some(saved) = crate::team::token_replaced(team_id, lost).transpose() else { return };
close_open_team_profiles(team_id);
perm::forget(team_id);
super::cache::forget(team_id);
match saved {
Ok(st) => {
super::open::close_team_sessions_with_end(team_id, super::open::End::Keep);
tell("space-changed", serde_json::to_value(&st.space).unwrap_or_default());
let name = name.unwrap_or_else(|| "A team".into());
crate::notify_warning(format!("{name} replaced this launcher's invite: paste the new one from the team's admin."));
}
Err(e) => eprintln!("[launcher] team {team_id} replaced this token, and saving that failed: {e:#}"),
Err(e) => {
close_open_team_profiles(team_id);
eprintln!("[launcher] team {team_id} replaced this token, and saving that failed: {e:#}");
}
}
}

Expand Down
Loading