pubnub/dx/presence/event_engine/
invocation.rs1use crate::{
7 core::event_engine::EffectInvocation,
8 lib::core::fmt::{Display, Formatter, Result},
9 presence::event_engine::{PresenceEffect, PresenceEvent, PresenceInput},
10};
11
12#[derive(Debug)]
13pub(crate) enum PresenceEffectInvocation {
14 Heartbeat {
16 input: PresenceInput,
21 },
22
23 Leave {
25 input: PresenceInput,
30 },
31
32 Wait {
34 input: PresenceInput,
39 },
40
41 CancelWait,
43
44 TerminateEventEngine,
46}
47
48impl EffectInvocation for PresenceEffectInvocation {
49 type Effect = PresenceEffect;
50 type Event = PresenceEvent;
51
52 fn id(&self) -> &str {
53 match self {
54 Self::Heartbeat { .. } => "HEARTBEAT",
55 Self::Leave { .. } => "LEAVE",
56 Self::Wait { .. } => "WAIT",
57 Self::CancelWait => "CANCEL_WAIT",
58 Self::TerminateEventEngine => "TERMINATE_EVENT_ENGINE",
59 }
60 }
61
62 fn is_managed(&self) -> bool {
63 matches!(self, Self::Wait { .. })
64 }
65
66 fn is_cancelling(&self) -> bool {
67 matches!(self, Self::CancelWait)
68 }
69
70 fn cancelling_effect(&self, effect: &Self::Effect) -> bool {
71 matches!(effect, PresenceEffect::Wait { .. }) && matches!(self, Self::CancelWait { .. })
72 }
73
74 fn is_terminating(&self) -> bool {
75 matches!(self, Self::TerminateEventEngine)
76 }
77}
78
79impl Display for PresenceEffectInvocation {
80 fn fmt(&self, f: &mut Formatter<'_>) -> Result {
81 match self {
82 Self::Heartbeat { .. } => write!(f, "HEARTBEAT"),
83 Self::Leave { .. } => write!(f, "LEAVE"),
84 Self::Wait { .. } => write!(f, "WAIT"),
85 Self::CancelWait => write!(f, "CANCEL_WAIT"),
86 Self::TerminateEventEngine => write!(f, "TERMINATE_EVENT_ENGINE"),
87 }
88 }
89}