From 99389eefba1883753c15c6f411fb8543c93f58a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 10 Feb 2018 17:36:33 +0100 Subject: Always return the oldest matching messages from MAM, even if no date is set --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 54bee84..acb8e18 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1020,7 +1020,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since); + const auto lines = Database::get_muc_most_recent_logs(this->user_jid, chan_name, hostname, limit, history_limit.since); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { -- cgit v1.2.3 From fd7c365288b9c4db1d441b553d42b26e81715b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 13 Feb 2018 03:10:00 +0100 Subject: Use the same function for both history orders --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index acb8e18..fefab40 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1020,7 +1020,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_most_recent_logs(this->user_jid, chan_name, hostname, limit, history_limit.since); + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { -- cgit v1.2.3 From 158d743bf539399e48c64044639b90e5c1705ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 4 Mar 2018 22:18:58 +0100 Subject: Remove the virtual channel feature altogether --- src/bridge/bridge.cpp | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index fefab40..cd3492f 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -63,7 +63,6 @@ void Bridge::shutdown(const std::string& exit_message) for (auto& pair: this->irc_clients) { pair.second->send_quit_command(exit_message); - pair.second->leave_dummy_channel(exit_message, {}); } } @@ -176,35 +175,6 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const auto res_in_chan = this->is_resource_in_chan(ChannelKey{iid.get_local(), hostname}, resource); if (!res_in_chan) this->add_resource_to_chan(ChannelKey{iid.get_local(), hostname}, resource); - if (iid.get_local().empty()) - { // Join the dummy channel - if (irc->is_welcomed()) - { - if (res_in_chan) - return false; - // Immediately simulate a message coming from the IRC server saying that we - // joined the channel - if (irc->get_dummy_channel().joined) - { - this->generate_channel_join_for_resource(iid, resource); - } - else - { - const IrcMessage join_message(irc->get_nick(), "JOIN", {""}); - irc->on_channel_join(join_message); - const IrcMessage end_join_message(std::string(iid.get_server()), "366", - {irc->get_nick(), - "", "End of NAMES list"}); - irc->on_channel_completely_joined(end_join_message); - } - } - else - { - irc->get_dummy_channel().joining = true; - irc->start(); - } - return true; - } if (irc->is_channel_joined(iid.get_local()) == false) { irc->send_join_command(iid.get_local(), password); @@ -445,11 +415,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con #endif if (channel->joined && !channel->parting && !persistent) { - const auto& chan_name = iid.get_local(); - if (chan_name.empty()) - irc->leave_dummy_channel(status_message, resource); - else - irc->send_part_command(iid.get_local(), status_message); + irc->send_part_command(iid.get_local(), status_message); } else if (channel->joined) { @@ -1254,9 +1220,6 @@ std::size_t Bridge::number_of_channels_the_resource_is_in(const std::string& irc res++; } - IrcClient* irc = this->find_irc_client(irc_hostname); - if (irc && (irc->get_dummy_channel().joined || irc->get_dummy_channel().joining)) - res++; return res; } -- cgit v1.2.3 From bb596582bd2d8b9aab3fe08e76a7d24d82bf614a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 12 Mar 2018 00:04:26 +0100 Subject: Add a node in the presence of a leaving participant fix #3339 --- src/bridge/bridge.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index cd3492f..9269bb7 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -419,7 +419,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } else if (channel->joined) { - this->send_muc_leave(iid, channel->get_self()->nick, "", true, true, resource); + this->send_muc_leave(iid, *channel->get_self(), "", true, true, resource); } if (persistent) this->remove_resource_from_chan(key, resource); @@ -430,7 +430,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con else { if (channel && channel->joined) - this->send_muc_leave(iid, channel->get_self()->nick, + this->send_muc_leave(iid, *channel->get_self(), "Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.", true, true, resource); this->remove_resource_from_chan(key, resource); @@ -847,19 +847,29 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, this->xmpp.send_presence_error(std::to_string(iid), nick, this->user_jid, type, condition, error_code, text); } -void Bridge::send_muc_leave(const Iid& iid, const std::string& nick, +void Bridge::send_muc_leave(const Iid& iid, const IrcUser& user, const std::string& message, const bool self, const bool user_requested, const std::string& resource) { + const IrcClient* client = this->find_irc_client(iid.get_server()); + if (!client) + { + log_error("Tried to send an unavailable presence for non existant client: ", std::to_string(iid)); + return; + } + std::string affiliation; + std::string role; + std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user.get_most_significant_mode(client->get_sorted_user_modes())); + if (!resource.empty()) - this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), - this->user_jid + "/" + resource, self, user_requested); + this->xmpp.send_muc_leave(std::to_string(iid), user.nick, this->make_xmpp_body(message), + this->user_jid + "/" + resource, self, user_requested, affiliation, role); else { for (const auto &res: this->resources_in_chan[iid.to_tuple()]) - this->xmpp.send_muc_leave(std::to_string(iid), nick, this->make_xmpp_body(message), - this->user_jid + "/" + res, self, user_requested); + this->xmpp.send_muc_leave(std::to_string(iid), user.nick, this->make_xmpp_body(message), + this->user_jid + "/" + res, self, user_requested, affiliation, role); if (self) { // Copy the resources currently in that channel -- cgit v1.2.3 From 9500bfd4ccb21b261fd8204180d78553704f7acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 18 Mar 2018 19:33:07 +0100 Subject: Reflect message IDs in channel MUCs fix #3283 --- src/bridge/bridge.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 9269bb7..9a0358c 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -185,7 +186,7 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const return false; } -void Bridge::send_channel_message(const Iid& iid, const std::string& body) +void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::string id) { if (iid.get_server().empty()) { @@ -210,6 +211,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) std::vector lines = utils::split(body, '\n', true); if (lines.empty()) return ; + bool first = true; for (const std::string& line: lines) { if (line.substr(0, 5) == "/mode") @@ -231,9 +233,12 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), std::get<0>(xmpp_body), irc->get_own_nick()); #endif + if (!first) + id = utils::gen_uuid(); for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line), - this->user_jid + "/" + resource, uuid); + this->user_jid + "/" + resource, uuid, id); + first = false; } } @@ -816,7 +821,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) { this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding), - this->user_jid + "/" + resource, {}); + this->user_jid + "/" + resource, {}, utils::gen_uuid()); } } -- cgit v1.2.3 From 1320dc6db48ebde28f5c0791cfc87cfe392d106e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 18 Mar 2018 19:41:52 +0100 Subject: =?UTF-8?q?Don=E2=80=99t=20reflect=20an=20empty=20id=20if=20it=20w?= =?UTF-8?q?as=20not=20included?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead, generate a uuid for that message --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 9a0358c..aba2f05 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -233,7 +233,7 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body, std:: uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), std::get<0>(xmpp_body), irc->get_own_nick()); #endif - if (!first) + if (!first || id.empty()) id = utils::gen_uuid(); for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line), -- cgit v1.2.3 From 619c991a691a455efee2baa4e1fe96e64d27ff64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 19 Mar 2018 20:08:35 +0100 Subject: Add a nick field in the IRC server configuration form fix #3317 --- src/bridge/bridge.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index aba2f05..bff86b9 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -166,10 +166,15 @@ IrcClient* Bridge::find_irc_client(const std::string& hostname) const } } -bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const std::string& password, +bool Bridge::join_irc_channel(const Iid& iid, std::string nickname, const std::string& password, const std::string& resource, HistoryLimit history_limit) { const auto& hostname = iid.get_server(); +#ifdef USE_DATABASE + auto soptions = Database::get_irc_server_options(this->get_bare_jid(), hostname); + if (!soptions.col().empty()) + nickname = soptions.col(); +#endif IrcClient* irc = this->make_irc_client(hostname, nickname); irc->history_limit = history_limit; this->add_resource_to_server(hostname, resource); -- cgit v1.2.3 From faa33c1a712f98de4bafee821bde7eb270bbb7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 22 Mar 2018 20:44:30 +0100 Subject: Pass an IrcClient* to send_muc_leave instead of doing an other search --- src/bridge/bridge.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index bff86b9..f32ad31 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -429,7 +429,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } else if (channel->joined) { - this->send_muc_leave(iid, *channel->get_self(), "", true, true, resource); + this->send_muc_leave(iid, *channel->get_self(), "", true, true, resource, irc); } if (persistent) this->remove_resource_from_chan(key, resource); @@ -442,7 +442,7 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con if (channel && channel->joined) this->send_muc_leave(iid, *channel->get_self(), "Biboumi note: " + std::to_string(resources - 1) + " resources are still in this channel.", - true, true, resource); + true, true, resource, irc); this->remove_resource_from_chan(key, resource); } if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) @@ -860,14 +860,9 @@ void Bridge::send_presence_error(const Iid& iid, const std::string& nick, void Bridge::send_muc_leave(const Iid& iid, const IrcUser& user, const std::string& message, const bool self, const bool user_requested, - const std::string& resource) + const std::string& resource, + const IrcClient* client) { - const IrcClient* client = this->find_irc_client(iid.get_server()); - if (!client) - { - log_error("Tried to send an unavailable presence for non existant client: ", std::to_string(iid)); - return; - } std::string affiliation; std::string role; std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user.get_most_significant_mode(client->get_sorted_user_modes())); -- cgit v1.2.3 From e2fc3cf68e1dc145e75fe67f2543765ff00ba839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 23 Mar 2018 16:16:30 +0100 Subject: Properly handle force-join presences by sending everything in return fix #3305 --- src/bridge/bridge.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index f32ad31..90caac1 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -166,8 +166,11 @@ IrcClient* Bridge::find_irc_client(const std::string& hostname) const } } -bool Bridge::join_irc_channel(const Iid& iid, std::string nickname, const std::string& password, - const std::string& resource, HistoryLimit history_limit) +bool Bridge::join_irc_channel(const Iid& iid, std::string nickname, + const std::string& password, + const std::string& resource, + HistoryLimit history_limit, + const bool force_join) { const auto& hostname = iid.get_server(); #ifdef USE_DATABASE @@ -185,7 +188,8 @@ bool Bridge::join_irc_channel(const Iid& iid, std::string nickname, const std::s { irc->send_join_command(iid.get_local(), password); return true; - } else if (!res_in_chan) { + } else if (!res_in_chan || force_join) { + // See https://github.com/xsf/xeps/pull/499 for the force_join argument this->generate_channel_join_for_resource(iid, resource); } return false; -- cgit v1.2.3 From 0cd848e532c8c60ed4f3a5d1e6a3850929f2765b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 31 Mar 2018 02:10:39 +0200 Subject: Send the stanza-id for messages received by other users fix #3347 --- src/bridge/bridge.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 90caac1..569574a 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -819,19 +819,19 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std void Bridge::send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc) { const auto encoding = in_encoding_for(*this, iid); + std::string uuid{}; if (muc) { #ifdef USE_DATABASE const auto xmpp_body = this->make_xmpp_body(body, encoding); if (!nick.empty() && this->record_history) - Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), - std::get<0>(xmpp_body), nick); + uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), + std::get<0>(xmpp_body), nick); #endif for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) { this->xmpp.send_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding), - this->user_jid + "/" + resource, {}, utils::gen_uuid()); - + this->user_jid + "/" + resource, uuid, utils::gen_uuid()); } } else -- cgit v1.2.3 From 857c7d3972a03cbeebf730d99b924d3710dee6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 10 Apr 2018 23:33:59 +0200 Subject: Use a different Date data type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PLEASE backup your database before testing this commit, and report any migration issue. In postgresql, we use timestamp with timezone. In sqlite3 we use REAL (the date is expressed as julianday) This requires a migration of the muclogline_ table: In postgresql it’s pretty simple, we convert all the integer into timestamps With sqlite3, we actually rename the table, create the new one with the correct type, then copy everything to the new table, with a conversion function for the Date_ column, and then we delete the old table. fix #3343 --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 569574a..2598f51 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1009,9 +1009,9 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { - const auto seconds = line.col(); + const DateTime& datetime = line.col(); this->xmpp.send_history_message(chan_name, line.col(), line.col(), - this->user_jid + "/" + resource, seconds); + this->user_jid + "/" + resource, datetime); } #else (void)hostname; -- cgit v1.2.3 From 5ef7ba08028065b03d51d1dc70bb35aeb41ae19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 14 Apr 2018 19:48:45 +0200 Subject: Use the Date to find a next page in RSM, not the id This way, it works, whatever the order of insertion in the database was. fix #3343 --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 2598f51..afc8ad3 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1005,7 +1005,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, {}, Database::Paging::last); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { -- cgit v1.2.3 From 39a32d55248808637cee78b9218053306964f7aa Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 31 Mar 2018 16:36:57 +0200 Subject: Use jid.bare() instead of manual concatenation --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index afc8ad3..7f21254 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -103,7 +103,7 @@ const std::string& Bridge::get_jid() const std::string Bridge::get_bare_jid() const { Jid jid(this->user_jid); - return jid.local + "@" + jid.domain; + return jid.bare(); } Xmpp::body Bridge::make_xmpp_body(const std::string& str, const std::string& encoding) -- cgit v1.2.3 From a90f196a1ce779d502baf0aadff6e6917fec8a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 24 Apr 2018 19:13:10 +0200 Subject: Revert "Use the Date to find a next page in RSM, not the id" This reverts commit 5ef7ba08028065b03d51d1dc70bb35aeb41ae19d. --- src/bridge/bridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 7f21254..defb9a5 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1005,7 +1005,7 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, {}, Database::Paging::last); + const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { -- cgit v1.2.3 From 61de6b1dac4ef29627f3bdb9ce11b6c0d06f4a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 24 Apr 2018 19:19:06 +0200 Subject: Revert "Use a different Date data type" This reverts commit 857c7d3972a03cbeebf730d99b924d3710dee6a0. --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index defb9a5..1c646fe 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1009,9 +1009,9 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { - const DateTime& datetime = line.col(); + const auto seconds = line.col(); this->xmpp.send_history_message(chan_name, line.col(), line.col(), - this->user_jid + "/" + resource, datetime); + this->user_jid + "/" + resource, seconds); } #else (void)hostname; -- cgit v1.2.3 From b0168fd45b3683c2d6f61ccae67dcd5b918a363d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 29 Apr 2018 22:18:26 +0200 Subject: =?UTF-8?q?mam:=20Send=20=E2=80=9Cfin=20complete=E2=80=9D=20only?= =?UTF-8?q?=20when=20appropriate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also simplify how we did the whole “limit + 1” And fix one bad interpretation of the XEP for the case where the query has no after or before restriction. fix #3349 --- src/bridge/bridge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 1c646fe..7a0157a 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1005,7 +1005,8 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam auto limit = coptions.col(); if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto lines = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto result = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto& lines = std::get<1>(result); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) { -- cgit v1.2.3 From 0b8738d87aa101117c7681ade41f8527ad515d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 22 Jun 2018 21:33:58 +0200 Subject: Archive the Mode messages, except if they are received for an unjoined chan fix #3362 --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 7a0157a..b6081d5 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -816,7 +816,7 @@ void Bridge::send_irc_version_request(const std::string& irc_hostname, const std this->add_waiting_irc(std::move(cb)); } -void Bridge::send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc) +void Bridge::send_message(const Iid& iid, const std::string& nick, const std::string& body, const bool muc, const bool log) { const auto encoding = in_encoding_for(*this, iid); std::string uuid{}; @@ -824,7 +824,7 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st { #ifdef USE_DATABASE const auto xmpp_body = this->make_xmpp_body(body, encoding); - if (!nick.empty() && this->record_history) + if (log && this->record_history) uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), std::get<0>(xmpp_body), nick); #endif -- cgit v1.2.3 From 52166e07acd785b39c0da98be4c35e886b75c3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 25 Jun 2018 22:57:13 +0200 Subject: Trivial syntax improvements --- src/bridge/bridge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index b6081d5..08d0bab 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -63,7 +63,8 @@ void Bridge::shutdown(const std::string& exit_message) { for (auto& pair: this->irc_clients) { - pair.second->send_quit_command(exit_message); + std::shared_ptr& irc = pair.second; + irc->send_quit_command(exit_message); } } -- cgit v1.2.3 From 7f8a612c9881928f722fb41c75ff18b94a133ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 25 Jun 2018 22:57:23 +0200 Subject: Fix a warning (unused variable) in some build config --- src/bridge/bridge.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 08d0bab..c3c2003 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -828,6 +828,8 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st if (log && this->record_history) uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), std::get<0>(xmpp_body), nick); +#else + (void)log; #endif for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) { -- cgit v1.2.3 From 7a4cea426d0a07d577753ee008416e19eca6260d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 24 Jul 2018 23:14:35 +0200 Subject: Reflect messages to XMPP only when they are actually sent --- src/bridge/bridge.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index c3c2003..39ee158 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -224,6 +224,23 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body, std:: bool first = true; for (const std::string& line: lines) { + std::string uuid; +#ifdef USE_DATABASE + const auto xmpp_body = this->make_xmpp_body(line); + if (this->record_history) + uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), + std::get<0>(xmpp_body), irc->get_own_nick()); +#endif + if (!first || id.empty()) + id = utils::gen_uuid(); + + MessageCallback mirror_to_all_resources = [this, iid, uuid, id](const IrcClient* irc, const IrcMessage& message) { + const std::string& line = message.arguments[1]; + for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) + this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line), + this->user_jid + "/" + resource, uuid, id); + }; + if (line.substr(0, 5) == "/mode") { std::vector args = utils::split(line.substr(5), ' ', false); @@ -232,22 +249,11 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body, std:: // XMPP user, that’s not a textual message. } else if (line.substr(0, 4) == "/me ") - irc->send_channel_message(iid.get_local(), action_prefix + line.substr(4) + "\01"); + irc->send_channel_message(iid.get_local(), action_prefix + line.substr(4) + "\01", + std::move(mirror_to_all_resources)); else - irc->send_channel_message(iid.get_local(), line); + irc->send_channel_message(iid.get_local(), line, std::move(mirror_to_all_resources)); - std::string uuid; -#ifdef USE_DATABASE - const auto xmpp_body = this->make_xmpp_body(line); - if (this->record_history) - uuid = Database::store_muc_message(this->get_bare_jid(), iid.get_local(), iid.get_server(), std::chrono::system_clock::now(), - std::get<0>(xmpp_body), irc->get_own_nick()); -#endif - if (!first || id.empty()) - id = utils::gen_uuid(); - for (const auto& resource: this->resources_in_chan[iid.to_tuple()]) - this->xmpp.send_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line), - this->user_jid + "/" + resource, uuid, id); first = false; } } -- cgit v1.2.3 From 782732ba167470fa99ab3d0900c02295b4684b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sat, 4 Aug 2018 14:50:33 +0200 Subject: Remove a bunch of useless empty lines --- src/bridge/bridge.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 39ee158..ad03f38 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -458,7 +458,6 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con } if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) this->remove_resource_from_server(iid.get_server(), resource); - } void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource) @@ -900,9 +899,7 @@ void Bridge::send_muc_leave(const Iid& iid, const IrcUser& user, for (const auto& r: resources_in_chan) if (this->number_of_channels_the_resource_is_in(iid.get_server(), r) == 0) this->remove_resource_from_server(iid.get_server(), r); - } - } IrcClient* irc = this->find_irc_client(iid.get_server()); if (self && irc && irc->number_of_joined_channels() == 0) -- cgit v1.2.3 From 0b51e3828116f6847865fae93893eb97a10d1cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 23 Aug 2018 20:30:11 +0200 Subject: MaxHistoryLength now has some sensible default value if the user set a negative one --- src/bridge/bridge.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index ad03f38..a69bdff 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1007,11 +1007,14 @@ void Bridge::send_room_history(const std::string& hostname, const std::string& c void Bridge::send_room_history(const std::string& hostname, std::string chan_name, const std::string& resource, const HistoryLimit& history_limit) { #ifdef USE_DATABASE - const auto coptions = Database::get_irc_channel_options_with_server_and_global_default(this->user_jid, hostname, chan_name); - auto limit = coptions.col(); + const auto goptions = Database::get_global_options(this->user_jid); + log_debug(goptions.col()); + auto limit = goptions.col(); + if (limit < 0) + limit = 20; if (history_limit.stanzas >= 0 && history_limit.stanzas < limit) limit = history_limit.stanzas; - const auto result = Database::get_muc_logs(this->user_jid, chan_name, hostname, limit, history_limit.since, {}, Id::unset_value, Database::Paging::last); + const auto result = Database::get_muc_logs(this->user_jid, chan_name, hostname, static_cast(limit), history_limit.since, {}, Id::unset_value, Database::Paging::last); const auto& lines = std::get<1>(result); chan_name.append(utils::empty_if_fixed_server("%" + hostname)); for (const auto& line: lines) -- cgit v1.2.3 From 248e25c22fc15105d2a9db695ddb93ed5a8e0802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 26 Aug 2018 15:41:54 +0200 Subject: Replace a useless shared_ptr by a unique_ptr --- src/bridge/bridge.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index a69bdff..d7f5f16 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -63,7 +63,7 @@ void Bridge::shutdown(const std::string& exit_message) { for (auto& pair: this->irc_clients) { - std::shared_ptr& irc = pair.second; + std::unique_ptr& irc = pair.second; irc->send_quit_command(exit_message); } } @@ -134,11 +134,11 @@ IrcClient* Bridge::make_irc_client(const std::string& hostname, const std::strin realname = this->get_bare_jid(); } this->irc_clients.emplace(hostname, - std::make_shared(this->poller, hostname, + std::make_unique(this->poller, hostname, nickname, username, realname, jid.domain, *this)); - std::shared_ptr irc = this->irc_clients.at(hostname); + std::unique_ptr& irc = this->irc_clients.at(hostname); return irc.get(); } } @@ -1151,12 +1151,12 @@ void Bridge::trigger_on_irc_message(const std::string& irc_hostname, const IrcMe } } -std::unordered_map>& Bridge::get_irc_clients() +std::unordered_map>& Bridge::get_irc_clients() { return this->irc_clients; } -const std::unordered_map>& Bridge::get_irc_clients() const +const std::unordered_map>& Bridge::get_irc_clients() const { return this->irc_clients; } -- cgit v1.2.3 From 478619b10a27f7a25ba0b1082f4b12981b29d546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 26 Aug 2018 15:42:38 +0200 Subject: Trivial little syntax changes --- src/bridge/bridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index d7f5f16..5ba8a2d 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -456,8 +456,8 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con true, true, resource, irc); this->remove_resource_from_chan(key, resource); } - if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) - this->remove_resource_from_server(iid.get_server(), resource); + if (this->number_of_channels_the_resource_is_in(iid.get_server(), resource) == 0) + this->remove_resource_from_server(iid.get_server(), resource); } void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, const std::string& requesting_resource) -- cgit v1.2.3 From b9f6fbd8405c1d16ca637fb32850d44173528e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 26 Aug 2018 18:08:14 +0200 Subject: Remove an unused function (and a useless debug log) --- src/bridge/bridge.cpp | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/bridge/bridge.cpp') diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index 5ba8a2d..cc2ef66 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -1008,7 +1008,6 @@ void Bridge::send_room_history(const std::string& hostname, std::string chan_nam { #ifdef USE_DATABASE const auto goptions = Database::get_global_options(this->user_jid); - log_debug(goptions.col()); auto limit = goptions.col(); if (limit < 0) limit = 20; @@ -1223,15 +1222,6 @@ void Bridge::remove_resource_from_server(const Bridge::IrcHostname& irc_hostname } } -bool Bridge::is_resource_in_server(const Bridge::IrcHostname& irc_hostname, const std::string& resource) const -{ - auto it = this->resources_in_server.find(irc_hostname); - if (it != this->resources_in_server.end()) - if (it->second.count(resource) == 1) - return true; - return false; -} - std::size_t Bridge::number_of_resources_in_chan(const Bridge::ChannelKey& channel) const { auto it = this->resources_in_chan.find(channel); -- cgit v1.2.3