diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-01-06 01:22:43 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-01-06 01:22:43 +0100 |
commit | fef9c8193ddf8cdf81978874be788af9441e2286 (patch) | |
tree | f38a50b1e52e3da1a66d4d2ab5016a2cd7903322 /src/bridge/bridge.cpp | |
parent | 7701c907636d79f55e033aa7adaf7ffae4150c91 (diff) | |
download | biboumi-fef9c8193ddf8cdf81978874be788af9441e2286.tar.gz biboumi-fef9c8193ddf8cdf81978874be788af9441e2286.tar.bz2 biboumi-fef9c8193ddf8cdf81978874be788af9441e2286.tar.xz biboumi-fef9c8193ddf8cdf81978874be788af9441e2286.zip |
Also set the role and affiliation of users already in the chan
Diffstat (limited to 'src/bridge/bridge.cpp')
-rw-r--r-- | src/bridge/bridge.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index dae5a72..be0d270 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -6,6 +6,7 @@ #include <logger/logger.hpp> #include <utils/split.hpp> #include <iostream> +#include <tuple> static const char* action_prefix = "\01ACTION "; static const size_t action_prefix_len = 8; @@ -21,6 +22,22 @@ Bridge::~Bridge() { } +/** + * Return the role and affiliation, corresponding to the given irc mode */ +static std::tuple<std::string, std::string> get_role_affiliation_from_irc_mode(const char mode) +{ + if (mode == 'a' || mode == 'q') + return std::make_tuple("moderator", "owner"); + else if (mode == 'o') + return std::make_tuple("moderator", "admin"); + else if (mode == 'h') + return std::make_tuple("moderator", "member"); + else if (mode == 'v') + return std::make_tuple("participant", "member"); + else + return std::make_tuple("participant", "none"); +} + void Bridge::shutdown() { for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) @@ -197,15 +214,13 @@ void Bridge::send_xmpp_message(const std::string& from, const std::string& autho void Bridge::send_user_join(const std::string& hostname, const std::string& chan_name, const IrcUser* user, + const char user_mode, const bool self) { - std::string affiliation = "participant"; - std::string role = "none"; - if (user->modes.find('o') != user->modes.end()) - { - affiliation = "admin"; - role = "moderator"; - } + std::string affiliation; + std::string role; + std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(user_mode); + this->xmpp->send_user_join(chan_name + "%" + hostname, user->nick, user->host, affiliation, role, this->user_jid, self); } @@ -237,30 +252,7 @@ void Bridge::send_affiliation_role_change(const Iid& iid, const std::string& tar { std::string role; std::string affiliation; - if (mode == 0) - { - role = "participant"; - affiliation = "none"; - } - else if (mode == 'a') - { - role = "moderator"; - affiliation = "owner"; - } - else if (mode == 'o') - { - role = "moderator"; - affiliation = "admin"; - } - else if (mode == 'h') - { - role = "moderator"; - affiliation = "member"; - } - else if (mode == 'v') - { - role = "participant"; - affiliation = "member"; - } + + std::tie(role, affiliation) = get_role_affiliation_from_irc_mode(mode); this->xmpp->send_affiliation_role_change(iid.chan + "%" + iid.server, target, affiliation, role, this->user_jid); } |