Ivan-lis
c52d237dc4
All checks were successful
PR Check / on-push-commit-check (push) Successful in 13m52s
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
#pragma once
|
|
#include <libxml++/libxml++.h>
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <larra/iq.hpp>
|
|
#include <larra/jid.hpp>
|
|
#include <larra/utils.hpp>
|
|
#include <ranges>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace larra::xmpp::iq {
|
|
|
|
struct RosterItem {
|
|
BareJid jid;
|
|
friend constexpr auto ToString(const RosterItem& item) {
|
|
return ToString(item.jid);
|
|
}
|
|
constexpr auto operator==(const RosterItem&) const -> bool = default;
|
|
friend auto operator<<(xmlpp::Element* element, const RosterItem& item) -> void;
|
|
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> RosterItem;
|
|
};
|
|
|
|
struct Roster {
|
|
static constexpr auto kDefaultName = "query";
|
|
static constexpr auto kDefaultNamespace = "jabber:iq:roster";
|
|
|
|
std::vector<RosterItem> items;
|
|
|
|
friend auto ToString(const Roster& roster) -> std::string {
|
|
static constexpr std::string_view prefix = "Roster: [\n\t";
|
|
static constexpr std::string_view suffix = "]";
|
|
// \n\r\t
|
|
std::size_t total_length = std::ranges::fold_left(roster.items | std::views::transform([](const auto& el) {
|
|
return larra::xmpp::utils::AccumulateFieldLength(el.jid) + 3;
|
|
}),
|
|
prefix.length() + suffix.length(),
|
|
std::plus<>{});
|
|
|
|
std::string s;
|
|
s.resize(total_length);
|
|
s = prefix;
|
|
for(const auto& el : roster.items) {
|
|
s += ToString(el);
|
|
s += "\n\t";
|
|
}
|
|
return s += suffix;
|
|
}
|
|
friend auto operator<<(xmlpp::Element* element, const Roster& roster) -> void;
|
|
[[nodiscard]] static auto Parse(xmlpp::Element* element) -> Roster;
|
|
};
|
|
|
|
using GetRoster = Get<Roster>;
|
|
using ResultRoster = Result<Roster>;
|
|
|
|
} // namespace larra::xmpp::iq
|