From e41dc33f23efba47c2445260a9bb2138b573679c Mon Sep 17 00:00:00 2001
From: Janne Mareike Koschinski <janne@kuschku.de>
Date: Tue, 1 Mar 2022 19:06:53 +0100
Subject: [PATCH] fix: correct issue with backlog loading

---
 build.gradle.kts                              |  2 +-
 .../client/syncables/ClientBacklogManager.kt  | 13 ++--
 .../syncables/StatefulSyncableStub.kt         |  8 +++
 .../syncables/stubs/BacklogManagerStub.kt     | 68 +++++++++++++++++++
 4 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/build.gradle.kts b/build.gradle.kts
index fe4a4e5..c6142b2 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -15,4 +15,4 @@ plugins {
 }
 
 group = "de.justjanne.libquassel"
-version = "0.9.1"
+version = "0.9.2"
diff --git a/libquassel-client/src/main/kotlin/de/justjanne/libquassel/client/syncables/ClientBacklogManager.kt b/libquassel-client/src/main/kotlin/de/justjanne/libquassel/client/syncables/ClientBacklogManager.kt
index 31f88e4..7d19179 100644
--- a/libquassel-client/src/main/kotlin/de/justjanne/libquassel/client/syncables/ClientBacklogManager.kt
+++ b/libquassel-client/src/main/kotlin/de/justjanne/libquassel/client/syncables/ClientBacklogManager.kt
@@ -9,6 +9,7 @@
 
 package de.justjanne.libquassel.client.syncables
 
+import de.justjanne.bitflags.none
 import de.justjanne.bitflags.of
 import de.justjanne.bitflags.toBits
 import de.justjanne.libquassel.client.util.CoroutineKeyedQueue
