fixing a big oopsie that would cause the creation of a new empty buffer on any observ...
[quassel.git] / src / client / clientbacklogmanager.cpp
index 8cf2af4..742d305 100644 (file)
@@ -35,13 +35,8 @@ ClientBacklogManager::ClientBacklogManager(QObject *parent)
 {
 }
 
-void ClientBacklogManager::receiveBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, QVariantList msgs) {
-  Q_UNUSED(first)
-  Q_UNUSED(last)
-  Q_UNUSED(limit)
-
-  if(msgs.isEmpty())
-    return;
+void ClientBacklogManager::receiveBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, int additional, QVariantList msgs) {
+  Q_UNUSED(first) Q_UNUSED(last) Q_UNUSED(limit) Q_UNUSED(additional)
 
   emit messagesReceived(bufferId, msgs.count());
 
@@ -56,12 +51,27 @@ void ClientBacklogManager::receiveBacklog(BufferId bufferId, MsgId first, MsgId
     if(!_requester->buffer(bufferId, msglist)) {
       // this was the last part to buffer
       stopBuffering();
+      reset();
     }
   } else {
     dispatchMessages(msglist);
   }
 }
 
+void ClientBacklogManager::receiveBacklogAll(MsgId first, MsgId last, int limit, int additional, QVariantList msgs) {
+  Q_UNUSED(first) Q_UNUSED(last) Q_UNUSED(limit) Q_UNUSED(additional)
+
+  MessageList msglist;
+  foreach(QVariant v, msgs) {
+    Message msg = v.value<Message>();
+    msg.setFlags(msg.flags() | Message::Backlog);
+    msglist << msg;
+  }
+
+  dispatchMessages(msglist);
+  reset();
+}
+
 void ClientBacklogManager::requestInitialBacklog() {
   if(_requester) {
     qWarning() << "ClientBacklogManager::requestInitialBacklog() called twice in the same session! (Backlog has already been requested)";
@@ -71,7 +81,11 @@ void ClientBacklogManager::requestInitialBacklog() {
   BacklogSettings settings;
   switch(settings.requesterType()) {
   case BacklogRequester::GlobalUnread:
+    _requester = new GlobalUnreadBacklogRequester(this);
+    break;
   case BacklogRequester::PerBufferUnread:
+    _requester = new PerBufferUnreadBacklogRequester(this);
+    break;
   case BacklogRequester::PerBufferFixed:
   default:
     _requester = new FixedBacklogRequester(this);
@@ -84,7 +98,6 @@ void ClientBacklogManager::stopBuffering() {
   Q_ASSERT(_requester);
 
   dispatchMessages(_requester->bufferedMessages(), true);
-  reset();
 }
 
 bool ClientBacklogManager::isBuffering() {