X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircchannel.cpp;h=37318d9e14088682dbf511f6d82e06797fd0079a;hp=be1347b974bba1f83ab21dc2dd12025ef8a83327;hb=6eefdfc697067d184a589fc8a231b16316c09106;hpb=aca57168d0ee9391d691b0e7089a792093215e6d diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index be1347b9..37318d9e 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 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 * @@ -30,7 +30,6 @@ #include -INIT_SYNCABLE_OBJECT(IrcChannel) IrcChannel::IrcChannel(const QString &channelname, Network *network) : SyncableObject(network), _initialized(false), @@ -38,30 +37,25 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network) _topic(QString()), _encrypted(false), _network(network), - _codecForEncoding(0), - _codecForDecoding(0) + _codecForEncoding(nullptr), + _codecForDecoding(nullptr) { setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); } -IrcChannel::~IrcChannel() -{ -} - - // ==================== // PUBLIC: // ==================== bool IrcChannel::isKnownUser(IrcUser *ircuser) const { - if (ircuser == 0) { + if (ircuser == nullptr) { qWarning() << "Channel" << name() << "received IrcUser Nullpointer!"; return false; } 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; } @@ -170,6 +164,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 +174,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); - connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString))); + _userModes[ircuser] = sortedModes[i]; + ircuser->joinChannel(this, true); + connect(ircuser, &IrcUser::nickSet, this, selectOverload(&IrcChannel::ircUserNickSet)); // connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); // 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; } @@ -229,7 +236,7 @@ void IrcChannel::part(IrcUser *ircuser) ircuser->partChannel(this); // 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); + disconnect(ircuser, nullptr, this, nullptr); emit ircUserParted(ircuser); if (network()->isMe(ircuser) || _userModes.isEmpty()) { @@ -238,7 +245,7 @@ void IrcChannel::part(IrcUser *ircuser) QList users = _userModes.keys(); _userModes.clear(); foreach(IrcUser *user, users) { - disconnect(user, 0, this, 0); + disconnect(user, nullptr, this, nullptr); user->partChannel(this); } emit parted(); @@ -258,7 +265,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 +287,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 +309,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 +331,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 +345,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 +360,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 +368,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 +376,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 +384,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 +398,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(); @@ -413,7 +424,7 @@ void IrcChannel::initSetChanModes(const QVariantMap &channelModes) void IrcChannel::ircUserDestroyed() { - IrcUser *ircUser = static_cast(sender()); + auto *ircUser = static_cast(sender()); Q_ASSERT(ircUser); _userModes.remove(ircUser); // no further propagation. @@ -423,7 +434,7 @@ void IrcChannel::ircUserDestroyed() void IrcChannel::ircUserNickSet(QString nick) { - IrcUser *ircUser = qobject_cast(sender()); + auto *ircUser = qobject_cast(sender()); Q_ASSERT(ircUser); emit ircUserNickSet(ircUser, nick); } @@ -547,9 +558,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 +592,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 +608,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;