X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.h;h=c7a02d5a8e484f753011cb1b00ed8737877aa762;hp=c8840ed8e0b4972d0b6cb6209cca3391b6f7d6d8;hb=7298446b3e86140c4bbbfe7aeeb959c16c53363c;hpb=1cb02004ee5973b89368bd84f234d4652794690d diff --git a/src/common/ircuser.h b/src/common/ircuser.h index c8840ed8..c7a02d5a 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,14 +18,15 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef IRCUSER_H -#define IRCUSER_H +#pragma once +#include "common-export.h" + +#include #include #include #include #include -#include #include "syncableobject.h" #include "types.h" @@ -34,22 +35,23 @@ class SignalProxy; class Network; class IrcChannel; -class IrcUser : public SyncableObject +class COMMON_EXPORT IrcUser : public SyncableObject { - SYNCABLE_OBJECT Q_OBJECT + SYNCABLE_OBJECT Q_PROPERTY(QString user READ user WRITE setUser) Q_PROPERTY(QString host READ host WRITE setHost) Q_PROPERTY(QString nick READ nick WRITE setNick) Q_PROPERTY(QString realName READ realName WRITE setRealName) + Q_PROPERTY(QString account READ account WRITE setAccount) Q_PROPERTY(bool away READ isAway WRITE setAway) Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage) Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime) Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime) Q_PROPERTY(QString server READ server WRITE setServer) Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator) - Q_PROPERTY(int lastAwayMessage READ lastAwayMessage WRITE setLastAwayMessage) + Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime) Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply) Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost) Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted) @@ -57,14 +59,19 @@ class IrcUser : public SyncableObject Q_PROPERTY(QStringList channels READ channels) Q_PROPERTY(QString userModes READ userModes WRITE setUserModes) -public : - IrcUser(const QString &hostmask, Network *network); - virtual ~IrcUser(); +public: + IrcUser(const QString& hostmask, Network* network); inline QString user() const { return _user; } inline QString host() const { return _host; } inline QString nick() const { return _nick; } inline QString realName() const { return _realName; } + /** + * Account name, e.g. NickServ/SASL account + * + * @return Account name if logged in, * if logged out, or empty string if unknown + */ + inline QString account() const { return _account; } QString hostmask() const; inline bool isAway() const { return _away; } inline QString awayMessage() const { return _awayMessage; } @@ -72,75 +79,117 @@ public : inline QDateTime loginTime() const { return _loginTime; } inline QString server() const { return _server; } inline QString ircOperator() const { return _ircOperator; } - inline int lastAwayMessage() const { return _lastAwayMessage; } + inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; } inline QString whoisServiceReply() const { return _whoisServiceReply; } inline QString suserHost() const { return _suserHost; } inline bool encrypted() const { return _encrypted; } - inline Network *network() const { return _network; } + inline Network* network() const { return _network; } inline QString userModes() const { return _userModes; } QStringList channels() const; // user-specific encodings - inline QTextCodec *codecForEncoding() const { return _codecForEncoding; } - inline QTextCodec *codecForDecoding() const { return _codecForDecoding; } - void setCodecForEncoding(const QString &codecName); - void setCodecForEncoding(QTextCodec *codec); - void setCodecForDecoding(const QString &codecName); - void setCodecForDecoding(QTextCodec *codec); + inline QTextCodec* codecForEncoding() const { return _codecForEncoding; } + inline QTextCodec* codecForDecoding() const { return _codecForDecoding; } + void setCodecForEncoding(const QString& codecName); + void setCodecForEncoding(QTextCodec* codec); + void setCodecForDecoding(const QString& codecName); + void setCodecForDecoding(QTextCodec* codec); - QString decodeString(const QByteArray &text) const; - QByteArray encodeString(const QString &string) const; + QString decodeString(const QByteArray& text) const; + QByteArray encodeString(const QString& string) const; // only valid on client side, these are not synced! inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); } - void setLastChannelActivity(BufferId id, const QDateTime &time); + void setLastChannelActivity(BufferId id, const QDateTime& time); inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); } - void setLastSpokenTo(BufferId id, const QDateTime &time); + void setLastSpokenTo(BufferId id, const QDateTime& time); + + /** + * Gets whether or not the away state has changed since it was last acknowledged + * + * Away state is marked as changed by any modification to away status (away/here, message) + * + * NOTE: On servers lacking support for IRCv3 away-notify, this won't update until an autoWHO- + * run for away/here changes, or until sending a message to the user for away message changes. + * + * @see IrcUser::acknowledgeAwayChanged() + * + * @return True if current away state is unchanged from last acknowledgement, otherwise false + */ + inline bool hasAwayChanged() const { return _awayChanged; } + + /** + * Sets the last away state change as acknowledged + * + * @see IrcUser::hasAwayChanged() + */ + inline void acknowledgeAwayChanged() + { + // Don't sync this as individual clients may suppress different kinds of behaviors + _awayChanged = false; + } + + void partChannelInternal(IrcChannel* channel, bool skip_sync = false); + void quitInternal(bool skip_sync = false); public slots: - void setUser(const QString &user); - void setHost(const QString &host); - void setNick(const QString &nick); - void setRealName(const QString &realName); - void setAway(const bool &away); - void setAwayMessage(const QString &awayMessage); - void setIdleTime(const QDateTime &idleTime); - void setLoginTime(const QDateTime &loginTime); - void setServer(const QString &server); - void setIrcOperator(const QString &ircOperator); - void setLastAwayMessage(const int &lastAwayMessage); - void setWhoisServiceReply(const QString &whoisServiceReply); - void setSuserHost(const QString &suserHost); + void setUser(const QString& user); + void setHost(const QString& host); + void setNick(const QString& nick); + void setRealName(const QString& realName); + /** + * Set account name, e.g. NickServ/SASL account + * + * @param[in] account Account name if logged in, * if logged out, or empty string if unknown + */ + void setAccount(const QString& account); + void setAway(bool away); + void setAwayMessage(const QString& awayMessage); + void setIdleTime(const QDateTime& idleTime); + void setLoginTime(const QDateTime& loginTime); + void setServer(const QString& server); + void setIrcOperator(const QString& ircOperator); + // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets + // converted to setting the appropriate lastAwayMessageTime. Do not use this in new code. + void setLastAwayMessage(int lastAwayMessage); + void setLastAwayMessageTime(const QDateTime& lastAwayMessageTime); + void setWhoisServiceReply(const QString& whoisServiceReply); + void setSuserHost(const QString& suserHost); void setEncrypted(bool encrypted); - void updateHostmask(const QString &mask); - - void setUserModes(const QString &modes); - - void joinChannel(IrcChannel *channel); - void joinChannel(const QString &channelname); - void partChannel(IrcChannel *channel); - void partChannel(const QString &channelname); + void updateHostmask(const QString& mask); + + void setUserModes(const QString& modes); + + /*! + * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in. + * \param channel Pointer to a channel this user just joined + * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak. + */ + void joinChannel(IrcChannel* channel, bool skip_channel_join = false); + void joinChannel(const QString& channelname); + void partChannel(IrcChannel* channel); + void partChannel(const QString& channelname); void quit(); - void addUserModes(const QString &modes); - void removeUserModes(const QString &modes); + void addUserModes(const QString& modes); + void removeUserModes(const QString& modes); signals: -// void userSet(QString user); -// void hostSet(QString host); - void nickSet(QString newnick); // needed in NetworkModel -// void realNameSet(QString realName); - void awaySet(bool away); // needed in NetworkModel -// void awayMessageSet(QString awayMessage); -// void idleTimeSet(QDateTime idleTime); -// void loginTimeSet(QDateTime loginTime); -// void serverSet(QString server); -// void ircOperatorSet(QString ircOperator); -// void lastAwayMessageSet(int lastAwayMessage); -// void whoisServiceReplySet(QString whoisServiceReply); -// void suserHostSet(QString suserHost); + // void userSet(QString user); + // void hostSet(QString host); + void nickSet(QString newnick); // needed in NetworkModel + // void realNameSet(QString realName); + void awaySet(bool away); // needed in NetworkModel + // void awayMessageSet(QString awayMessage); + // void idleTimeSet(QDateTime idleTime); + // void loginTimeSet(QDateTime loginTime); + // void serverSet(QString server); + // void ircOperatorSet(QString ircOperator); + // void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime); + // void whoisServiceReplySet(QString whoisServiceReply); + // void suserHostSet(QString suserHost); void encryptedSet(bool encrypted); void userModesSet(QString modes); @@ -151,25 +200,24 @@ signals: void channelParted(QString channel); void quited(); - void lastChannelActivityUpdated(BufferId id, const QDateTime &newTime); - void lastSpokenToUpdated(BufferId id, const QDateTime &newTime); + void lastChannelActivityUpdated(BufferId id, const QDateTime& newTime); + void lastSpokenToUpdated(BufferId id, const QDateTime& newTime); private slots: void updateObjectName(); void channelDestroyed(); private: - inline bool operator==(const IrcUser &ircuser2) - { - return (_nick.toLower() == ircuser2.nick().toLower()); - } + inline bool operator==(const IrcUser& ircuser2) { return (_nick.toLower() == ircuser2.nick().toLower()); } + inline bool operator==(const QString& nickname) { return (_nick.toLower() == nickname.toLower()); } - inline bool operator==(const QString &nickname) - { - return (_nick.toLower() == nickname.toLower()); - } - + /** + * Sets the last away state change as unacknowledged + * + * @see IrcUser::hasAwayChanged() + */ + inline void markAwayChanged() { _awayChanged = true; } bool _initialized; @@ -177,6 +225,7 @@ private: QString _user; QString _host; QString _realName; + QString _account; /// Account name, e.g. NickServ/SASL account QString _awayMessage; bool _away; QString _server; @@ -184,23 +233,24 @@ private: QDateTime _idleTimeSet; QDateTime _loginTime; QString _ircOperator; - int _lastAwayMessage; + QDateTime _lastAwayMessageTime; QString _whoisServiceReply; QString _suserHost; bool _encrypted; // QSet _channels; - QSet _channels; + QSet _channels; QString _userModes; - Network *_network; + Network* _network; - QTextCodec *_codecForEncoding; - QTextCodec *_codecForDecoding; + QTextCodec* _codecForEncoding; + QTextCodec* _codecForDecoding; QHash _lastActivity; QHash _lastSpokenTo; -}; - -#endif + // Given it's never been acknowledged, assume changes exist on IrcUser creation + /// Tracks if changes in away state (away/here, message) have yet to be acknowledged + bool _awayChanged = true; +};