larra/library/include/larra/presence.hpp

67 lines
2.5 KiB
C++

#pragma once
#include <libxml++/libxml++.h>
#include <larra/jid.hpp>
#include <optional>
#include <variant>
namespace larra::xmpp::presence {
namespace c2s {
struct Unavailable {
static constexpr auto kDefaultName = "presence";
friend auto operator<<(xmlpp::Element* element, const Unavailable&) -> void;
[[nodiscard]] static auto TryParse(xmlpp::Element* element) -> std::optional<Unavailable>;
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> Unavailable;
};
struct Available {
static constexpr auto kDefaultName = "presence";
friend auto operator<<(xmlpp::Element*, const Available&) -> void;
[[nodiscard]] static auto TryParse(xmlpp::Element* element) -> std::optional<Available>;
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> Available;
};
} // namespace c2s
using ClientToServer = std::variant<c2s::Unavailable, c2s::Available>;
struct Initial {
static constexpr auto kDefaultName = "presence";
FullJid from;
BareJid to;
template <typename Self>
[[nodiscard]] constexpr auto From(this Self&& self, BareJid value) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"from", Initial>(std::forward<Self>(self), std::move(value));
}
template <typename Self>
[[nodiscard]] constexpr auto To(this Self&& self, BareJid value) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"to", Initial>(std::forward<Self>(self), std::move(value));
}
friend auto operator<<(xmlpp::Element* element, const Initial& presence) -> void;
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> Initial;
};
struct Probe {
static constexpr auto kDefaultName = "presence";
BareJid from;
BareJid to;
std::string id;
template <typename Self>
[[nodiscard]] constexpr auto From(this Self&& self, BareJid value) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"from", Probe>(std::forward<Self>(self), std::move(value));
}
template <typename Self>
[[nodiscard]] constexpr auto To(this Self&& self, BareJid value) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"to", Probe>(std::forward<Self>(self), std::move(value));
}
template <typename Self>
[[nodiscard]] constexpr auto Id(this Self&& self, std::string value) -> std::decay_t<Self> {
return utils::FieldSetHelper::With<"id", Probe>(std::forward<Self>(self), std::move(value));
}
friend auto operator<<(xmlpp::Element* element, const Probe& presence) -> void;
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> Probe;
};
} // namespace larra::xmpp::presence