23 #include "irc/configuration/ircconfig.h" 24 #include "irc/ircglobal.h" 25 #include "irc/ircmessageclass.h" 26 #include "irc/ircnetworkadapter.h" 27 #include "irc/ircuserinfo.h" 28 #include "irc/ircuserlist.h" 29 #include "ircchanneladapter.h" 31 IRCChannelAdapter::IRCChannelAdapter(
IRCNetworkAdapter *pNetwork,
const QString &recipient)
37 IRCChannelAdapter::~IRCChannelAdapter()
39 if (this->pNetwork !=
nullptr)
40 sendMessage(
"/part " + this->recipientName +
" " + gIRCConfig.personal.quitMessage);
47 const QString &myNickname = pNetwork->myNickname();
48 return isOperator(myNickname);
62 for (
const QString &name : names)
64 appendNameToCachedList(name);
70 pNetwork->banUser(nickname, reason, this->recipientName);
75 emit nameListUpdated(*users);
83 QString actualSenderName = sender;
84 if (pUserInfo !=
nullptr)
89 const QString &myNickname = pNetwork->myNickname();
90 if (content.contains(myNickname, Qt::CaseInsensitive)
91 && sender.compare(myNickname, Qt::CaseInsensitive) != 0)
93 emit myNicknameUsed();
99 bool IRCChannelAdapter::hasUser(
const QString &nickname)
101 return users->hasUser(nickname);
107 if (pUser !=
nullptr)
108 return pUser->isOp();
115 if (hasUser(nickname))
118 this->sendMessage(QString(
"/kick %1 %2 %3").arg(this->recipientName, cleanNickname, reason));
126 if (!users->removeNameFromCachedList(name))
127 emit error(QString(R
"(Attempted to remove name "%1" from the "%2" channel's name list but no such name is on the list.)").arg(name, this->recipientName)); 129 emit nameRemoved(user);
134 pNetwork->setChannelMode(this->recipientName, nickname,
"h", bSet);
139 pNetwork->setChannelMode(this->recipientName, nickname,
"o", bSet);
144 pNetwork->setChannelMode(this->recipientName, nickname,
"v", bSet);
149 if (hasUser(oldNickname))
151 IRCUserInfo oldName = users->userCopy(oldNickname);
153 users->changeNick(oldNickname, newNickname);
154 emit nameRemoved(oldName);
155 emit nameAdded(users->userCopy(newNickname));
157 emit messageWithClass(tr(
"%1 is now known as %2").arg(oldNickname, newNickname),
158 IRCMessageClass::ChannelAction);
164 appendNameToCachedList(nickname);
166 emit messageWithClass(tr(
"User %1 [%2] has joined the channel.").arg(nickname, fullSignature),
167 IRCMessageClass::ChannelAction);
172 if (!hasUser(nickname))
178 removeNameFromCachedList(nickname);
182 case IRCChatAdapter::ChannelPart:
183 emit messageWithClass(tr(
"User %1 has left the channel. (PART: %2)").arg(nickname, farewellMessage),
184 IRCMessageClass::ChannelAction);
187 case IRCChatAdapter::NetworkKill:
188 emit messageWithClass(tr(
"Connection for user %1 has been killed. (KILL: %2)").arg(nickname, farewellMessage),
189 IRCMessageClass::NetworkAction);
192 case IRCChatAdapter::NetworkQuit:
193 emit messageWithClass(tr(
"User %1 has quit the network. (QUIT: %2)").arg(nickname, farewellMessage),
194 IRCMessageClass::NetworkAction);
198 emit error(tr(
"Unknown quit type from user %1.").arg(nickname));
204 const QList<char> &addedFlags,
const QList<char> &removedFlags)
206 const IRCUserInfo *pUserInfo = this->users->user(nickname);
207 if (pUserInfo !=
nullptr)
210 for (
char mode : addedFlags)
212 newUserInfo.setMode(mode);
214 for (
char mode : removedFlags)
216 newUserInfo.unsetMode(mode);
219 this->users->setUserModes(nickname, newUserInfo.modes());
220 emit nameUpdated(newUserInfo);
Interprets communication between the client and the IRC server.
void userLeaves(const QString &nickname, const QString &farewellMessage, IRCQuitType quitType) override
Use this to register the fact that user has left the chat.
Allows to perform operation on a list of users.
void emitCachedNameListUpdated()
Emits cached list of names. This should be called when end of names list message is received for this...
void kickUser(const QString &nickname, const QString &reason)
Kicks user from the channel.
void userJoins(const QString &nickname, const QString &fullSignature) override
Use this to register the fact that user has joined the chat.
void removeNameFromCachedList(const QString &name)
Removes a name from the sortecd cachedNames list.
void setHalfOp(const QString &nickname, bool bSet)
Sets half op mode for given user.
void appendNamesToCachedList(const QStringList &names)
Appends a list of names to cachedNames list. This ensures that no duplicate names are found on the li...
QString cleanNickname() const
Returns nickname with no prefixes, contrary to the prefixedName() .
void userChangesNickname(const QString &oldNickname, const QString &newNickname) override
virtual void emitChatMessage(const QString &sender, const QString &content)
Emits message() signal formatting it to present sender's message.
QString prefixedName() const
Will generate prefix based on the user flags.
bool amIOperator() const
Checks if this client is an operator on this channel.
Handles chatting through IRC.
void banUser(const QString &nickname, const QString &reason)
Bans and kicks user from the channel.
void emitChatMessage(const QString &sender, const QString &content) override
Emits message() signal formatting it to present sender's message.
void setVoiced(const QString &nickname, bool bSet)
Sets voice mode for given user.
Holds information flags about given nickname.
void setOp(const QString &nickname, bool bSet)
Sets op mode for given user.
virtual IRCNetworkAdapter * network()=0
The idea of the adapter system is that each adapter is either a network or is a child of a network...
void userModeChanges(const QString &nickname, const QList< char > &addedFlags, const QList< char > &removedFlags) override
bool isOperator(const QString &nickname) const
Checks if user is an operator on this channel.
void appendNameToCachedList(const QString &name)
Appends a single name to the sorted cachedNames list.