Features: iq::Bind and iq::Roster #4
Loading…
Reference in a new issue
No description provided.
Delete branch "feature_roster_on_login"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -0,0 +29,4 @@
return {};
}
auto* jid_el = dynamic_cast<const xmlpp::Element*>(jid_node);
You can create a structure that contains jid as an attribute and use automatic generation of serialization and deserialization
I tried, but roster result should has 'jid' attr, while with Serialization with BareJid I got
<NO_NAME username="n" server="s" >
Expected ResultRoster
See how it's done in SomeStruct5 in tests/serialization.cpp
Interesting, looks like last time I did something wrong and got <username="n" server="s"> instead. Will try t use BareJid
Done
@ -0,0 +48,4 @@
using IqBind = Iq<Bind>;
inline auto MakeSetBind() {
return SetBind{.id = "1", .payload = Bind{}};
For what?
@ -126,2 +146,2 @@
}) //
| std::ranges::to<std::unordered_map<std::string_view, std::string_view>>();
auto params = std::views::split(decoded, ',') | std::views::transform([](auto param) {
return std::string_view{param};
Why? It was more readable before.
@ -72,0 +55,4 @@
std::string username;
std::string server;
constexpr operator FullJid() const {
return FullJid{.username = username, .server = server, .resource = ""};
Extra copying if there is an rvalue. Better to forward depending on the type with which it is called.
@ -0,0 +38,4 @@
}
friend constexpr auto operator<<(xmlpp::Element* element, const Roster& roster) {
element->set_attribute("xmlns", Roster::kDefaultNamespace);
std::ranges::for_each(roster.items, [element](const auto& item) {
Why not range based for?
@ -0,0 +51,4 @@
return {.items = item_nodes | std::views::transform([](const xmlpp::Node* node) {
auto item_element = dynamic_cast<const xmlpp::Element*>(node);
if(!item_element) {
throw std::runtime_error("Can't convert xmlpp::Node to xmlpp::Element");
You can create a structure that contains jid as an attribute and use automatic generation of serialization and deserialization
Done
@ -0,0 +70,4 @@
using IqRoster = Iq<Roster>;
inline auto MakeGetRoster(const FullJid& jid) {
return GetRoster{.id = "1", .from = ToString(jid), .payload = Roster{}};
For what?
@ -297,1 +297,4 @@
template <typename T>
concept LengthCalculatable = requires(const T& obj) {
{ obj.length() } -> std::convertible_to<std::size_t>; // Checks if obj has a length() method returning a type convertible to std::size_t
A comment that doesn't explain anything and just repeats the code.
@ -0,0 +10,4 @@
FullJid jid{.username = "test", .server = "server", .resource = "res"}; // NOLINT
auto roster = iq::MakeGetRoster(jid);
roster.payload.items.emplace_back("u1", "s1");
roster.payload.items.emplace_back("u2", "s2");
Why not just throw all the necessary elements through the vector constructor in Roster constructor?
@ -0,0 +22,4 @@
ASSERT_EQ(roster.payload.items.size(), parse_res.payload.items.size());
for(const auto& [idx, expect_el, parsed_el] : std::views::zip(std::views::iota(0), roster.payload.items, parse_res.payload.items)) {
EXPECT_EQ(expect_el, parsed_el) << "Mismatched on idx: " << idx;
// std::cerr << " " << "idx: " << idx << "; expect_el: " << expect_el << "; parsed_el: " << parsed_el << '\n';
Code left in the comment
@ -0,0 +33,4 @@
roster.payload.items.emplace_back("u2", "s2");
roster.payload.items.emplace_back("u3", "s3");
EXPECT_NO_THROW({ std::cerr << "[ ] Roster payload: " << ToString(roster.payload) << '\n'; });
EXPECT_EQ and test content
@ -11,6 +12,8 @@ namespace iq {
template <auto& Name, typename PayloadType>
struct BaseImplWithPayload {
std::string id;
std::optional<std::string> from{};
Why std::string and not a more limited type like Jid ?
Fixed
54b3535ebc
tod88f14a66d
@ -75,0 +95,4 @@
co_return;
}
auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
Maybe we can change namings later
d88f14a66d
to1a9b293dee
1a9b293dee
to604b423d1c
604b423d1c
to30a5e69d14
fbfd37e082
to9b25ed1620
9b25ed1620
to495b58489e
@ -20,2 +24,4 @@
return utils::FieldSetHelper::With<"id", BaseImplWithPayload>(std::forward<Self>(self), std::move(id));
}
template <typename Self>
[[nodiscard]] constexpr auto To(this Self&& self, std::string to) -> std::decay_t<Self> {
Uses std::string for setters even though another type is stored.
@ -53,2 +88,3 @@
}
return {.id = idNode->get_value(), .payload = S::Parse(payload2)};
return {.id = idNode->get_value(),
.from = (from ? std::optional{BareJid::Parse(from->get_value())} : std::nullopt),
Use BareJid::Parse when there might not be a BareJid
@ -0,0 +32,4 @@
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) {
It would be better to move this to a .cpp file to make the header files lighter.
@ -0,0 +73,4 @@
S::Serialize(element, self);
}
constexpr auto RosterItem::Parse(xmlpp::Element* element) -> RosterItem {
return S::Parse<RosterItem>(element);
It would be better to move definitions to a .cpp file to make the header files lighter.
@ -298,0 +302,4 @@
template <typename T>
auto AccumulateFieldLength(const T& obj) -> std::size_t {
std::size_t total_length = 0;
camelCase
@ -0,0 +16,4 @@
auto parse_res = decltype(roster)::Parse(node);
ASSERT_EQ(roster.payload.items.size(), parse_res.payload.items.size());
for(const auto& [idx, expect_el, parsed_el] : std::views::zip(std::views::iota(0), roster.payload.items, parse_res.payload.items)) {
camelCase
495b58489e
toa4e973ca32
@ -7,1 +7,4 @@
#include <larra/stream_error.hpp>
#include <variant>
#include "utempl/utils.hpp"
????
a4e973ca32
tob6c31e8e85
b6c31e8e85
toc52d237dc4