From: Marcus Eggenberger Date: Wed, 11 Feb 2009 12:50:58 +0000 (+0100) Subject: making away state and user modes persistent X-Git-Tag: 0.4.0~97 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=c5d6b6156d0d360940c45db3ae88bce808dce1ee making away state and user modes persistent --- diff --git a/src/core/SQL/SQLite/14/select_network_awaymsg.sql b/src/core/SQL/SQLite/14/select_network_awaymsg.sql new file mode 100644 index 00000000..8b55cf43 --- /dev/null +++ b/src/core/SQL/SQLite/14/select_network_awaymsg.sql @@ -0,0 +1,3 @@ +SELECT awaymessage +FROM network +WHERE userid = :userid AND networkid = :networkid diff --git a/src/core/SQL/SQLite/14/select_network_usermode.sql b/src/core/SQL/SQLite/14/select_network_usermode.sql new file mode 100644 index 00000000..a6d6a774 --- /dev/null +++ b/src/core/SQL/SQLite/14/select_network_usermode.sql @@ -0,0 +1,3 @@ +SELECT usermode +FROM network +WHERE userid = :userid AND networkid = :networkid \ No newline at end of file diff --git a/src/core/SQL/SQLite/14/update_network_set_awaymsg.sql b/src/core/SQL/SQLite/14/update_network_set_awaymsg.sql new file mode 100644 index 00000000..e0254da5 --- /dev/null +++ b/src/core/SQL/SQLite/14/update_network_set_awaymsg.sql @@ -0,0 +1,3 @@ +UPDATE network +SET awaymessage = :awaymsg +WHERE userid = :userid AND networkid = :networkid diff --git a/src/core/SQL/SQLite/14/update_network_set_usermode.sql b/src/core/SQL/SQLite/14/update_network_set_usermode.sql new file mode 100644 index 00000000..b87c4c8e --- /dev/null +++ b/src/core/SQL/SQLite/14/update_network_set_usermode.sql @@ -0,0 +1,3 @@ +UPDATE network +SET usermode = :usermode +WHERE userid = :userid AND networkid = :networkid \ No newline at end of file diff --git a/src/core/core.h b/src/core/core.h index 53a6a31b..c0916c9b 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -201,6 +201,48 @@ class Core : public QObject { return instance()->storage->setPersistentChannelKey(user, networkId, channel, key); } + //! retrieve last known away message for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + */ + static inline QString awayMessage(UserId user, NetworkId networkId) { + return instance()->storage->awayMessage(user, networkId); + } + + //! Make away message persistent for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + * \param awayMsg The current away message of own user + */ + static inline void setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg) { + return instance()->storage->setAwayMessage(user, networkId, awayMsg); + } + + //! retrieve last known user mode for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + */ + static inline QString userModes(UserId user, NetworkId networkId) { + return instance()->storage->userModes(user, networkId); + } + + //! Make our user modes persistent for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + * \param userModes The current user modes of own user + */ + static inline void setUserModes(UserId user, NetworkId networkId, const QString &userModes) { + return instance()->storage->setUserModes(user, networkId, userModes); + } + //! Get the unique BufferInfo for the given combination of network and buffername for a user. /** \note This method is threadsafe. * diff --git a/src/core/corenetwork.cpp b/src/core/corenetwork.cpp index a40b5464..314f3d29 100644 --- a/src/core/corenetwork.cpp +++ b/src/core/corenetwork.cpp @@ -181,6 +181,16 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason) { _quitRequested = requested; // see socketDisconnected(); _autoReconnectTimer.stop(); _autoReconnectCount = 0; // prohibiting auto reconnect + + IrcUser *me_ = me(); + if(me_) { + QString awayMsg; + if(me_->isAway()) + awayMsg = me_->awayMessage(); + Core::setAwayMessage(userId(), networkId(), awayMsg); + Core::setUserModes(userId(), networkId(), me_->userModes()); + } + displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting.")); if(socket.state() == QAbstractSocket::UnconnectedState) { socketDisconnected(); diff --git a/src/core/sql.qrc b/src/core/sql.qrc index 6e169afb..7c58469a 100644 --- a/src/core/sql.qrc +++ b/src/core/sql.qrc @@ -55,6 +55,8 @@ ./SQL/SQLite/14/select_messagesAllNew.sql ./SQL/SQLite/14/select_messagesNewerThan.sql ./SQL/SQLite/14/select_messagesNewestK.sql + ./SQL/SQLite/14/select_network_awaymsg.sql + ./SQL/SQLite/14/select_network_usermode.sql ./SQL/SQLite/14/select_networkExists.sql ./SQL/SQLite/14/select_networks_for_user.sql ./SQL/SQLite/14/select_nicks.sql @@ -85,6 +87,8 @@ ./SQL/SQLite/14/update_identity.sql ./SQL/SQLite/14/update_network.sql ./SQL/SQLite/14/update_network_connected.sql + ./SQL/SQLite/14/update_network_set_awaymsg.sql + ./SQL/SQLite/14/update_network_set_usermode.sql ./SQL/SQLite/14/update_user_setting.sql ./SQL/SQLite/14/update_username.sql ./SQL/SQLite/14/update_userpassword.sql diff --git a/src/core/sqlitestorage.cpp b/src/core/sqlitestorage.cpp index 17a16d90..003d57a6 100644 --- a/src/core/sqlitestorage.cpp +++ b/src/core/sqlitestorage.cpp @@ -704,6 +704,51 @@ void SqliteStorage::setPersistentChannelKey(UserId user, const NetworkId &networ watchQuery(query); } +QString SqliteStorage::awayMessage(UserId user, NetworkId networkId) { + QSqlQuery query(logDb()); + query.prepare(queryString("select_network_awaymsg")); + query.bindValue(":userid", user.toInt()); + query.bindValue(":networkid", networkId.toInt()); + safeExec(query); + watchQuery(query); + QString awayMsg; + if(query.first()) + awayMsg = query.value(0).toString(); + return awayMsg; +} + +void SqliteStorage::setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg) { + QSqlQuery query(logDb()); + query.prepare(queryString("update_network_set_awaymsg")); + query.bindValue(":userid", user.toInt()); + query.bindValue(":networkid", networkId.toInt()); + query.bindValue(":awaymsg", awayMsg); + safeExec(query); + watchQuery(query); +} + +QString SqliteStorage::userModes(UserId user, NetworkId networkId) { + QSqlQuery query(logDb()); + query.prepare(queryString("select_network_usermode")); + query.bindValue(":userid", user.toInt()); + query.bindValue(":networkid", networkId.toInt()); + safeExec(query); + watchQuery(query); + QString modes; + if(query.first()) + modes = query.value(0).toString(); + return modes; +} + +void SqliteStorage::setUserModes(UserId user, NetworkId networkId, const QString &userModes) { + QSqlQuery query(logDb()); + query.prepare(queryString("update_network_set_usermode")); + query.bindValue(":userid", user.toInt()); + query.bindValue(":networkid", networkId.toInt()); + query.bindValue(":usermode", userModes); + safeExec(query); + watchQuery(query); +} void SqliteStorage::createBuffer(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer) { QSqlQuery query(logDb()); diff --git a/src/core/sqlitestorage.h b/src/core/sqlitestorage.h index 6df95b1b..fbb366f6 100644 --- a/src/core/sqlitestorage.h +++ b/src/core/sqlitestorage.h @@ -73,6 +73,12 @@ public slots: virtual void setChannelPersistent(UserId user, const NetworkId &networkId, const QString &channel, bool isJoined); virtual void setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key); + /* persistent user states */ + virtual QString awayMessage(UserId user, NetworkId networkId); + virtual void setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg); + virtual QString userModes(UserId user, NetworkId networkId); + virtual void setUserModes(UserId user, NetworkId networkId, const QString &userModes); + /* Buffer handling */ virtual BufferInfo bufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer = "", bool create = true); virtual BufferInfo getBufferInfo(UserId user, const BufferId &bufferId); diff --git a/src/core/storage.h b/src/core/storage.h index fb536115..cc3d0393 100644 --- a/src/core/storage.h +++ b/src/core/storage.h @@ -222,7 +222,43 @@ public slots: * \param key The key of the channel (possibly empty) */ virtual void setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key) = 0; - + + //! retrieve last known away message for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + */ + virtual QString awayMessage(UserId user, NetworkId networkId) = 0; + + //! Make away message persistent for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + * \param awayMsg The current away message of own user + */ + virtual void setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg) = 0; + + + //! retrieve last known user mode for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + */ + virtual QString userModes(UserId user, NetworkId networkId) = 0; + + //! Make our user modes persistent for session restore + /** \note This method is threadsafe + * + * \param user The Id of the networks owner + * \param networkId The Id of the network + * \param userModes The current user modes of own user + */ + virtual void setUserModes(UserId user, NetworkId networkId, const QString &userModes) = 0; + + /* Buffer handling */ //! Get the unique BufferInfo for the given combination of network and buffername for a user.