From 150afaed9002fced708e3f04e85faa98a55e0ee0 Mon Sep 17 00:00:00 2001 From: HanzZ Date: Tue, 4 Dec 2012 18:21:44 +0100 Subject: [PATCH] Removed m_modes and m_away and introduced IRCBuddy in communi backend --- backends/libcommuni/session.cpp | 24 +++++++++++++----------- backends/libcommuni/session.h | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/backends/libcommuni/session.cpp b/backends/libcommuni/session.cpp index 134a1de4..d3bf7e5d 100644 --- a/backends/libcommuni/session.cpp +++ b/backends/libcommuni/session.cpp @@ -118,9 +118,9 @@ void MyIrcSession::on_nickChanged(IrcMessage *message) { for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) { std::string nickname = TO_UTF8(m->sender().name()); - bool flags = m_modes[it->second->getChannel() + nickname]; + IRCBuddy &buddy = getIRCBuddy(it->second->getChannel(), nickname); LOG4CXX_INFO(logger, user << ": " << nickname << " changed nickname to " << TO_UTF8(m->nick())); - np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) flags, pbnetwork::STATUS_ONLINE, "", TO_UTF8(m->nick())); + np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) buddy.isOp(), pbnetwork::STATUS_ONLINE, "", TO_UTF8(m->nick())); } } @@ -134,14 +134,14 @@ void MyIrcSession::on_modeChanged(IrcMessage *message) { return; LOG4CXX_INFO(logger, user << ": " << nickname << " changed mode to " << mode); for(AutoJoinMap::iterator it = m_autoJoin.begin(); it != m_autoJoin.end(); it++) { + IRCBuddy &buddy = getIRCBuddy(it->second->getChannel(), nickname); if (mode == "+o") { - m_modes[it->second->getChannel() + nickname] = 1; + buddy.setOp(true); } else { - m_modes[it->second->getChannel() + nickname] = 0; + buddy.setOp(false); } - bool flags = m_modes[it->second->getChannel() + nickname]; - np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) flags, pbnetwork::STATUS_ONLINE, ""); + np->handleParticipantChanged(user, nickname, it->second->getChannel() + suffix,(int) buddy.isOp(), pbnetwork::STATUS_ONLINE, ""); } } @@ -214,7 +214,8 @@ void MyIrcSession::on_numericMessageReceived(IrcMessage *message) { if (m->parameters().value(6).toUpper().startsWith("G")) { channel = m->parameters().value(1); nick = TO_UTF8(m->parameters().value(5)); - np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, m_modes[TO_UTF8(channel) + nick], pbnetwork::STATUS_AWAY); + IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nick); + np->handleParticipantChanged(user, nick, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_AWAY); } break; case 353: @@ -223,11 +224,12 @@ void MyIrcSession::on_numericMessageReceived(IrcMessage *message) { LOG4CXX_INFO(logger, user << ": Received members for " << TO_UTF8(channel) << suffix); for (int i = 0; i < members.size(); i++) { - bool flags = 0; + bool op = 0; std::string nickname = TO_UTF8(members.at(i)); - flags = correctNickname(nickname); - m_modes[TO_UTF8(channel) + nickname] = flags; - np->handleParticipantChanged(user, nickname, TO_UTF8(channel) + suffix,(int) flags, pbnetwork::STATUS_ONLINE); + op = correctNickname(nickname); + IRCBuddy &buddy = getIRCBuddy(TO_UTF8(channel), nickname); + buddy.setOp(op); + np->handleParticipantChanged(user, nickname, TO_UTF8(channel) + suffix, buddy.isOp(), pbnetwork::STATUS_ONLINE); } break; diff --git a/backends/libcommuni/session.h b/backends/libcommuni/session.h index d398dd25..c0e39a35 100644 --- a/backends/libcommuni/session.h +++ b/backends/libcommuni/session.h @@ -37,11 +37,24 @@ public: std::string m_password; }; + class IRCBuddy { + public: + IRCBuddy(bool op = false, bool away = false) : m_op(op), m_away(away) {}; + + void setOp(bool op) { m_op = op; } + bool isOp() { return m_op; } + void setAway(bool away) { m_away = away; } + bool isAway() { return m_away; } + + private: + bool m_op; + bool m_away; + }; + typedef std::map > AutoJoinMap; + typedef std::map > IRCBuddyMap; MyIrcSession(const std::string &user, IRCNetworkPlugin *np, const std::string &suffix = "", QObject* parent = 0); - std::map m_modes; - std::map m_away; std::string suffix; int rooms; @@ -61,6 +74,10 @@ public: return m_identify; } + IRCBuddy &getIRCBuddy(const std::string &channel, const std::string &name) { + return m_buddies[channel][name]; + } + bool correctNickname(std::string &nickname); void on_joined(IrcMessage *message); @@ -88,6 +105,7 @@ protected: bool m_connected; std::list m_rooms; std::list m_names; + IRCBuddyMap m_buddies; }; #endif // SESSION_H