Presence now has constructors for each type variant, and a with_payload builder method (closes #79)
This commit is contained in:
parent
72ddb8b851
commit
512c1d1aae
2 changed files with 43 additions and 0 deletions
|
@ -5,6 +5,8 @@ xxx
|
|||
* Improvements:
|
||||
- muc::user::Item: Added with_ helpers
|
||||
- Correct cargo doc warnings
|
||||
- Presence now has constructors for each variant so you don't have to import presence::Type, where Presence::available represents type None (#79)
|
||||
- Presence::with_payload builds a payload into the presence (#79)
|
||||
* Breaking changes:
|
||||
- Removed the 'serde' feature. Add it directly by using 'jid'.
|
||||
`jid = { version = "*", features = ["serde"] }`.
|
||||
|
|
|
@ -191,6 +191,41 @@ impl Presence {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create a presence without a type, which means available
|
||||
pub fn available() -> Presence {
|
||||
Self::new(Type::None)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Error
|
||||
pub fn error() -> Presence {
|
||||
Self::new(Type::Error)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Probe
|
||||
pub fn probe() -> Presence {
|
||||
Self::new(Type::Probe)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Subscribe
|
||||
pub fn subscribe() -> Presence {
|
||||
Self::new(Type::Subscribe)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Subscribed
|
||||
pub fn subscribed() -> Presence {
|
||||
Self::new(Type::Subscribed)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Unavailable
|
||||
pub fn unavailable() -> Presence {
|
||||
Self::new(Type::Unavailable)
|
||||
}
|
||||
|
||||
/// Builds a presence of type Unsubscribe
|
||||
pub fn unsubscribe() -> Presence {
|
||||
Self::new(Type::Unsubscribe)
|
||||
}
|
||||
|
||||
/// Set the emitter of this presence, this should only be useful for
|
||||
/// servers and components, as clients can only send presences from their
|
||||
/// own resource (which is implicit).
|
||||
|
@ -224,6 +259,12 @@ impl Presence {
|
|||
self
|
||||
}
|
||||
|
||||
/// Set a payload inside this presence.
|
||||
pub fn with_payload<P: PresencePayload>(mut self, payload: P) -> Presence {
|
||||
self.payloads.push(payload.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the payloads of this presence.
|
||||
pub fn with_payloads(mut self, payloads: Vec<Element>) -> Presence {
|
||||
self.payloads = payloads;
|
||||
|
|
Loading…
Reference in a new issue