summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-01-08 22:31:08 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2023-01-31 21:27:00 +0100
commitc2df0381313ffe5e155b7dc3d6d4c7271a4b73a2 (patch)
tree0f9385be3a08e45045291ed52b692a3579db394d /src/main.cpp
parented40a224e4256867d5f8c9f7c4c3ea998d4b88ce (diff)
Contact name setting and property lookup
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 12f46ac..edf68d7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -465,7 +465,7 @@ void contactList(const vector<string> &)
};
for (const auto & c : h->behavior().lens<SharedState>().lens<Set<Contact>>().get().view(cmp)) {
ostringstream ss;
- ss << "contact-list-item " << c.name();
+ ss << "contact-list-item " << string(c.leastRoot()) << " " << c.name();
if (auto id = c.identity())
if (auto iname = id->name())
ss << " " << *iname;
@@ -474,6 +474,30 @@ void contactList(const vector<string> &)
printLine("contact-list-done");
}
+void contactSetName(const vector<string> & args)
+{
+ auto id = args.at(0);
+ auto name = args.at(1);
+
+ auto cmp = [](const Contact & x, const Contact & y) {
+ return x.data() < y.data();
+ };
+ for (const auto & c : h->behavior().lens<SharedState>().lens<Set<Contact>>().get().view(cmp)) {
+ if (string(c.leastRoot()) == id) {
+ auto nh = h->update([&] (const Stored<LocalState> & loc) {
+ auto st = loc.ref().storage();
+ auto cc = c.customName(st, name);
+ auto contacts = loc->shared<Set<Contact>>();
+ return st.store(loc->shared<Set<Contact>>(contacts.add(st, cc)));
+ });
+ if (nh)
+ *h = *nh;
+ break;
+ }
+ }
+ printLine("contact-set-name-done");
+}
+
vector<Command> commands = {
{ "store", store },
{ "stored-generation", storedGeneration },
@@ -496,6 +520,7 @@ vector<Command> commands = {
{ "contact-accept", contactAccept },
{ "contact-reject", contactReject },
{ "contact-list", contactList },
+ { "contact-set-name", contactSetName },
};
}