Don't invoke notifications for own messages, fixes #507
[quassel.git] / src / core / corebacklogmanager.cpp
index c7bc8e7..d9f3d90 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -30,10 +30,10 @@ CoreBacklogManager::CoreBacklogManager(CoreSession *coreSession)
 {
 }
 
 {
 }
 
-QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, int limit, int offset) {
+QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, MsgId first, MsgId last, int limit, int additional) {
   QVariantList backlog;
   QList<Message> msgList;
   QVariantList backlog;
   QList<Message> msgList;
-  msgList = Core::requestMsgs(coreSession()->user(), bufferId, limit, offset);
+  msgList = Core::requestMsgs(coreSession()->user(), bufferId, first, last, limit);
 
   QList<Message>::const_iterator msgIter = msgList.constBegin();
   QList<Message>::const_iterator msgListEnd = msgList.constEnd();
 
   QList<Message>::const_iterator msgIter = msgList.constBegin();
   QList<Message>::const_iterator msgListEnd = msgList.constEnd();
@@ -41,5 +41,64 @@ QVariantList CoreBacklogManager::requestBacklog(BufferId bufferId, int limit, in
     backlog << qVariantFromValue(*msgIter);
     msgIter++;
   }
     backlog << qVariantFromValue(*msgIter);
     msgIter++;
   }
+
+  if(additional) {
+    if(first != -1) {
+      last = first;
+    } else {
+      last = -1;
+      if(!msgList.isEmpty()) {
+       if(msgList.first().msgId() < msgList.last().msgId())
+         last = msgList.first().msgId();
+       else
+         last = msgList.last().msgId();
+      }
+    }
+    msgList = Core::requestMsgs(coreSession()->user(), bufferId, -1, last, additional);
+    msgIter = msgList.constBegin();
+    msgListEnd = msgList.constEnd();
+    while(msgIter != msgListEnd) {
+      backlog << qVariantFromValue(*msgIter);
+      msgIter++;
+    }
+  }
+
+  return backlog;
+}
+
+QVariantList CoreBacklogManager::requestBacklogAll(MsgId first, MsgId last, int limit, int additional) {
+  qDebug() << "CoreBacklogManager::requestBacklogAll" << first << last << limit << additional;
+  QVariantList backlog;
+  QList<Message> msgList;
+  msgList = Core::requestAllMsgs(coreSession()->user(), first, last, limit);
+
+  QList<Message>::const_iterator msgIter = msgList.constBegin();
+  QList<Message>::const_iterator msgListEnd = msgList.constEnd();
+  while(msgIter != msgListEnd) {
+    backlog << qVariantFromValue(*msgIter);
+    msgIter++;
+  }
+
+  if(additional) {
+    if(first != -1) {
+      last = first;
+    } else {
+      last = -1;
+      if(!msgList.isEmpty()) {
+       if(msgList.first().msgId() < msgList.last().msgId())
+         last = msgList.first().msgId();
+       else
+         last = msgList.last().msgId();
+      }
+    }
+    msgList = Core::requestAllMsgs(coreSession()->user(), -1, last, additional);
+    msgIter = msgList.constBegin();
+    msgListEnd = msgList.constEnd();
+    while(msgIter != msgListEnd) {
+      backlog << qVariantFromValue(*msgIter);
+      msgIter++;
+    }
+  }
+
   return backlog;
 }
   return backlog;
 }