1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "common-export.h"
28 #include <QStringList>
29 #include <QVariantMap>
31 #include "syncableobject.h"
38 class COMMON_EXPORT IrcUser : public SyncableObject
43 Q_PROPERTY(QString user READ user WRITE setUser)
44 Q_PROPERTY(QString host READ host WRITE setHost)
45 Q_PROPERTY(QString nick READ nick WRITE setNick)
46 Q_PROPERTY(QString realName READ realName WRITE setRealName)
47 Q_PROPERTY(QString account READ account WRITE setAccount)
48 Q_PROPERTY(bool away READ isAway WRITE setAway)
49 Q_PROPERTY(QString awayMessage READ awayMessage WRITE setAwayMessage)
50 Q_PROPERTY(QDateTime idleTime READ idleTime WRITE setIdleTime)
51 Q_PROPERTY(QDateTime loginTime READ loginTime WRITE setLoginTime)
52 Q_PROPERTY(QString server READ server WRITE setServer)
53 Q_PROPERTY(QString ircOperator READ ircOperator WRITE setIrcOperator)
54 Q_PROPERTY(QDateTime lastAwayMessageTime READ lastAwayMessageTime WRITE setLastAwayMessageTime)
55 Q_PROPERTY(QString whoisServiceReply READ whoisServiceReply WRITE setWhoisServiceReply)
56 Q_PROPERTY(QString suserHost READ suserHost WRITE setSuserHost)
57 Q_PROPERTY(bool encrypted READ encrypted WRITE setEncrypted)
59 Q_PROPERTY(QStringList channels READ channels)
60 Q_PROPERTY(QString userModes READ userModes WRITE setUserModes)
63 IrcUser(const QString& hostmask, Network* network);
65 inline QString user() const { return _user; }
66 inline QString host() const { return _host; }
67 inline QString nick() const { return _nick; }
68 inline QString realName() const { return _realName; }
70 * Account name, e.g. NickServ/SASL account
72 * @return Account name if logged in, * if logged out, or empty string if unknown
74 inline QString account() const { return _account; }
75 QString hostmask() const;
76 inline bool isAway() const { return _away; }
77 inline QString awayMessage() const { return _awayMessage; }
79 inline QDateTime loginTime() const { return _loginTime; }
80 inline QString server() const { return _server; }
81 inline QString ircOperator() const { return _ircOperator; }
82 inline QDateTime lastAwayMessageTime() const { return _lastAwayMessageTime; }
83 inline QString whoisServiceReply() const { return _whoisServiceReply; }
84 inline QString suserHost() const { return _suserHost; }
85 inline bool encrypted() const { return _encrypted; }
86 inline Network* network() const { return _network; }
88 inline QString userModes() const { return _userModes; }
90 QStringList channels() const;
92 // user-specific encodings
93 inline QTextCodec* codecForEncoding() const { return _codecForEncoding; }
94 inline QTextCodec* codecForDecoding() const { return _codecForDecoding; }
95 void setCodecForEncoding(const QString& codecName);
96 void setCodecForEncoding(QTextCodec* codec);
97 void setCodecForDecoding(const QString& codecName);
98 void setCodecForDecoding(QTextCodec* codec);
100 QString decodeString(const QByteArray& text) const;
101 QByteArray encodeString(const QString& string) const;
103 // only valid on client side, these are not synced!
104 inline QDateTime lastChannelActivity(BufferId id) const { return _lastActivity.value(id); }
105 void setLastChannelActivity(BufferId id, const QDateTime& time);
106 inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); }
107 void setLastSpokenTo(BufferId id, const QDateTime& time);
110 * Gets whether or not the away state has changed since it was last acknowledged
112 * Away state is marked as changed by any modification to away status (away/here, message)
114 * NOTE: On servers lacking support for IRCv3 away-notify, this won't update until an autoWHO-
115 * run for away/here changes, or until sending a message to the user for away message changes.
117 * @see IrcUser::acknowledgeAwayChanged()
119 * @return True if current away state is unchanged from last acknowledgement, otherwise false
121 inline bool hasAwayChanged() const { return _awayChanged; }
124 * Sets the last away state change as acknowledged
126 * @see IrcUser::hasAwayChanged()
128 inline void acknowledgeAwayChanged()
130 // Don't sync this as individual clients may suppress different kinds of behaviors
131 _awayChanged = false;
134 void partChannelInternal(IrcChannel* channel, bool skip_sync = false);
135 void quitInternal(bool skip_sync = false);
138 void setUser(const QString& user);
139 void setHost(const QString& host);
140 void setNick(const QString& nick);
141 void setRealName(const QString& realName);
143 * Set account name, e.g. NickServ/SASL account
145 * @param[in] account Account name if logged in, * if logged out, or empty string if unknown
147 void setAccount(const QString& account);
148 void setAway(bool away);
149 void setAwayMessage(const QString& awayMessage);
150 void setIdleTime(const QDateTime& idleTime);
151 void setLoginTime(const QDateTime& loginTime);
152 void setServer(const QString& server);
153 void setIrcOperator(const QString& ircOperator);
154 // setLastAwayMessage is only called by legacy (pre-0.13) cores, which automatically gets
155 // converted to setting the appropriate lastAwayMessageTime. Do not use this in new code.
156 void setLastAwayMessage(int lastAwayMessage);
157 void setLastAwayMessageTime(const QDateTime& lastAwayMessageTime);
158 void setWhoisServiceReply(const QString& whoisServiceReply);
159 void setSuserHost(const QString& suserHost);
160 void setEncrypted(bool encrypted);
161 void updateHostmask(const QString& mask);
163 void setUserModes(const QString& modes);
166 * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in.
167 * \param channel Pointer to a channel this user just joined
168 * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak.
170 void joinChannel(IrcChannel* channel, bool skip_channel_join = false);
171 void joinChannel(const QString& channelname);
172 void partChannel(IrcChannel* channel);
173 void partChannel(const QString& channelname);
176 void addUserModes(const QString& modes);
177 void removeUserModes(const QString& modes);
180 // void userSet(QString user);
181 // void hostSet(QString host);
182 void nickSet(QString newnick); // needed in NetworkModel
183 // void realNameSet(QString realName);
184 void awaySet(bool away); // needed in NetworkModel
185 // void awayMessageSet(QString awayMessage);
186 // void idleTimeSet(QDateTime idleTime);
187 // void loginTimeSet(QDateTime loginTime);
188 // void serverSet(QString server);
189 // void ircOperatorSet(QString ircOperator);
190 // void lastAwayMessageTimeSet(QDateTime lastAwayMessageTime);
191 // void whoisServiceReplySet(QString whoisServiceReply);
192 // void suserHostSet(QString suserHost);
193 void encryptedSet(bool encrypted);
195 void userModesSet(QString modes);
196 void userModesAdded(QString modes);
197 void userModesRemoved(QString modes);
199 // void channelJoined(QString channel);
200 void channelParted(QString channel);
203 void lastChannelActivityUpdated(BufferId id, const QDateTime& newTime);
204 void lastSpokenToUpdated(BufferId id, const QDateTime& newTime);
207 void updateObjectName();
208 void channelDestroyed();
211 inline bool operator==(const IrcUser& ircuser2) { return (_nick.toLower() == ircuser2.nick().toLower()); }
213 inline bool operator==(const QString& nickname) { return (_nick.toLower() == nickname.toLower()); }
216 * Sets the last away state change as unacknowledged
218 * @see IrcUser::hasAwayChanged()
220 inline void markAwayChanged() { _awayChanged = true; }
228 QString _account; /// Account name, e.g. NickServ/SASL account
229 QString _awayMessage;
233 QDateTime _idleTimeSet;
234 QDateTime _loginTime;
235 QString _ircOperator;
236 QDateTime _lastAwayMessageTime;
237 QString _whoisServiceReply;
241 // QSet<QString> _channels;
242 QSet<IrcChannel*> _channels;
247 QTextCodec* _codecForEncoding;
248 QTextCodec* _codecForDecoding;
250 QHash<BufferId, QDateTime> _lastActivity;
251 QHash<BufferId, QDateTime> _lastSpokenTo;
253 // Given it's never been acknowledged, assume changes exist on IrcUser creation
254 /// Tracks if changes in away state (away/here, message) have yet to be acknowledged
255 bool _awayChanged = true;