From 9f7782bb0c5915969fd7477e0ed7c10b1a5c2d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 6 Jul 2017 22:24:42 +0200 Subject: =?UTF-8?q?Add=20a=20global=20=E2=80=9Cpersistent=E2=80=9D=20optio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.rst | 1 + doc/biboumi.1.rst | 4 ++++ src/bridge/bridge.cpp | 11 ++++++++--- src/database/database.hpp | 2 +- src/xmpp/biboumi_adhoc_commands.cpp | 18 ++++++++++++++++++ tests/end_to_end/__main__.py | 1 + 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c8cddfe..1540abf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Version 6.0 to work with the database. - The RecordHistory option can now also be configured for each IRC channel, individually. + - Add a global option to make all channels persistent. Version 5.0 - 2017-05-24 ======================== diff --git a/doc/biboumi.1.rst b/doc/biboumi.1.rst index 4a2225e..91b2f6d 100644 --- a/doc/biboumi.1.rst +++ b/doc/biboumi.1.rst @@ -558,6 +558,10 @@ On the gateway itself (e.g on the JID biboumi.example.com): the database. * Max history length: The maximum number of lines in the history that the server is allowed to send when joining a channel. + * Persistent: Overrides the value specified in each individual channel, + all channels are persistent, whether or not their specific value is + true or false. See below for more details on what a persistent + channel is. On a server JID (e.g on the JID chat.freenode.org@biboumi.example.com) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 23ecfe9..81ca147 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -436,9 +436,14 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con // acknowledgment from the server bool persistent = false; #ifdef USE_DATABASE - const auto coptions = Database::get_irc_channel_options_with_server_default(this->user_jid, - iid.get_server(), iid.get_local()); - persistent = coptions.col(); + const auto goptions = Database::get_global_options(this->user_jid); + if (goptions.col()) + persistent = true; + else + { + const auto coptions = Database::get_irc_channel_options_with_server_default(this->user_jid, iid.get_server(), iid.get_local()); + persistent = coptions.col(); + } #endif if (channel->joined && !channel->parting && !persistent) { diff --git a/src/database/database.hpp b/src/database/database.hpp index 28b6b1b..8364abc 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -98,7 +98,7 @@ class Database using MucLogLineTable = Table; using MucLogLine = MucLogLineTable::RowType; - using GlobalOptionsTable = Table; + using GlobalOptionsTable = Table; using GlobalOptions = GlobalOptionsTable::RowType; using IrcServerOptionsTable = Table; diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index ad4faf8..c1b7323 100644 --- a/src/xmpp/biboumi_adhoc_commands.cpp +++ b/src/xmpp/biboumi_adhoc_commands.cpp @@ -147,6 +147,21 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman else value.set_inner("false"); } + + XmlSubNode persistent(x, "field"); + persistent["var"] = "persistent"; + persistent["type"] = "boolean"; + persistent["label"] = "Make all channels persistent"; + persistent["desc"] = "If true, all channels will be persistent"; + + { + XmlSubNode value(persistent, "value"); + value.set_name("value"); + if (options.col()) + value.set_inner("true"); + else + value.set_inner("false"); + } } void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, XmlNode& command_node) @@ -173,6 +188,9 @@ void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, if (bridge) bridge->set_record_history(options.col()); } + else if (field->get_tag("var") == "persistent" && + value) + options.col() = to_bool(value->get_inner()); } options.save(Database::db); diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 19dc270..580f8e4 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -2392,6 +2392,7 @@ if __name__ == '__main__': "/iq/commands:command/dataform:x[@type='form']/dataform:instructions[text()='Edit the form, to configure your global settings for the component.']", "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='max_history_length']/dataform:value[text()='42']", "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='boolean'][@var='record_history']/dataform:value[text()='false']", + "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='boolean'][@var='persistent']/dataform:value[text()='false']", "/iq/commands:command/commands:actions/commands:next", ), after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid")) -- cgit v1.2.3