From c77614992ddccd12870434f564dacfbbff2e5858 Mon Sep 17 00:00:00 2001 From: Ivan-lis Date: Mon, 14 Oct 2024 08:38:22 +0000 Subject: [PATCH] temp1 --- library/include/larra/client/client.hpp | 5 ++ library/include/larra/roster.hpp | 76 +++++++++++++++++++++++++ library/query.hpp | 0 3 files changed, 81 insertions(+) create mode 100644 library/include/larra/roster.hpp create mode 100644 library/query.hpp diff --git a/library/include/larra/client/client.hpp b/library/include/larra/client/client.hpp index 5ee658c..b3ccddd 100644 --- a/library/include/larra/client/client.hpp +++ b/library/include/larra/client/client.hpp @@ -21,6 +21,7 @@ #include #include #include +#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 { + Iq> + this->Send(); + } private: bool active = true; diff --git a/library/include/larra/roster.hpp b/library/include/larra/roster.hpp new file mode 100644 index 0000000..06816a1 --- /dev/null +++ b/library/include/larra/roster.hpp @@ -0,0 +1,76 @@ +#pragma once +#include + +#include +#include +#include +/* +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 { + 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 { + 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; + +struct Initial { + static constexpr auto kDefaultName = "presence"; + FullJid from; + BareJid to; + template + [[nodiscard]] constexpr auto From(this Self&& self, BareJid value) -> std::decay_t { + return utils::FieldSetHelper::With<"from", Initial>(std::forward(self), std::move(value)); + } + template + [[nodiscard]] constexpr auto To(this Self&& self, BareJid value) -> std::decay_t { + return utils::FieldSetHelper::With<"to", Initial>(std::forward(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 +*/ \ No newline at end of file diff --git a/library/query.hpp b/library/query.hpp new file mode 100644 index 0000000..e69de29