1use std::collections::HashMap;
2
3use crate::ConnectionId;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct DocSearch {
8 pub(crate) phase: DocSearchPhase,
9 pub(crate) pending_connections: Vec<url::Url>,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq)]
13pub enum DocSearchPhase {
14 Loading,
15 Searching(HashMap<ConnectionId, PeerRequestState>),
16 Ready,
17}
18
19impl DocSearch {
20 pub fn phase(&self) -> &DocSearchPhase {
21 &self.phase
22 }
23
24 pub fn pending_connections(&self) -> &[url::Url] {
25 &self.pending_connections
26 }
27
28 pub fn is_currently_unavailable(&self) -> bool {
29 let DocSearchPhase::Searching(peers) = &self.phase else {
30 return false;
31 };
32 if !self.pending_connections.is_empty() {
33 return false;
34 }
35 peers
36 .values()
37 .all(|p| matches!(p, PeerRequestState::Unavailable))
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum PeerRequestState {
44 Requested,
46 Unavailable,
48 Syncing,
50 Available,
52}