summaryrefslogtreecommitdiff
path: root/src/bridge
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-06-18 22:42:58 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-06-18 22:42:58 +0200
commit04de62a4e0af4843e84c933e16f249ba1df6874f (patch)
tree764c8234801de762a73aa0acff26efc742976cd2 /src/bridge
parent56eb5df28a1023db2039388fe6c8fc1346da1a3d (diff)
downloadbiboumi-04de62a4e0af4843e84c933e16f249ba1df6874f.tar.gz
biboumi-04de62a4e0af4843e84c933e16f249ba1df6874f.tar.bz2
biboumi-04de62a4e0af4843e84c933e16f249ba1df6874f.tar.xz
biboumi-04de62a4e0af4843e84c933e16f249ba1df6874f.zip
Messages to room participants are forwarded to the IRC user
For example, both JID #chan%server@biboumi/Toto and toto!server@biboumi are equivalent, except that if you send a message to the first one, subsequent messages coming from the user toto will come from that same JID. This is done to be consistent for the XMPP user, and respond from the same JID than the 'to' of the first message. fix #2468
Diffstat (limited to 'src/bridge')
-rw-r--r--src/bridge/bridge.cpp30
-rw-r--r--src/bridge/bridge.hpp16
2 files changed, 44 insertions, 2 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index 6d864c0..a0964df 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -242,8 +242,18 @@ void Bridge::send_message(const Iid& iid, const std::string& nick, const std::st
this->xmpp->send_muc_message(std::to_string(iid), nick,
this->make_xmpp_body(body), this->user_jid);
else
- this->xmpp->send_message(std::to_string(iid),
- this->make_xmpp_body(body), this->user_jid, "chat");
+ {
+ std::string target = std::to_string(iid);
+ bool fulljid = false;
+ auto it = this->preferred_user_from.find(iid.get_local());
+ if (it != this->preferred_user_from.end())
+ {
+ target = it->second;
+ fulljid = true;
+ }
+ this->xmpp->send_message(target, this->make_xmpp_body(body),
+ this->user_jid, "chat", fulljid);
+ }
}
void Bridge::send_join_failed(const Iid& iid, const std::string& nick, const std::string& type, const std::string& condition, const std::string& text)
@@ -343,3 +353,19 @@ void Bridge::send_iq_version_request(const std::string& nick, const std::string&
{
this->xmpp->send_iq_version_request(nick + "!" + 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);
+}
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index 814222b..8711829 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -123,6 +123,14 @@ public:
* Get the number of server to which this bridge is connected or connecting.
*/
size_t active_clients() const;
+ /**
+ * Add (or replace the existing) <nick, jid> into the preferred_user_from map
+ */
+ void set_preferred_from_jid(const std::string& nick, const std::string& full_jid);
+ /**
+ * Remove the preferred jid for the given IRC nick
+ */
+ void remove_preferred_from_jid(const std::string& nick);
private:
/**
@@ -157,6 +165,14 @@ private:
* their sockets.
*/
std::shared_ptr<Poller> poller;
+ /**
+ * A map of <nick, full_jid>. For example if this map contains <"toto",
+ * "#somechan%server@biboumi/ToTo">, whenever a private message is
+ * received from the user "toto", instead of forwarding it to XMPP with
+ * from='toto!server@biboumi', we use instead
+ * from='#somechan%server@biboumi/ToTo'
+ */
+ std::unordered_map<std::string, std::string> preferred_user_from;
Bridge(const Bridge&) = delete;
Bridge(Bridge&& other) = delete;