This commit is contained in:
Ivan-lis 2024-10-14 08:38:22 +00:00
parent a98f2e8552
commit c77614992d
3 changed files with 81 additions and 0 deletions

View file

@ -21,6 +21,7 @@
#include <larra/user_account.hpp>
#include <larra/xml_stream.hpp>
#include <ranges>
#include "larra/iq.hpp"
namespace larra::xmpp {
constexpr auto kDefaultXmppPort = 5222;
@ -71,6 +72,10 @@ struct Client {
[[nodiscard]] constexpr auto Jid() const -> const BareJid& {
return this->jid;
}
[[nodiscard]] auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
Iq<iq::Get<Roster>>
this->Send();
}
private:
bool active = true;

View file

@ -0,0 +1,76 @@
#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 constexpr auto operator<<(xmlpp::Element* element, const Unavailable&) {
element->set_attribute("type", "unavailable");
}
[[nodiscard]] static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<Unavailable> {
if(auto type = element->get_attribute("type")) {
if(type->get_value() == "unavailable") {
return Unavailable{};
};
}
return std::nullopt;
}
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Unavailable {
return Unavailable::TryParse(element).value();
}
};
struct Available {
static constexpr auto kDefaultName = "presence";
friend constexpr auto operator<<(xmlpp::Element*, const Available&) {
}
[[nodiscard]] static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<Available> {
return Unavailable::TryParse(element).has_value() ? std::nullopt : std::optional{Available{}};
}
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Available {
return Available::TryParse(element).value();
}
};
} // 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 constexpr auto operator<<(xmlpp::Element* element, const Initial& presence) {
element->set_attribute("from", ToString(presence.from));
element->set_attribute("to", ToString(presence.to));
}
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Initial {
auto from = element->get_attribute("from");
if(!from) {
throw std::runtime_error("Not found attribute from for Parse presence::Initial");
}
auto to = element->get_attribute("to");
if(!to) {
throw std::runtime_error("Not found attribute to for Parse presence::Initial");
}
return {.from = FullJid::Parse(from->get_value()), .to = BareJid::Parse(to->get_value())};
}
};
} // namespace larra::xmpp
*/

0
library/query.hpp Normal file
View file