projects
/
quassel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
modernize: Use braced-init list when returning types
[quassel.git]
/
src
/
common
/
ircchannel.cpp
diff --git
a/src/common/ircchannel.cpp
b/src/common/ircchannel.cpp
index
4b8cd33
..
7bb83ed
100644
(file)
--- a/
src/common/ircchannel.cpp
+++ b/
src/common/ircchannel.cpp
@@
-30,7
+30,6
@@
#include <QDebug>
#include <QDebug>
-INIT_SYNCABLE_OBJECT(IrcChannel)
IrcChannel::IrcChannel(const QString &channelname, Network *network)
: SyncableObject(network),
_initialized(false),
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),
_topic(QString()),
_encrypted(false),
_network(network),
- _codecForEncoding(
0
),
- _codecForDecoding(
0
)
+ _codecForEncoding(
nullptr
),
+ _codecForDecoding(
nullptr
)
{
setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname);
}
{
setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname);
}
-IrcChannel::~IrcChannel()
-{
-}
-
-
// ====================
// PUBLIC:
// ====================
bool IrcChannel::isKnownUser(IrcUser *ircuser) const
{
// ====================
// 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 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;
}
return false;
}
@@
-170,6
+164,9
@@
void IrcChannel::joinIrcUsers(const QList<IrcUser *> &users, const QStringList &
return;
}
return;
}
+ // Sort user modes first
+ const QStringList sortedModes = network()->sortPrefixModes(modes);
+
QStringList newNicks;
QStringList newModes;
QList<IrcUser *> newUsers;
QStringList newNicks;
QStringList newModes;
QList<IrcUser *> newUsers;
@@
-177,20
+174,22
@@
void IrcChannel::joinIrcUsers(const QList<IrcUser *> &users, const QStringList &
IrcUser *ircuser;
for (int i = 0; i < users.count(); i++) {
ircuser = users[i];
IrcUser *ircuser;
for (int i = 0; i < users.count(); i++) {
ircuser = users[i];
- if (!ircuser || _userModes.contains(ircuser)) {
- if (modes[i].count() > 1) {
+ 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?
// 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 <
m
odes[i].count(); ++i_m) {
- addUserMode(ircuser,
m
odes[i][i_m]);
+ for (int i_m = 0; i_m <
sortedM
odes[i].count(); ++i_m) {
+ addUserMode(ircuser,
sortedM
odes[i][i_m]);
}
} else {
}
} else {
- addUserMode(ircuser,
m
odes[i]);
+ addUserMode(ircuser,
sortedM
odes[i]);
}
continue;
}
}
continue;
}
- _userModes[ircuser] =
m
odes[i];
+ _userModes[ircuser] =
sortedM
odes[i];
ircuser->joinChannel(this, true);
connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString)));
ircuser->joinChannel(this, true);
connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString)));
@@
-199,7
+198,7
@@
void IrcChannel::joinIrcUsers(const QList<IrcUser *> &users, const QStringList &
// the joins are propagated by the ircuser. The signal ircUserJoined is only for convenience
newNicks << ircuser->nick();
// the joins are propagated by the ircuser. The signal ircUserJoined is only for convenience
newNicks << ircuser->nick();
- newModes <<
m
odes[i];
+ newModes <<
sortedM
odes[i];
newUsers << ircuser;
}
newUsers << ircuser;
}
@@
-237,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
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()) {
emit ircUserParted(ircuser);
if (network()->isMe(ircuser) || _userModes.isEmpty()) {
@@
-246,7
+245,7
@@
void IrcChannel::part(IrcUser *ircuser)
QList<IrcUser *> users = _userModes.keys();
_userModes.clear();
foreach(IrcUser *user, users) {
QList<IrcUser *> users = _userModes.keys();
_userModes.clear();
foreach(IrcUser *user, users) {
- disconnect(user,
0, this, 0
);
+ disconnect(user,
nullptr, this, nullptr
);
user->partChannel(this);
}
emit parted();
user->partChannel(this);
}
emit parted();
@@
-266,7
+265,8
@@
void IrcChannel::part(const QString &nick)
void IrcChannel::setUserModes(IrcUser *ircuser, const QString &modes)
{
if (isKnownUser(ircuser)) {
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);
QString nick = ircuser->nick();
SYNC_OTHER(setUserModes, ARG(nick), ARG(modes))
emit ircUserModesSet(ircuser, modes);
@@
-287,7
+287,8
@@
void IrcChannel::addUserMode(IrcUser *ircuser, const QString &mode)
return;
if (!_userModes[ircuser].contains(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);
QString nick = ircuser->nick();
SYNC_OTHER(addUserMode, ARG(nick), ARG(mode))
emit ircUserModeAdded(ircuser, mode);
@@
-308,6
+309,7
@@
void IrcChannel::removeUserMode(IrcUser *ircuser, const QString &mode)
return;
if (_userModes[ircuser].contains(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));
_userModes[ircuser].remove(mode);
QString nick = ircuser->nick();
SYNC_OTHER(removeUserMode, ARG(nick), ARG(mode));
@@
-345,6
+347,7
@@
void IrcChannel::initSetUserModes(const QVariantMap &usermodes)
modes << iter.value().toString();
++iter;
}
modes << iter.value().toString();
++iter;
}
+ // joinIrcUsers handles sorting modes
joinIrcUsers(users, modes);
}
joinIrcUsers(users, modes);
}
@@
-421,7
+424,7
@@
void IrcChannel::initSetChanModes(const QVariantMap &channelModes)
void IrcChannel::ircUserDestroyed()
{
void IrcChannel::ircUserDestroyed()
{
-
IrcUser
*ircUser = static_cast<IrcUser *>(sender());
+
auto
*ircUser = static_cast<IrcUser *>(sender());
Q_ASSERT(ircUser);
_userModes.remove(ircUser);
// no further propagation.
Q_ASSERT(ircUser);
_userModes.remove(ircUser);
// no further propagation.
@@
-431,7
+434,7
@@
void IrcChannel::ircUserDestroyed()
void IrcChannel::ircUserNickSet(QString nick)
{
void IrcChannel::ircUserNickSet(QString nick)
{
-
IrcUser
*ircUser = qobject_cast<IrcUser *>(sender());
+
auto
*ircUser = qobject_cast<IrcUser *>(sender());
Q_ASSERT(ircUser);
emit ircUserNickSet(ircUser, nick);
}
Q_ASSERT(ircUser);
emit ircUserNickSet(ircUser, nick);
}