Only save the logs if recordHistory global config option is true
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
<field name="owner" type="string" length="3071"/>
|
<field name="owner" type="string" length="3071"/>
|
||||||
|
|
||||||
<field name="maxHistoryLength" type="integer" default="20"/>
|
<field name="maxHistoryLength" type="integer" default="20"/>
|
||||||
|
<field name="recordHistory" type="boolean" default="true"/>
|
||||||
</object>
|
</object>
|
||||||
|
|
||||||
<object name="IrcServerOptions">
|
<object name="IrcServerOptions">
|
||||||
@@ -25,7 +26,6 @@
|
|||||||
<field name="encodingIn" type="string" default="ISO-8859-1"/>
|
<field name="encodingIn" type="string" default="ISO-8859-1"/>
|
||||||
|
|
||||||
<field name="maxHistoryLength" type="integer" default="20"/>
|
<field name="maxHistoryLength" type="integer" default="20"/>
|
||||||
|
|
||||||
<index unique="true">
|
<index unique="true">
|
||||||
<indexfield name="owner"/>
|
<indexfield name="owner"/>
|
||||||
<indexfield name="server"/>
|
<indexfield name="server"/>
|
||||||
|
|||||||
@@ -294,6 +294,13 @@ messages to other users. This means that the order of the messages
|
|||||||
displayed in your XMPP client may not be the same than the order on other
|
displayed in your XMPP client may not be the same than the order on other
|
||||||
IRC users’.
|
IRC users’.
|
||||||
|
|
||||||
|
History
|
||||||
|
-------
|
||||||
|
|
||||||
|
Public channel messages are saved into the database, unless the
|
||||||
|
`record_history` option is set to false for that user
|
||||||
|
`Ad-hoc commands`).
|
||||||
|
|
||||||
List channels
|
List channels
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|||||||
+13
-2
@@ -32,6 +32,10 @@ Bridge::Bridge(const std::string& user_jid, BiboumiComponent& xmpp, std::shared_
|
|||||||
xmpp(xmpp),
|
xmpp(xmpp),
|
||||||
poller(poller)
|
poller(poller)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_DATABASE
|
||||||
|
const auto options = Database::get_global_options(this->user_jid);
|
||||||
|
this->set_record_history(options.recordHistory.value());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,6 +245,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
|
|||||||
|
|
||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
const auto xmpp_body = this->make_xmpp_body(line);
|
const auto xmpp_body = this->make_xmpp_body(line);
|
||||||
|
if (this->record_history)
|
||||||
Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
|
Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
|
||||||
std::get<0>(xmpp_body), irc->get_own_nick());
|
std::get<0>(xmpp_body), irc->get_own_nick());
|
||||||
#endif
|
#endif
|
||||||
@@ -616,7 +621,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
|
|||||||
{
|
{
|
||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
const auto xmpp_body = this->make_xmpp_body(body, encoding);
|
const auto xmpp_body = this->make_xmpp_body(body, encoding);
|
||||||
if (!nick.empty())
|
if (!nick.empty() && this->record_history)
|
||||||
Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
|
Database::store_muc_message(this->get_bare_jid(), iid, std::chrono::system_clock::now(),
|
||||||
std::get<0>(xmpp_body), nick);
|
std::get<0>(xmpp_body), nick);
|
||||||
#endif
|
#endif
|
||||||
@@ -971,7 +976,6 @@ void Bridge::generate_channel_join_for_resource(const Iid& iid, const std::strin
|
|||||||
{
|
{
|
||||||
if (user->nick != self->nick)
|
if (user->nick != self->nick)
|
||||||
{
|
{
|
||||||
log_debug(user->nick);
|
|
||||||
this->send_user_join(iid.get_server(), iid.get_encoded_local(),
|
this->send_user_join(iid.get_server(), iid.get_encoded_local(),
|
||||||
user.get(), user->get_most_significant_mode(irc->get_sorted_user_modes()),
|
user.get(), user->get_most_significant_mode(irc->get_sorted_user_modes()),
|
||||||
false, resource);
|
false, resource);
|
||||||
@@ -982,3 +986,10 @@ void Bridge::generate_channel_join_for_resource(const Iid& iid, const std::strin
|
|||||||
true, resource);
|
true, resource);
|
||||||
this->send_topic(iid.get_server(), iid.get_encoded_local(), channel->topic, channel->topic_author, resource);
|
this->send_topic(iid.get_server(), iid.get_encoded_local(), channel->topic, channel->topic_author, resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DATABASE
|
||||||
|
void Bridge::set_record_history(const bool val)
|
||||||
|
{
|
||||||
|
this->record_history = val;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <biboumi.h>
|
||||||
|
|
||||||
class BiboumiComponent;
|
class BiboumiComponent;
|
||||||
class Poller;
|
class Poller;
|
||||||
|
|
||||||
@@ -215,6 +217,9 @@ public:
|
|||||||
void trigger_on_irc_message(const std::string& irc_hostname, const IrcMessage& message);
|
void trigger_on_irc_message(const std::string& irc_hostname, const IrcMessage& message);
|
||||||
std::unordered_map<std::string, std::shared_ptr<IrcClient>>& get_irc_clients();
|
std::unordered_map<std::string, std::shared_ptr<IrcClient>>& get_irc_clients();
|
||||||
std::set<char> get_chantypes(const std::string& hostname) const;
|
std::set<char> get_chantypes(const std::string& hostname) const;
|
||||||
|
#ifdef USE_DATABASE
|
||||||
|
void set_record_history(const bool val);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@@ -295,6 +300,9 @@ private:
|
|||||||
* TODO: send message history
|
* TODO: send message history
|
||||||
*/
|
*/
|
||||||
void generate_channel_join_for_resource(const Iid& iid, const std::string& resource);
|
void generate_channel_join_for_resource(const Iid& iid, const std::string& resource);
|
||||||
|
#ifdef USE_DATABASE
|
||||||
|
bool record_history { true };
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IRCNotConnected: public std::exception
|
struct IRCNotConnected: public std::exception
|
||||||
|
|||||||
@@ -135,16 +135,32 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman
|
|||||||
max_histo_length["label"] = "Max history length";
|
max_histo_length["label"] = "Max history length";
|
||||||
max_histo_length["desc"] = "The maximum number of lines in the history that the server sends when joining a channel";
|
max_histo_length["desc"] = "The maximum number of lines in the history that the server sends when joining a channel";
|
||||||
|
|
||||||
XmlNode max_histo_length_value("value");
|
XmlNode value("value");
|
||||||
max_histo_length_value.set_inner(std::to_string(options.maxHistoryLength.value()));
|
value.set_inner(std::to_string(options.maxHistoryLength.value()));
|
||||||
max_histo_length.add_child(std::move(max_histo_length_value));
|
max_histo_length.add_child(std::move(value));
|
||||||
x.add_child(std::move(max_histo_length));
|
x.add_child(std::move(max_histo_length));
|
||||||
|
|
||||||
|
XmlNode record_history("field");
|
||||||
|
record_history["var"] = "record_history";
|
||||||
|
record_history["type"] = "boolean";
|
||||||
|
record_history["label"] = "Record history";
|
||||||
|
record_history["desc"] = "Whether to save the messages into the database, or not";
|
||||||
|
|
||||||
|
value.set_name("value");
|
||||||
|
if (options.recordHistory.value())
|
||||||
|
value.set_inner("true");
|
||||||
|
else
|
||||||
|
value.set_inner("false");
|
||||||
|
record_history.add_child(std::move(value));
|
||||||
|
x.add_child(std::move(record_history));
|
||||||
|
|
||||||
command_node.add_child(std::move(x));
|
command_node.add_child(std::move(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureGlobalStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node)
|
void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, XmlNode& command_node)
|
||||||
{
|
{
|
||||||
|
BiboumiComponent& biboumi_component = static_cast<BiboumiComponent&>(xmpp_component);
|
||||||
|
|
||||||
const XmlNode* x = command_node.get_child("x", "jabber:x:data");
|
const XmlNode* x = command_node.get_child("x", "jabber:x:data");
|
||||||
if (x)
|
if (x)
|
||||||
{
|
{
|
||||||
@@ -157,6 +173,14 @@ void ConfigureGlobalStep2(XmppComponent&, AdhocSession& session, XmlNode& comman
|
|||||||
if (field->get_tag("var") == "max_history_length" &&
|
if (field->get_tag("var") == "max_history_length" &&
|
||||||
value && !value->get_inner().empty())
|
value && !value->get_inner().empty())
|
||||||
options.maxHistoryLength = value->get_inner();
|
options.maxHistoryLength = value->get_inner();
|
||||||
|
else if (field->get_tag("var") == "record_history" &&
|
||||||
|
value && !value->get_inner().empty())
|
||||||
|
{
|
||||||
|
options.recordHistory = to_bool(value->get_inner());
|
||||||
|
Bridge* bridge = biboumi_component.find_user_bridge(owner.bare());
|
||||||
|
if (bridge)
|
||||||
|
bridge->set_record_history(options.recordHistory.value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
options.update();
|
options.update();
|
||||||
|
|||||||
Reference in New Issue
Block a user