diff --git a/src/bridge.cpp b/src/bridge.cpp index 05e80bb..d6f940b 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -58,13 +58,23 @@ Bridge::Bridge( ) : _cr(cr), _rmm(rmm), _conf(conf) { _rmm.subscribe(this, enumType::message_construct); + if (!_conf.has_bool("Bridge", "username_angle_brackets")) { + _conf.set("Bridge", "username_angle_brackets", true); + } + if (!_conf.has_bool("Bridge", "username_id")) { + _conf.set("Bridge", "username_id", true); + } + if (!_conf.has_bool("Bridge", "username_colon")) { + _conf.set("Bridge", "username_colon", true); + } + // load synced contacts (bridged groups) std::map tmp_name_to_id; for (const auto [contact_id, vgroup_str] : _conf.entries_string("Bridge", "contact_to_vgroup")) { const auto tmp_vgroup_str = std::string{vgroup_str.start, vgroup_str.start+vgroup_str.extend}; if (!tmp_name_to_id.count(tmp_vgroup_str)) { tmp_name_to_id[tmp_vgroup_str] = _vgroups.size(); - _vgroups.emplace_back();; + _vgroups.emplace_back().vg_name = tmp_vgroup_str; } auto& v_group = _vgroups.at(tmp_name_to_id.at(tmp_vgroup_str)); @@ -148,25 +158,42 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) { const auto& message_text = e.e.get().text; const bool is_action = e.e.all_of(); + const bool use_angle_brackets = _conf.get_bool("Bridge", "username_angle_brackets", vgroup.vg_name).value(); + std::string from_str; + if (use_angle_brackets) { + from_str += "<"; + } + if (_cr.all_of(contact_from)) { const auto& name = _cr.get(contact_from).name; if (name.empty()) { - from_str += "(contact_from)) { - // copy - auto id = _cr.get(contact_from).data; - id.resize(3); - from_str += "#" + bin2hex(id); + if (_conf.get_bool("Bridge", "username_id", vgroup.vg_name).value()) { + if (_cr.all_of(contact_from)) { + // copy + auto id = _cr.get(contact_from).data; + id.resize(3); // TODO:make size configurable + + // TODO: make seperator configurable + from_str += "#" + bin2hex(id); + } } - from_str += "> "; + if (use_angle_brackets) { + from_str += ">"; + } + + if (_conf.get_bool("Bridge", "username_colon", vgroup.vg_name).value()) { + from_str += ":"; + } + + from_str += " "; // for each c in vg not c... for (const auto& other_vc : vgroup.contacts) { diff --git a/src/bridge.hpp b/src/bridge.hpp index 286f17f..a086811 100644 --- a/src/bridge.hpp +++ b/src/bridge.hpp @@ -22,7 +22,8 @@ class Bridge : public RegistryMessageModelEventI { }; std::vector contacts; - // metadata/settings? + std::string vg_name; + // TODO: cache settings here? }; std::vector _vgroups; std::map _c_to_vg;