port to contact4

This commit is contained in:
Green Sky 2025-03-10 20:40:25 +01:00
parent e77e57fa78
commit 9e42508428
No known key found for this signature in database
GPG Key ID: DBE05085D874AB4A
12 changed files with 57 additions and 52 deletions

View File

@ -33,6 +33,7 @@ target_compile_features(totato PUBLIC cxx_std_17)
target_link_libraries(totato PUBLIC target_link_libraries(totato PUBLIC
solanaceae_util solanaceae_util
solanaceae_contact solanaceae_contact
solanaceae_contact_impl
solanaceae_message3 solanaceae_message3
solanaceae_plugin solanaceae_plugin

View File

@ -1,6 +1,6 @@
#include "./managment_commands.hpp" #include "./managment_commands.hpp"
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
#include <solanaceae/message3/message_command_dispatcher.hpp> #include <solanaceae/message3/message_command_dispatcher.hpp>
@ -13,7 +13,7 @@
void registerConfigCommands( void registerConfigCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
) { ) {
mcd.registerCommand( mcd.registerCommand(

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/fwd.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
// fwd // fwd
@ -10,7 +10,7 @@ struct ConfigModelI;
void registerConfigCommands( void registerConfigCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
); );

View File

@ -1,18 +1,19 @@
#include "./managment_commands.hpp" #include "./managment_commands.hpp"
#include <random>
#include <solanaceae/contact/contact_model3.hpp>
//#include <solanaceae/util/config_model.hpp> //#include <solanaceae/util/config_model.hpp>
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/message3/message_command_dispatcher.hpp> #include <solanaceae/message3/message_command_dispatcher.hpp>
#include <solanaceae/message3/components.hpp>
//#include <solanaceae/contact/components.hpp> //#include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp>
#include <random>
void registerFunCommands( void registerFunCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
) { ) {
mcd.registerCommand( mcd.registerCommand(

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
// fwd // fwd
@ -10,7 +9,7 @@ struct ConfigModelI;
void registerFunCommands( void registerFunCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
); );

View File

@ -1,6 +1,6 @@
#include <solanaceae/object_store/object_store.hpp> #include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/util/simple_config_model.hpp> #include <solanaceae/util/simple_config_model.hpp>
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/contact_store_impl.hpp>
#include <solanaceae/message3/registry_message_model_impl.hpp> #include <solanaceae/message3/registry_message_model_impl.hpp>
#include <solanaceae/message3/message_time_sort.hpp> #include <solanaceae/message3/message_time_sort.hpp>
#include <solanaceae/plugin/plugin_manager.hpp> #include <solanaceae/plugin/plugin_manager.hpp>
@ -185,11 +185,11 @@ int main(int argc, char** argv) {
// TODO: name // TODO: name
} }
Contact3Registry cr; ContactStore4Impl cs;
RegistryMessageModelImpl rmm{cr}; RegistryMessageModelImpl rmm{cs};
MessageTimeSort mts{rmm}; MessageTimeSort mts{rmm};
MessageCleanser mc{cr, rmm, conf}; MessageCleanser mc{cs, rmm, conf};
MessageCommandDispatcher mcd{cr, rmm, conf}; MessageCommandDispatcher mcd{cs, rmm, conf};
{ // setup basic commands for bot { // setup basic commands for bot
mcd.registerCommand( mcd.registerCommand(
@ -223,9 +223,9 @@ int main(int argc, char** argv) {
ToxPrivateImpl tpi{tc.getTox()}; ToxPrivateImpl tpi{tc.getTox()};
AutoDirty ad{tc}; AutoDirty ad{tc};
ToxContactModel2 tcm{cr, tc, tc}; ToxContactModel2 tcm{cs, tc, tc};
ToxMessageManager tmm{rmm, cr, tcm, tc, tc}; ToxMessageManager tmm{rmm, cs, tcm, tc, tc};
ToxTransferManager ttm{rmm, cr, tcm, tc, tc, os}; ToxTransferManager ttm{rmm, cs, tcm, tc, tc, os};
PluginManager pm; PluginManager pm;
@ -233,7 +233,7 @@ int main(int argc, char** argv) {
g_provideInstance<ObjectStore2>("ObjectStore2", "host", &os); g_provideInstance<ObjectStore2>("ObjectStore2", "host", &os);
g_provideInstance<ConfigModelI>("ConfigModelI", "host", &conf); g_provideInstance<ConfigModelI>("ConfigModelI", "host", &conf);
g_provideInstance<Contact3Registry>("Contact3Registry", "1", "host", &cr); g_provideInstance<ContactStore4I>("ContactStore4I", "host", &cs);
g_provideInstance<RegistryMessageModelI>("RegistryMessageModelI", "host", &rmm); g_provideInstance<RegistryMessageModelI>("RegistryMessageModelI", "host", &rmm);
g_provideInstance<MessageCommandDispatcher>("MessageCommandDispatcher", "host", &mcd); g_provideInstance<MessageCommandDispatcher>("MessageCommandDispatcher", "host", &mcd);
@ -267,11 +267,11 @@ int main(int argc, char** argv) {
} }
} }
registerManagementCommands(mcd, conf, cr, rmm); registerManagementCommands(mcd, conf, cs, rmm);
// TODO: finish impl // TODO: finish impl
//registerConfigCommands(mcd, conf, cr, rmm); //registerConfigCommands(mcd, conf, cs, rmm);
registerToxCommands(mcd, conf, cr, rmm, tc, tpi); registerToxCommands(mcd, conf, cs, rmm, tc, tpi);
registerFunCommands(mcd, conf, cr, rmm); registerFunCommands(mcd, conf, cs, rmm);
mcd.registerCommand( mcd.registerCommand(
"totato", "", "totato", "",

View File

@ -1,6 +1,6 @@
#include "./managment_commands.hpp" #include "./managment_commands.hpp"
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
#include <solanaceae/message3/message_command_dispatcher.hpp> #include <solanaceae/message3/message_command_dispatcher.hpp>
@ -12,25 +12,22 @@
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
static std::optional<Contact3> getContactFromIDStr( static std::optional<Contact4> getContactFromIDStr(
Contact3Registry& cr, ContactStore4I& cs,
std::string_view id_str std::string_view id_str
) { ) {
const std::vector<uint8_t> id = hex2bin(std::string{id_str}); const std::vector<uint8_t> id = hex2bin(id_str);
const auto view = cr.view<Contact::Components::ID>(); const auto found_contact = cs.getOneContactByID(ByteSpan{id});
const auto found_contact = std::find_if(view.begin(), view.end(), [&id, &view](const Contact3 c) -> bool {
return view.get<Contact::Components::ID>(c).data == id;
});
if (found_contact != view.end()) { if (static_cast<bool>(found_contact)) {
return *found_contact; return found_contact;
} else { } else {
return std::nullopt; return std::nullopt;
} }
} }
static std::string getStatusFromContact( static std::string getStatusFromContact(
Contact3Handle c ContactHandle4 c
) { ) {
std::string status_str; std::string status_str;
@ -53,7 +50,7 @@ static std::string getStatusFromContact(
bool handleContactAddToGroup( bool handleContactAddToGroup(
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
std::string_view params, std::string_view params,
@ -73,7 +70,7 @@ bool handleContactAddToGroup(
return true; return true;
} }
const auto target_opt = getContactFromIDStr(cr, params); const auto target_opt = getContactFromIDStr(cs, params);
if (!target_opt.has_value()) { if (!target_opt.has_value()) {
rmm.sendText( rmm.sendText(
contact_from, contact_from,
@ -99,7 +96,7 @@ bool handleContactAddToGroup(
reply += "' to the "; reply += "' to the ";
reply += group; reply += group;
reply += "s.\n"; reply += "s.\n";
reply += getStatusFromContact(Contact3Handle{cr, target_opt.value()}); reply += getStatusFromContact(cs.contactHandle(target_opt.value()));
rmm.sendText( rmm.sendText(
contact_from, contact_from,
@ -112,14 +109,14 @@ bool handleContactAddToGroup(
void registerManagementCommands( void registerManagementCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
) { ) {
mcd.registerCommand( mcd.registerCommand(
"Management", "manage", "Management", "manage",
"admin-add", "admin-add",
[&](std::string_view params, Message3Handle m) -> bool { [&](std::string_view params, Message3Handle m) -> bool {
return handleContactAddToGroup(conf, cr, rmm, params, m, "admin"); return handleContactAddToGroup(conf, cs, rmm, params, m, "admin");
}, },
"Add an admin by ID.", "Add an admin by ID.",
MessageCommandDispatcher::Perms::ADMIN MessageCommandDispatcher::Perms::ADMIN
@ -129,7 +126,7 @@ void registerManagementCommands(
"Management", "manage", "Management", "manage",
"mod-add", "mod-add",
[&](std::string_view params, Message3Handle m) -> bool { [&](std::string_view params, Message3Handle m) -> bool {
return handleContactAddToGroup(conf, cr, rmm, params, m, "moderator"); return handleContactAddToGroup(conf, cs, rmm, params, m, "moderator");
}, },
"Add a moderator by ID.", "Add a moderator by ID.",
MessageCommandDispatcher::Perms::ADMIN MessageCommandDispatcher::Perms::ADMIN

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/fwd.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
// fwd // fwd
@ -10,7 +10,7 @@ struct ConfigModelI;
void registerManagementCommands( void registerManagementCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm RegistryMessageModelI& rmm
); );

View File

@ -1,5 +1,6 @@
#include "./message_cleanser.hpp" #include "./message_cleanser.hpp"
#include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/contact/components.hpp> #include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp> #include <solanaceae/message3/components.hpp>
#include <solanaceae/util/utils.hpp> #include <solanaceae/util/utils.hpp>
@ -9,10 +10,10 @@
#include <cstdint> #include <cstdint>
MessageCleanser::MessageCleanser( MessageCleanser::MessageCleanser(
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ConfigModelI& conf ConfigModelI& conf
) : _cr(cr), _rmm(rmm), _conf(conf) { ) : _cs(cs), _rmm(rmm), _conf(conf) {
if (!_conf.has_int("MessageCleanser", "old_age_minutes")) { if (!_conf.has_int("MessageCleanser", "old_age_minutes")) {
_conf.set("MessageCleanser", "old_age_minutes", int64_t(_old_age_default)); _conf.set("MessageCleanser", "old_age_minutes", int64_t(_old_age_default));
} }
@ -30,15 +31,17 @@ float MessageCleanser::iterate(float time_delta) {
uint64_t now_ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); uint64_t now_ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
const auto& cr = _cs.registry();
// TODO: iterate rmm directly // TODO: iterate rmm directly
//_rmm.get(); //_rmm.get();
// workaround by iterating contacts // workaround by iterating contacts
for (const auto& c : _cr.view<Contact::Components::TagBig>()) { for (const auto& c : cr.view<Contact::Components::TagBig>()) {
if (auto* reg = _rmm.get(c); reg != nullptr) { if (auto* reg = _rmm.get(c); reg != nullptr) {
float old_age {0.f}; float old_age {0.f};
{ // old age from conf { // old age from conf
// TODO: find some way to extract this (maybe map into contact reg?) // TODO: find some way to extract this (maybe map into contact reg?)
if (const auto* id_comp = _cr.try_get<Contact::Components::ID>(c); id_comp != nullptr) { if (const auto* id_comp = cr.try_get<Contact::Components::ID>(c); id_comp != nullptr) {
const auto id_hex = bin2hex(id_comp->data); const auto id_hex = bin2hex(id_comp->data);
old_age = _conf.get_int("MessageCleanser", "old_age_minutes", id_hex).value_or(_old_age_default); old_age = _conf.get_int("MessageCleanser", "old_age_minutes", id_hex).value_or(_old_age_default);
} else { } else {

View File

@ -4,7 +4,7 @@
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
class MessageCleanser { class MessageCleanser {
Contact3Registry& _cr; ContactStore4I& _cs;
RegistryMessageModelI& _rmm; RegistryMessageModelI& _rmm;
ConfigModelI& _conf; ConfigModelI& _conf;
@ -15,7 +15,7 @@ class MessageCleanser {
public: public:
MessageCleanser( MessageCleanser(
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ConfigModelI& conf ConfigModelI& conf
); );

View File

@ -1,6 +1,6 @@
#include "./tox_commands.hpp" #include "./tox_commands.hpp"
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/contact_store_i.hpp>
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
#include <solanaceae/util/utils.hpp> #include <solanaceae/util/utils.hpp>
#include <solanaceae/toxcore/tox_interface.hpp> #include <solanaceae/toxcore/tox_interface.hpp>
@ -17,7 +17,7 @@
void registerToxCommands( void registerToxCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ToxI& t, ToxI& t,
ToxPrivateI& tp ToxPrivateI& tp
@ -43,6 +43,8 @@ void registerToxCommands(
reply += "\ndht-closenum-announce-capable:"; reply += "\ndht-closenum-announce-capable:";
reply += std::to_string(tp.toxDHTGetNumCloselistAnnounceCapable()); reply += std::to_string(tp.toxDHTGetNumCloselistAnnounceCapable());
const auto& cr = cs.registry();
if (cr.all_of<Contact::Components::ToxFriendEphemeral>(contact_from)) { if (cr.all_of<Contact::Components::ToxFriendEphemeral>(contact_from)) {
const auto con_opt = t.toxFriendGetConnectionStatus(cr.get<Contact::Components::ToxFriendEphemeral>(contact_from).friend_number); const auto con_opt = t.toxFriendGetConnectionStatus(cr.get<Contact::Components::ToxFriendEphemeral>(contact_from).friend_number);
if (!con_opt.has_value() || con_opt.value() == Tox_Connection::TOX_CONNECTION_NONE) { if (!con_opt.has_value() || con_opt.value() == Tox_Connection::TOX_CONNECTION_NONE) {
@ -174,6 +176,8 @@ void registerToxCommands(
return true; return true;
} }
const auto& cr = cs.registry();
// get current group // get current group
if (!cr.all_of<Contact::Components::Parent>(contact_from)) { if (!cr.all_of<Contact::Components::Parent>(contact_from)) {
rmm.sendText( rmm.sendText(

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/fwd.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
// fwd // fwd
@ -12,7 +12,7 @@ struct ToxPrivateI;
void registerToxCommands( void registerToxCommands(
MessageCommandDispatcher& mcd, MessageCommandDispatcher& mcd,
ConfigModelI& conf, ConfigModelI& conf,
Contact3Registry& cr, ContactStore4I& cs,
RegistryMessageModelI& rmm, RegistryMessageModelI& rmm,
ToxI& t, ToxI& t,
ToxPrivateI& tp ToxPrivateI& tp