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
54
55
56
57
58
59
60
//! Types for the *m.presence* event.

use ruma_identifiers::{EventId, UserId};

event! {
    /// Informs the client of a user's presence state change.
    pub struct PresenceEvent(PresenceEventContent) {
        /// The unique identifier for the event.
        pub event_id: EventId
    }
}

/// The payload of a `PresenceEvent`.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PresenceEventContent {
    /// The current avatar URL for this user.
    #[serde(skip_serializing_if="Option::is_none")]
    pub avatar_url: Option<String>,

    /// Whether or not the user is currently active.
    pub currently_active: bool,

    /// The current display name for this user.
    #[serde(skip_serializing_if="Option::is_none")]
    pub displayname: Option<String>,

    /// The last time since this used performed some action, in milliseconds.
    #[serde(skip_serializing_if="Option::is_none")]
    pub last_active_ago: Option<u64>,

    /// The presence state for this user.
    pub presence: PresenceState,

    /// The unique identifier for the user associated with this event.
    pub user_id: UserId,
}

/// A description of a user's connectivity and availability for chat.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum PresenceState {
    /// Disconnected from the service.
    #[serde(rename="offline")]
    Offline,

    /// Connected to the service.
    #[serde(rename="online")]
    Online,

    /// Connected to the service but not available for chat.
    #[serde(rename="unavailable")]
    Unavailable,
}

impl_enum! {
    PresenceState {
        Offline => "offline",
        Online => "online",
        Unavailable => "unavailable",
    }
}