mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 12:46:49 +00:00
64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
use std::fmt::Debug;
|
|
|
|
use ruma::{OwnedServerName, OwnedUserId};
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
pub enum Destination {
|
|
Appservice(String),
|
|
Push(OwnedUserId, String), // user and pushkey
|
|
Federation(OwnedServerName),
|
|
}
|
|
|
|
impl Destination {
|
|
#[must_use]
|
|
pub(super) fn kind(&self) -> &'static str {
|
|
match self {
|
|
| Self::Appservice(_) => "appservice",
|
|
| Self::Push(..) => "push",
|
|
| Self::Federation(_) => "federation",
|
|
}
|
|
}
|
|
|
|
/// Gets the prefix for this destination.
|
|
#[must_use]
|
|
pub(super) fn get_prefix(&self) -> Vec<u8> {
|
|
match self {
|
|
| Self::Federation(server) => {
|
|
let len = server.as_bytes().len().saturating_add(1);
|
|
|
|
let mut p = Vec::with_capacity(len);
|
|
p.extend_from_slice(server.as_bytes());
|
|
p.push(0xFF);
|
|
p
|
|
},
|
|
| Self::Appservice(server) => {
|
|
let sigil = b"+";
|
|
let len = sigil.len().saturating_add(server.len()).saturating_add(1);
|
|
|
|
let mut p = Vec::with_capacity(len);
|
|
p.extend_from_slice(sigil);
|
|
p.extend_from_slice(server.as_bytes());
|
|
p.push(0xFF);
|
|
p
|
|
},
|
|
| Self::Push(user, pushkey) => {
|
|
let sigil = b"$";
|
|
let len = sigil
|
|
.len()
|
|
.saturating_add(user.as_bytes().len())
|
|
.saturating_add(1)
|
|
.saturating_add(pushkey.len())
|
|
.saturating_add(1);
|
|
|
|
let mut p = Vec::with_capacity(len);
|
|
p.extend_from_slice(sigil);
|
|
p.extend_from_slice(user.as_bytes());
|
|
p.push(0xFF);
|
|
p.extend_from_slice(pushkey.as_bytes());
|
|
p.push(0xFF);
|
|
p
|
|
},
|
|
}
|
|
}
|
|
}
|