X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fircparser.cpp;h=1a2a1fdb6bfa2e647451b84b2e3e27d2d4b43b31;hp=3bd8691324dedf43c1cd6fe7526b828aa4d41af1;hb=e14649614fbbf9b386505a5d782b88b1ac313c1f;hpb=1dc525a6f105f8db449bf04b127147f24de3d421 diff --git a/src/core/ircparser.cpp b/src/core/ircparser.cpp index 3bd86913..1a2a1fdb 100644 --- a/src/core/ircparser.cpp +++ b/src/core/ircparser.cpp @@ -119,7 +119,7 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent* e) qDebug() << "IRC net" << net->networkId() << "<<" << tags << prefix << cmd << params; } - if (tags.contains(IrcTags::SERVER_TIME)) { + if (net->capEnabled(IrcCap::SERVER_TIME) && tags.contains(IrcTags::SERVER_TIME)) { QDateTime serverTime = QDateTime::fromString(tags[IrcTags::SERVER_TIME], "yyyy-MM-ddThh:mm:ss.zzzZ"); serverTime.setTimeSpec(Qt::UTC); if (serverTime.isValid()) { @@ -129,6 +129,26 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent* e) } } + if (net->capEnabled(IrcCap::ACCOUNT_TAG) && tags.contains(IrcTags::ACCOUNT)) { + // Whenever account-tag is specified, update the relevant IrcUser if it exists + // Logged-out status is handled in specific commands (PRIVMSG, NOTICE, etc) + // + // Don't use "updateNickFromMask" here to ensure this only updates existing IrcUsers and + // won't create a new IrcUser. This guards against an IRC server setting "account" tag in + // nonsensical places, e.g. for messages that are not user sent. + IrcUser* ircuser = net->ircUser(prefix); + if (ircuser) { + ircuser->setAccount(tags[IrcTags::ACCOUNT]); + } + + // NOTE: if "account-tag" is enabled and no "account" tag is sent, the given user isn't + // logged in ONLY IF it is a user-initiated command. Quassel follows a mixture of what + // other clients do here - only marking as logged out via PRIVMSG/NOTICE, but marking logged + // in via any message. + // + // See https://ircv3.net/specs/extensions/account-tag-3.2 + } + QList events; EventManager::EventType type = EventManager::Invalid; @@ -169,7 +189,24 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent* e) if (checkParamCount(cmd, params, 1)) { QString senderNick = nickFromMask(prefix); - net->updateNickFromMask(prefix); + // Fetch/create the relevant IrcUser, and store it for later updates + IrcUser* ircuser = net->updateNickFromMask(prefix); + + // Handle account-tag + if (ircuser && net->capEnabled(IrcCap::ACCOUNT_TAG)) { + if (tags.contains(IrcTags::ACCOUNT)) { + // Account tag available, set account. + // This duplicates the generic account-tag handling in case a new IrcUser object + // was just created. + ircuser->setAccount(tags[IrcTags::ACCOUNT]); + } + else { + // PRIVMSG is user sent; it's safe to assume the user has logged out. + // "*" is used to represent logged-out. + ircuser->setAccount("*"); + } + } + // Check if the sender is our own nick. If so, treat message as if sent by ourself. // See http://ircv3.net/specs/extensions/echo-message-3.2.html // Cache the result to avoid multiple redundant comparisons @@ -212,6 +249,9 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent* e) // Cache the result to avoid multiple redundant comparisons bool isSelfMessage = net->isMyNick(nickFromMask(prefix)); + // Only update from the prefix once during the loop + bool updatedFromPrefix = false; + QStringList targets = net->serverDecode(params.at(0)).split(',', QString::SkipEmptyParts); QStringList::const_iterator targetIter; for (targetIter = targets.constBegin(); targetIter != targets.constEnd(); ++targetIter) { @@ -248,7 +288,29 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent* e) if (!isSelfMessage) { target = nickFromMask(prefix); } - net->updateNickFromMask(prefix); + + if (!updatedFromPrefix) { + // Don't repeat this within the loop, the prefix doesn't change + updatedFromPrefix = true; + + // Fetch/create the relevant IrcUser, and store it for later updates + IrcUser* ircuser = net->updateNickFromMask(prefix); + + // Handle account-tag + if (ircuser && net->capEnabled(IrcCap::ACCOUNT_TAG)) { + if (tags.contains(IrcTags::ACCOUNT)) { + // Account tag available, set account. + // This duplicates the generic account-tag handling in case a + // new IrcUser object was just created. + ircuser->setAccount(tags[IrcTags::ACCOUNT]); + } + else { + // NOTICE is user sent; it's safe to assume the user has + // logged out. "*" is used to represent logged-out. + ircuser->setAccount("*"); + } + } + } } }