1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use_prelude!();
use std::sync::{Arc, Weak};

use super::{v2::V2Presence, v3::PresenceGraph};

/// A token returned by `Presence::observe`. Retain this object to continue
/// receiving callback updates.
pub struct PresenceObserver {
    _ctx: Arc<PresenceObserverCtx>,
}
pub(crate) type WeakPresenceObserver = Weak<PresenceObserverCtx>;

impl PresenceObserver {
    pub(crate) fn new(_ctx: Arc<PresenceObserverCtx>) -> Self {
        Self { _ctx }
    }
}

impl Observer for PresenceObserver {}

pub(crate) struct PresenceObserverCtx {
    pub(crate) on_presence: Box<dyn Fn(&PresenceGraph) + Send + Sync + 'static>,
}

impl PresenceObserverCtx {
    pub(crate) fn new(on_presence: Box<dyn Fn(&PresenceGraph) + Send + Sync + 'static>) -> Self {
        Self { on_presence }
    }
}

// A token returned by `observe_peers`. Retain this object to continue
/// receiving callback updates.
pub struct PeersObserver {
    _context: Arc<PeersObserverCtx>,
}

impl PeersObserver {
    pub(crate) fn new(context: Arc<PeersObserverCtx>) -> Self {
        Self { _context: context }
    }
}

impl Observer for PeersObserver {}

pub(crate) struct PeersObserverCtx {
    pub(crate) on_presence: Box<dyn Fn(V2Presence) + Send + Sync + 'static>,
}

impl PeersObserverCtx {
    pub(crate) fn new(on_presence: Box<dyn Fn(V2Presence) + Send + Sync + 'static>) -> Self {
        Self { on_presence }
    }
}