X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=6133e4334d1cd25d661fce48429d1a8f894ada65;hp=543f2b716f0a96293de0c894b6e84b51cc90e9b4;hb=ee8b9f55860e340c1600188fddcfd557c7489f66;hpb=921e54680da16fcf2adb7a90506875aceb6633a4 diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 543f2b71..6133e433 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.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 * @@ -40,7 +40,7 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net _server(), // _idleTime(QDateTime::currentDateTime()), _ircOperator(), - _lastAwayMessage(0), + _lastAwayMessageTime(), _whoisServiceReply(), _encrypted(false), _network(network), @@ -48,6 +48,8 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net _codecForDecoding(0) { updateObjectName(); + _lastAwayMessageTime.setTimeSpec(Qt::UTC); + _lastAwayMessageTime.setMSecsSinceEpoch(0); } @@ -68,8 +70,12 @@ QString IrcUser::hostmask() const QDateTime IrcUser::idleTime() { - if (QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200) + if ((QDateTime::currentDateTime().toMSecsSinceEpoch() - _idleTimeSet.toMSecsSinceEpoch()) + > 1200000) { + // 20 * 60 * 1000 = 1200000 + // 20 minutes have elapsed, clear the known idle time as it's likely inaccurate by now _idleTime = QDateTime(); + } return _idleTime; } @@ -146,10 +152,20 @@ void IrcUser::setRealName(const QString &realName) } +void IrcUser::setAccount(const QString &account) +{ + if (_account != account) { + _account = account; + SYNC(ARG(account)) + } +} + + void IrcUser::setAway(const bool &away) { if (away != _away) { _away = away; + markAwayChanged(); SYNC(ARG(away)) emit awaySet(away); } @@ -160,6 +176,7 @@ void IrcUser::setAwayMessage(const QString &awayMessage) { if (!awayMessage.isEmpty() && _awayMessage != awayMessage) { _awayMessage = awayMessage; + markAwayChanged(); SYNC(ARG(awayMessage)) } } @@ -202,11 +219,28 @@ void IrcUser::setIrcOperator(const QString &ircOperator) } +// This function is only ever called by SYNC calls from legacy cores (pre-0.13). +// Therefore, no SYNC call is needed here. void IrcUser::setLastAwayMessage(const int &lastAwayMessage) { - if (lastAwayMessage > _lastAwayMessage) { - _lastAwayMessage = lastAwayMessage; - SYNC(ARG(lastAwayMessage)) + QDateTime lastAwayMessageTime = QDateTime(); + lastAwayMessageTime.setTimeSpec(Qt::UTC); +#if QT_VERSION >= 0x050800 + lastAwayMessageTime.fromSecsSinceEpoch(lastAwayMessage); +#else + // toSecsSinceEpoch() was added in Qt 5.8. Manually downconvert to seconds for now. + // See https://doc.qt.io/qt-5/qdatetime.html#toMSecsSinceEpoch + lastAwayMessageTime.fromMSecsSinceEpoch(lastAwayMessage * 1000); +#endif + setLastAwayMessageTime(lastAwayMessageTime); +} + + +void IrcUser::setLastAwayMessageTime(const QDateTime &lastAwayMessageTime) +{ + if (lastAwayMessageTime > _lastAwayMessageTime) { + _lastAwayMessageTime = lastAwayMessageTime; + SYNC(ARG(lastAwayMessageTime)) } } @@ -275,12 +309,13 @@ void IrcUser::updateHostmask(const QString &mask) } -void IrcUser::joinChannel(IrcChannel *channel) +void IrcUser::joinChannel(IrcChannel *channel, bool skip_channel_join) { Q_ASSERT(channel); if (!_channels.contains(channel)) { _channels.insert(channel); - channel->joinIrcUser(this); + if (!skip_channel_join) + channel->joinIrcUser(this); } } @@ -345,9 +380,11 @@ void IrcUser::channelDestroyed() void IrcUser::setUserModes(const QString &modes) { - _userModes = modes; - SYNC(ARG(modes)) - emit userModesSet(modes); + if (_userModes != modes) { + _userModes = modes; + SYNC(ARG(modes)) + emit userModesSet(modes); + } } @@ -356,13 +393,19 @@ void IrcUser::addUserModes(const QString &modes) if (modes.isEmpty()) return; + // Don't needlessly sync when no changes are made + bool changesMade = false; for (int i = 0; i < modes.count(); i++) { - if (!_userModes.contains(modes[i])) + if (!_userModes.contains(modes[i])) { _userModes += modes[i]; + changesMade = true; + } } - SYNC(ARG(modes)) - emit userModesAdded(modes); + if (changesMade) { + SYNC(ARG(modes)) + emit userModesAdded(modes); + } }