summaryrefslogtreecommitdiff
path: root/src/bridge/bridge.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bridge/bridge.cpp')
-rw-r--r--src/bridge/bridge.cpp79
1 files changed, 22 insertions, 57 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 71c0ea4..e7f334f 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -170,8 +170,7 @@ 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,
- const bool force_join)
+ HistoryLimit history_limit)
{
const auto& hostname = iid.get_server();
#ifdef USE_DATABASE
@@ -185,18 +184,18 @@ bool Bridge::join_irc_channel(const Iid& iid, std::string nickname,
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 (irc->is_channel_joined(iid.get_local()) == false)
+ if (!irc->is_channel_joined(iid.get_local()))
{
irc->send_join_command(iid.get_local(), password);
return true;
- } else if (!res_in_chan || force_join) {
- // See https://github.com/xsf/xeps/pull/499 for the force_join argument
+ } else {
+ // See https://github.com/xsf/xeps/pull/499
this->generate_channel_join_for_resource(iid, resource);
}
return false;
}
-void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::string id)
+void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::string id, std::vector<XmlNode> nodes_to_reflect)
{
if (iid.get_server().empty())
{
@@ -234,15 +233,21 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body, std::
if (!first || id.empty())
id = utils::gen_uuid();
- MessageCallback mirror_to_all_resources = [this, iid, uuid, id](const IrcClient* irc, const IrcMessage& message) {
+ MessageCallback mirror_to_all_resources = [this, iid, uuid, id, nodes_to_reflect](const IrcClient* irc, const IrcMessage& message) {
std::string line = message.arguments[1];
// “temporary” workaround for \01ACTION…\01 -> /me messages
if ((line.size() > strlen("\01ACTION\01")) &&
(line.substr(0, 7) == "\01ACTION") && line[line.size() - 1] == '\01')
line = "/me " + line.substr(8, line.size() - 9);
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);
+ {
+ auto stanza = this->xmpp.make_muc_message(std::to_string(iid), irc->get_own_nick(), this->make_xmpp_body(line),
+ this->user_jid + "/"
+ + resource, uuid, id);
+ for (const auto& node: nodes_to_reflect)
+ stanza.add_child(node);
+ this->xmpp.send_stanza(stanza);
+ }
};
if (line.substr(0, 5) == "/mode")
@@ -448,9 +453,6 @@ void Bridge::leave_irc_channel(Iid&& iid, const std::string& status_message, con
}
if (persistent)
this->remove_resource_from_chan(key, resource);
- // Since there are no resources left in that channel, we don't
- // want to receive private messages using this room's JID
- this->remove_all_preferred_from_jid_of_room(iid.get_local());
}
else
{
@@ -859,27 +861,18 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
#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, uuid, utils::gen_uuid());
+ auto stanza = this->xmpp.make_muc_message(std::to_string(iid), nick, this->make_xmpp_body(body, encoding),
+ this->user_jid + "/"
+ + resource, uuid, utils::gen_uuid());
+ this->xmpp.send_stanza(stanza);
}
}
else
{
- const auto it = this->preferred_user_from.find(iid.get_local());
- if (it != this->preferred_user_from.end())
- {
- const auto chan_name = Iid(Jid(it->second).local, {}).get_local();
- for (const auto& resource: this->resources_in_chan[ChannelKey{chan_name, iid.get_server()}])
- this->xmpp.send_message(it->second, this->make_xmpp_body(body, encoding),
- this->user_jid + "/"
- + resource, "chat", true, true, true);
- }
- else
- {
- for (const auto& resource: this->resources_in_server[iid.get_server()])
- this->xmpp.send_message(std::to_string(iid), this->make_xmpp_body(body, encoding),
- this->user_jid + "/" + resource, "chat", false, true);
- }
+ this->xmpp.send_message(std::to_string(iid),
+ this->make_xmpp_body(body, encoding),
+ this->user_jid,
+ "chat", false, false);
}
}
@@ -1136,34 +1129,6 @@ void Bridge::on_irc_client_disconnected(const std::string& hostname)
this->xmpp.on_irc_client_disconnected(hostname, this->user_jid);
}
-void Bridge::set_preferred_from_jid(const std::string& nick, const std::string& full_jid)
-{
- auto it = this->preferred_user_from.find(nick);
- if (it == this->preferred_user_from.end())
- this->preferred_user_from.emplace(nick, full_jid);
- else
- this->preferred_user_from[nick] = full_jid;
-}
-
-void Bridge::remove_preferred_from_jid(const std::string& nick)
-{
- auto it = this->preferred_user_from.find(nick);
- if (it != this->preferred_user_from.end())
- this->preferred_user_from.erase(it);
-}
-
-void Bridge::remove_all_preferred_from_jid_of_room(const std::string& channel_name)
-{
- for (auto it = this->preferred_user_from.begin(); it != this->preferred_user_from.end();)
- {
- Iid iid(Jid(it->second).local, {});
- if (iid.get_local() == channel_name)
- it = this->preferred_user_from.erase(it);
- else
- ++it;
- }
-}
-
void Bridge::add_waiting_irc(irc_responder_callback_t&& callback)
{
this->waiting_irc.emplace_back(std::move(callback));