X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=09323067151fbfec4da59e944413a8830933c6f2;hp=145a198667bb3c535309e98603199fd7cd69edbe;hb=299bb29099bdfac07f6b318b62f5f4c50d7493e3;hpb=40601ae070413b727a68e35e5b8c619176c661b1 diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 145a1986..09323067 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -61,7 +61,7 @@ bool IrcChannel::isKnownUser(IrcUser *ircuser) const } if (!_userModes.contains(ircuser)) { - qWarning() << "Channel" << name() << "received data for unknown User" << ircuser->nick(); + // This can happen e.g. when disconnecting from a network, so don't log a warning return false; } @@ -73,7 +73,7 @@ bool IrcChannel::isValidChannelUserMode(const QString &mode) const { bool isvalid = true; if (mode.size() > 1) { - qWarning() << "Channel" << name() << "received Channel User Mode which is longer then 1 Char:" << mode; + qWarning() << "Channel" << name() << "received Channel User Mode which is longer than 1 Char:" << mode; isvalid = false; } return isvalid; @@ -170,6 +170,9 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & return; } + // Sort user modes first + const QStringList sortedModes = network()->sortPrefixModes(modes); + QStringList newNicks; QStringList newModes; QList newUsers; @@ -177,21 +180,31 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & IrcUser *ircuser; for (int i = 0; i < users.count(); i++) { ircuser = users[i]; - if (!ircuser || _userModes.contains(ircuser)) { - addUserMode(ircuser, modes[i]); + if (!ircuser) + continue; + if (_userModes.contains(ircuser)) { + if (sortedModes[i].count() > 1) { + // Multiple modes received, do it one at a time + // TODO Better way of syncing this without breaking protocol? + for (int i_m = 0; i_m < sortedModes[i].count(); ++i_m) { + addUserMode(ircuser, sortedModes[i][i_m]); + } + } else { + addUserMode(ircuser, sortedModes[i]); + } continue; } - _userModes[ircuser] = modes[i]; - ircuser->joinChannel(this); + _userModes[ircuser] = sortedModes[i]; + ircuser->joinChannel(this, true); connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString))); // connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); - // if you wonder why there is no counterpart to ircUserJoined: - // the joines are propagted by the ircuser. the signal ircUserJoined is only for convenience + // If you wonder why there is no counterpart to ircUserJoined: + // the joins are propagated by the ircuser. The signal ircUserJoined is only for convenience newNicks << ircuser->nick(); - newModes << modes[i]; + newModes << sortedModes[i]; newUsers << ircuser; } @@ -227,8 +240,8 @@ void IrcChannel::part(IrcUser *ircuser) if (isKnownUser(ircuser)) { _userModes.remove(ircuser); ircuser->partChannel(this); - // if you wonder why there is no counterpart to ircUserParted: - // the joines are propagted by the ircuser. the signal ircUserParted is only for convenience + // If you wonder why there is no counterpart to ircUserParted: + // the joins are propagted by the ircuser. The signal ircUserParted is only for convenience disconnect(ircuser, 0, this, 0); emit ircUserParted(ircuser); @@ -258,7 +271,8 @@ void IrcChannel::part(const QString &nick) void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes) { if (isKnownUser(ircuser)) { - _userModes[ircuser] = modes; + // Keep user modes sorted + _userModes[ircuser] = network()->sortPrefixModes(modes); QString nick = ircuser->nick(); SYNC_OTHER(setUserModes, ARG(nick), ARG(modes)) emit ircUserModesSet(ircuser, modes); @@ -279,7 +293,8 @@ void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode) return; if (!_userModes[ircuser].contains(mode)) { - _userModes[ircuser] += mode; + // Keep user modes sorted + _userModes[ircuser] = network()->sortPrefixModes(_userModes[ircuser] + mode); QString nick = ircuser->nick(); SYNC_OTHER(addUserMode, ARG(nick), ARG(mode)) emit ircUserModeAdded(ircuser, mode); @@ -300,6 +315,7 @@ void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode) return; if (_userModes[ircuser].contains(mode)) { + // Removing modes shouldn't mess up ordering _userModes[ircuser].remove(mode); QString nick = ircuser->nick(); SYNC_OTHER(removeUserMode, ARG(nick), ARG(mode)); @@ -321,7 +337,7 @@ QVariantMap IrcChannel::initUserModes() const QHash::const_iterator iter = _userModes.constBegin(); while (iter != _userModes.constEnd()) { usermodes[iter.key()->nick()] = iter.value(); - iter++; + ++iter; } return usermodes; } @@ -335,8 +351,9 @@ void IrcChannel::initSetUserModes(const QVariantMap &usermodes) while (iter != usermodes.constEnd()) { users << network()->newIrcUser(iter.key()); modes << iter.value().toString(); - iter++; + ++iter; } + // joinIrcUsers handles sorting modes joinIrcUsers(users, modes); } @@ -349,7 +366,7 @@ QVariantMap IrcChannel::initChanModes() const QHash::const_iterator A_iter = _A_channelModes.constBegin(); while (A_iter != _A_channelModes.constEnd()) { A_modes[A_iter.key()] = A_iter.value(); - A_iter++; + ++A_iter; } channelModes["A"] = A_modes; @@ -357,7 +374,7 @@ QVariantMap IrcChannel::initChanModes() const QHash::const_iterator B_iter = _B_channelModes.constBegin(); while (B_iter != _B_channelModes.constEnd()) { B_modes[B_iter.key()] = B_iter.value(); - B_iter++; + ++B_iter; } channelModes["B"] = B_modes; @@ -365,7 +382,7 @@ QVariantMap IrcChannel::initChanModes() const QHash::const_iterator C_iter = _C_channelModes.constBegin(); while (C_iter != _C_channelModes.constEnd()) { C_modes[C_iter.key()] = C_iter.value(); - C_iter++; + ++C_iter; } channelModes["C"] = C_modes; @@ -373,7 +390,7 @@ QVariantMap IrcChannel::initChanModes() const QSet::const_iterator D_iter = _D_channelModes.constBegin(); while (D_iter != _D_channelModes.constEnd()) { D_modes += *D_iter; - D_iter++; + ++D_iter; } channelModes["D"] = D_modes; @@ -387,21 +404,21 @@ void IrcChannel::initSetChanModes(const QVariantMap &channelModes) QVariantMap::const_iterator iterEnd = channelModes["A"].toMap().constEnd(); while (iter != iterEnd) { _A_channelModes[iter.key()[0]] = iter.value().toStringList(); - iter++; + ++iter; } iter = channelModes["B"].toMap().constBegin(); iterEnd = channelModes["B"].toMap().constEnd(); while (iter != iterEnd) { _B_channelModes[iter.key()[0]] = iter.value().toString(); - iter++; + ++iter; } iter = channelModes["C"].toMap().constBegin(); iterEnd = channelModes["C"].toMap().constEnd(); while (iter != iterEnd) { _C_channelModes[iter.key()[0]] = iter.value().toString(); - iter++; + ++iter; } QString D_modes = channelModes["D"].toString(); @@ -468,7 +485,7 @@ void IrcChannel::ircUserNickSet(QString nick) * C --> set value or remove * D --> on/off * - * B and C behave very similar... we store the data in different datastructes + * B and C behave very similar... we store the data in different datastructures * for future compatibility ******************************************************************************/ @@ -547,9 +564,8 @@ bool IrcChannel::hasMode(const QChar &mode) const return _C_channelModes.contains(mode); case Network::D_CHANMODE: return _D_channelModes.contains(mode); - default: - return false; } + return false; } @@ -582,9 +598,11 @@ QStringList IrcChannel::modeValueList(const QChar &mode) const case Network::A_CHANMODE: if (_A_channelModes.contains(mode)) return _A_channelModes[mode]; + break; default: - return QStringList(); + ; } + return {}; } @@ -596,21 +614,21 @@ QString IrcChannel::channelModeString() const QSet::const_iterator D_iter = _D_channelModes.constBegin(); while (D_iter != _D_channelModes.constEnd()) { modeString += *D_iter; - D_iter++; + ++D_iter; } QHash::const_iterator BC_iter = _C_channelModes.constBegin(); while (BC_iter != _C_channelModes.constEnd()) { modeString += BC_iter.key(); params << BC_iter.value(); - BC_iter++; + ++BC_iter; } BC_iter = _B_channelModes.constBegin(); while (BC_iter != _B_channelModes.constEnd()) { modeString += BC_iter.key(); params << BC_iter.value(); - BC_iter++; + ++BC_iter; } if (modeString.isEmpty()) return modeString;