summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-10-12 17:14:29 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-10-12 17:14:29 +0200
commit1aa2c2d857037f3274297527ca3971a75203d39c (patch)
tree9b09bea387764e4e9e20e5545d3091330695dbb9 /src
parent84aafab6040f8fd126e6c4941631d44f122c4b9a (diff)
downloadbiboumi-1aa2c2d857037f3274297527ca3971a75203d39c.tar.gz
biboumi-1aa2c2d857037f3274297527ca3971a75203d39c.tar.bz2
biboumi-1aa2c2d857037f3274297527ca3971a75203d39c.tar.xz
biboumi-1aa2c2d857037f3274297527ca3971a75203d39c.zip
Introduce the realname_from_jid option
When set to true, the realname and username are extracted (by default) from the user’s JID fix #3136
Diffstat (limited to 'src')
-rw-r--r--src/bridge/bridge.cpp19
-rw-r--r--src/bridge/bridge.hpp5
-rw-r--r--src/irc/irc_client.cpp8
-rw-r--r--src/irc/irc_client.hpp4
4 files changed, 26 insertions, 10 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index ba70069..ec143f0 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -90,7 +90,7 @@ Xmpp::body Bridge::make_xmpp_body(const std::string& str)
return irc_format_to_xhtmlim(res);
}
-IrcClient* Bridge::get_irc_client(const std::string& hostname, const std::string& username)
+IrcClient* Bridge::make_irc_client(const std::string& hostname, const std::string& nickname)
{
try
{
@@ -98,7 +98,18 @@ IrcClient* Bridge::get_irc_client(const std::string& hostname, const std::string
}
catch (const std::out_of_range& exception)
{
- this->irc_clients.emplace(hostname, std::make_shared<IrcClient>(this->poller, hostname, username, this));
+ auto username = nickname;
+ auto realname = nickname;
+ if (Config::get("realname_from_jid", "false") == "true")
+ {
+ Jid jid(this->user_jid);
+ username = jid.local;
+ realname = this->get_bare_jid();
+ }
+ this->irc_clients.emplace(hostname,
+ std::make_shared<IrcClient>(this->poller, hostname,
+ nickname, username,
+ realname, this));
std::shared_ptr<IrcClient> irc = this->irc_clients.at(hostname);
return irc.get();
}
@@ -128,9 +139,9 @@ IrcClient* Bridge::find_irc_client(const std::string& hostname)
}
}
-bool Bridge::join_irc_channel(const Iid& iid, const std::string& username, const std::string& password)
+bool Bridge::join_irc_channel(const Iid& iid, const std::string& nickname, const std::string& password)
{
- IrcClient* irc = this->get_irc_client(iid.get_server(), username);
+ IrcClient* irc = this->make_irc_client(iid.get_server(), nickname);
if (iid.get_local().empty())
{ // Join the dummy channel
if (irc->is_welcomed())
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index dfe0aa7..f1ecf25 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -60,7 +60,8 @@ public:
* Try to join an irc_channel, does nothing and return true if the channel
* was already joined.
*/
- bool join_irc_channel(const Iid& iid, const std::string& username, const std::string& password);
+ bool join_irc_channel(const Iid& iid, const std::string& nickname, const std::string& password);
+
void send_channel_message(const Iid& iid, const std::string& body);
void send_private_message(const Iid& iid, const std::string& body, const std::string& type="PRIVMSG");
void send_raw_message(const std::string& hostname, const std::string& body);
@@ -193,7 +194,7 @@ private:
* username in this case) if none is found, and connect that newly-created
* client immediately.
*/
- IrcClient* get_irc_client(const std::string& hostname, const std::string& username);
+ IrcClient* make_irc_client(const std::string& hostname, const std::string& nickname);
/**
* This version does not create the IrcClient if it does not exist, throws
* a IRCServerNotConnected error in that case.
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index d6c7021..0289d72 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -24,12 +24,14 @@ using namespace std::string_literals;
using namespace std::chrono_literals;
-IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& username, Bridge* bridge):
+IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname,
+ const std::string& nickname, const std::string& username,
+ const std::string& realname, Bridge* bridge):
TCPSocketHandler(poller),
hostname(hostname),
username(username),
- realname(username),
- current_nick(username),
+ realname(realname),
+ current_nick(nickname),
bridge(bridge),
welcomed(false),
chanmodes({"", "", "", ""}),
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index a6b51ce..7a04164 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -25,7 +25,9 @@ class Bridge;
class IrcClient: public TCPSocketHandler
{
public:
- explicit IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& username, Bridge* bridge);
+ explicit IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname,
+ const std::string& nickname, const std::string& username,
+ const std::string& realname, Bridge* bridge);
~IrcClient();
/**
* Connect to the IRC server