making away state and user modes persistent
authorMarcus Eggenberger <egs@quassel-irc.org>
Wed, 11 Feb 2009 12:50:58 +0000 (13:50 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Wed, 11 Feb 2009 12:50:58 +0000 (13:50 +0100)
src/core/SQL/SQLite/14/select_network_awaymsg.sql [new file with mode: 0644]
src/core/SQL/SQLite/14/select_network_usermode.sql [new file with mode: 0644]
src/core/SQL/SQLite/14/update_network_set_awaymsg.sql [new file with mode: 0644]
src/core/SQL/SQLite/14/update_network_set_usermode.sql [new file with mode: 0644]
src/core/core.h
src/core/corenetwork.cpp
src/core/sql.qrc
src/core/sqlitestorage.cpp
src/core/sqlitestorage.h
src/core/storage.h

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 (file)
index 0000000..8b55cf4
--- /dev/null
@@ -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 (file)
index 0000000..a6d6a77
--- /dev/null
@@ -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 (file)
index 0000000..e0254da
--- /dev/null
@@ -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 (file)
index 0000000..b87c4c8
--- /dev/null
@@ -0,0 +1,3 @@
+UPDATE network
+SET usermode = :usermode
+WHERE userid = :userid AND networkid = :networkid
\ No newline at end of file
index 53a6a31..c0916c9 100644 (file)
@@ -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.
    *
index a40b546..314f3d2 100644 (file)
@@ -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();
index 6e169af..7c58469 100644 (file)
@@ -55,6 +55,8 @@
     <file>./SQL/SQLite/14/select_messagesAllNew.sql</file>
     <file>./SQL/SQLite/14/select_messagesNewerThan.sql</file>
     <file>./SQL/SQLite/14/select_messagesNewestK.sql</file>
+    <file>./SQL/SQLite/14/select_network_awaymsg.sql</file>
+    <file>./SQL/SQLite/14/select_network_usermode.sql</file>
     <file>./SQL/SQLite/14/select_networkExists.sql</file>
     <file>./SQL/SQLite/14/select_networks_for_user.sql</file>
     <file>./SQL/SQLite/14/select_nicks.sql</file>
@@ -85,6 +87,8 @@
     <file>./SQL/SQLite/14/update_identity.sql</file>
     <file>./SQL/SQLite/14/update_network.sql</file>
     <file>./SQL/SQLite/14/update_network_connected.sql</file>
+    <file>./SQL/SQLite/14/update_network_set_awaymsg.sql</file>
+    <file>./SQL/SQLite/14/update_network_set_usermode.sql</file>
     <file>./SQL/SQLite/14/update_user_setting.sql</file>
     <file>./SQL/SQLite/14/update_username.sql</file>
     <file>./SQL/SQLite/14/update_userpassword.sql</file>
index 17a16d9..003d57a 100644 (file)
@@ -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());
index 6df95b1..fbb366f 100644 (file)
@@ -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);
index fb53611..cc3d039 100644 (file)
@@ -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.