@@ -48,8 +49,8 @@ class ClientBacklogManager(
     last: MsgId = MsgId(-1),
     limit: Int = -1,
     additional: Int = 0,
-    type: MessageTypes = MessageType.all,
-    flags: MessageFlags = MessageFlag.all
+    type: MessageTypes = MessageType.none(),
+    flags: MessageFlags = MessageFlag.none()
   ): QVariantList =
     bufferFilteredQueue.wait(BacklogData.BufferFiltered(bufferId, first, last, limit, additional, type, flags)) {
       requestBacklogFiltered(bufferId, first, last, limit, additional, type.toBits().toInt(), flags.toBits().toInt())
@@ -60,8 +61,8 @@ class ClientBacklogManager(
     first: MsgId = MsgId(-1),
     last: MsgId = MsgId(-1),
     limit: Int = -1,
-    type: MessageTypes = MessageType.all,
-    flags: MessageFlags = MessageFlag.all
+    type: MessageTypes = MessageType.none(),
+    flags: MessageFlags = MessageFlag.none()
   ): QVariantList =
     bufferForwardQueue.wait(BacklogData.BufferForward(bufferId, first, last, limit, type, flags)) {
       requestBacklogForward(bufferId, first, last, limit, type.toBits().toInt(), flags.toBits().toInt())
@@ -82,8 +83,8 @@ class ClientBacklogManager(
     last: MsgId = MsgId(-1),
     limit: Int = -1,
     additional: Int = 0,
-    type: MessageTypes = MessageType.all,
-    flags: MessageFlags = MessageFlag.all
+    type: MessageTypes = MessageType.none(),
+    flags: MessageFlags = MessageFlag.none()
   ): QVariantList =
     allFilteredQueue.wait(BacklogData.AllFiltered(first, last, limit, additional, type, flags)) {
       requestBacklogAllFiltered(first, last, limit, additional, type.toBits().toInt(), flags.toBits().toInt())
diff --git a/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/StatefulSyncableStub.kt b/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/StatefulSyncableStub.kt
index 7ce9fac..db413bf 100644
--- a/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/StatefulSyncableStub.kt
+++ b/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/StatefulSyncableStub.kt
@@ -18,6 +18,10 @@ interface StatefulSyncableStub : SyncableStub {
   fun fromVariantMap(properties: QVariantMap)
   fun toVariantMap(): QVariantMap
 
+  /**
+   * Replaces all properties of the object with the content of the
+   * "properties" parameter. This parameter is in network representation.
+   */
   fun update(properties: QVariantMap) {
     fromVariantMap(properties)
     sync(
@@ -27,6 +31,10 @@ interface StatefulSyncableStub : SyncableStub {
     )
   }
 
+  /**
+   * Replaces all properties of the object with the content of the
+   * "properties" parameter. This parameter is in network representation.
+   */
   fun requestUpdate(properties: QVariantMap = toVariantMap()) {
     sync(
       target = ProtocolSide.CORE,
diff --git a/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/stubs/BacklogManagerStub.kt b/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/stubs/BacklogManagerStub.kt
index 694ebd5..707a9b6 100644
--- a/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/stubs/BacklogManagerStub.kt
+++ b/libquassel-protocol/src/main/kotlin/de/justjanne/libquassel/protocol/syncables/stubs/BacklogManagerStub.kt
@@ -22,6 +22,15 @@ import de.justjanne.libquassel.protocol.variant.qVariant
 
 @SyncedObject("BacklogManager")
 interface BacklogManagerStub : SyncableStub {
+  /**
+   * Loads backlog for [bufferId], where the message id is >= [first] and < [last].
+   * If [first] or [last] is unset, the list will be unbounded in that direction.
+   *
+   * If a [limit] is set, the list will be truncated to the newest N messages.
+   *
+   * If both [first] and [last] are set, and the list of messages is not truncated by [limit],
+   * [additional] messages will be loaded before [last].
+   */
   @SyncedCall(target = ProtocolSide.CORE)
   fun requestBacklog(
     bufferId: BufferId,
@@ -41,6 +50,17 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Loads backlog for [bufferId], where the message id is >= [first] and < [last].
+   * If [first] or [last] is unset, the list will be unbounded in that direction.
+   *
+   * If a [limit] is set, the list will be truncated to the newest N messages.
+   *
+   * If both [first] and [last] are set, and the list of messages is not truncated by [limit],
+   * [additional] messages will be loaded before [last].
+   *
+   * Only messages matching [type] and [flags] will be returned and counted.
+   */
   @SyncedCall(target = ProtocolSide.CORE)
   fun requestBacklogFiltered(
     bufferId: BufferId,
@@ -64,6 +84,14 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Loads backlog for [bufferId], where the message id is >= [first] and < [last].
+   * If [first] or [last] is unset, the list will be unbounded in that direction.
+   *
+   * If a [limit] is set, the list will be truncated to the oldest N messages.
+   *
+   * Only messages matching [type] and [flags] will be returned and counted.
+   */
   @SyncedCall(target = ProtocolSide.CORE)
   fun requestBacklogForward(
     bufferId: BufferId,
@@ -85,6 +113,15 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Loads backlog for all buffers, where the message id is >= [first] and < [last].
+   * If [first] or [last] is unset, the list will be unbounded in that direction.
+   *
+   * If a [limit] is set, the list will be truncated to the newest N messages.
+   *
+   * If both [first] and [last] are set, and the list of messages is not truncated by [limit],
+   * [additional] messages will be loaded before [last].
+   */
   @SyncedCall(target = ProtocolSide.CORE)
   fun requestBacklogAll(
     first: MsgId = MsgId(-1),
@@ -102,6 +139,17 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Loads backlog for all buffers, where the message id is >= [first] and < [last].
+   * If [first] or [last] is unset, the list will be unbounded in that direction.
+   *
+   * If a [limit] is set, the list will be truncated to the newest N messages.
+   *
+   * If both [first] and [last] are set, and the list of messages is not truncated by [limit],
+   * [additional] messages will be loaded before [last].
+   *
+   * Only messages matching [type] and [flags] will be returned and counted.
+   */
   @SyncedCall(target = ProtocolSide.CORE)
   fun requestBacklogAllFiltered(
     first: MsgId = MsgId(-1),
@@ -123,6 +171,10 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Response to the corresponding [requestBacklog] call.
+   * [messages] contains the messages as `QVariant<Message>`
+   */
   @SyncedCall(target = ProtocolSide.CLIENT)
   fun receiveBacklog(
     bufferId: BufferId,
@@ -144,6 +196,10 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Response to the corresponding [requestBacklogFiltered] call.
+   * [messages] contains the messages as `QVariant<Message>`
+   */
   @SyncedCall(target = ProtocolSide.CLIENT)
   fun receiveBacklogFiltered(
     bufferId: BufferId,
@@ -169,6 +225,10 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Response to the corresponding [requestBacklogForward] call.
+   * [messages] contains the messages as `QVariant<Message>`
+   */
   @SyncedCall(target = ProtocolSide.CLIENT)
   fun receiveBacklogForward(
     bufferId: BufferId,
@@ -192,6 +252,10 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Response to the corresponding [requestBacklogAll] call.
+   * [messages] contains the messages as `QVariant<Message>`
+   */
   @SyncedCall(target = ProtocolSide.CLIENT)
   fun receiveBacklogAll(
     first: MsgId = MsgId(-1),
@@ -211,6 +275,10 @@ interface BacklogManagerStub : SyncableStub {
     )
   }
 
+  /**
+   * Response to the corresponding [requestBacklogAllFiltered] call.
+   * [messages] contains the messages as `QVariant<Message>`
+   */
   @SyncedCall(target = ProtocolSide.CLIENT)
   fun receiveBacklogAllFiltered(
     first: MsgId = MsgId(-1),
-- 
GitLab