Skip to content
Snippets Groups Projects
Verified Commit 4b9083d6 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Additional debugging info added

parent 49e28cdd
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -24,14 +24,16 @@ import de.kuschku.libquassel.quassel.syncables.interfaces.IBacklogManager
import de.kuschku.libquassel.session.BacklogStorage
import de.kuschku.libquassel.session.NotificationManager
import de.kuschku.libquassel.session.Session
import de.kuschku.libquassel.util.compatibility.LoggingHandler.Companion.log
import de.kuschku.libquassel.util.compatibility.LoggingHandler.LogLevel.ERROR
class BacklogManager(
private val session: Session,
private val notificationManager: NotificationManager?,
private val backlogStorage: BacklogStorage
) : SyncableObject(session, "BacklogManager"), IBacklogManager {
private val loading = mutableMapOf<BufferId, (List<Message>) -> Unit>()
private val loadingFiltered = mutableMapOf<BufferId, (List<Message>) -> Unit>()
private val loading = mutableMapOf<BufferId, (List<Message>) -> Boolean>()
private val loadingFiltered = mutableMapOf<BufferId, (List<Message>) -> Boolean>()
init {
initialized = true
......@@ -40,7 +42,7 @@ class BacklogManager(
fun updateIgnoreRules() = backlogStorage.updateIgnoreRules(session)
fun requestBacklog(bufferId: BufferId, first: MsgId = -1, last: MsgId = -1, limit: Int = -1,
additional: Int = 0, callback: (List<Message>) -> Unit) {
additional: Int = 0, callback: (List<Message>) -> Boolean) {
if (loading.contains(bufferId)) return
loading[bufferId] = callback
requestBacklog(bufferId, first, last, limit, additional)
......@@ -48,14 +50,14 @@ class BacklogManager(
fun requestBacklogFiltered(bufferId: BufferId, first: MsgId = -1, last: MsgId = -1,
limit: Int = -1, additional: Int = 0, type: Int = -1, flags: Int = -1,
callback: (List<Message>) -> Unit) {
callback: (List<Message>) -> Boolean) {
if (loadingFiltered.contains(bufferId)) return
loadingFiltered[bufferId] = callback
requestBacklogFiltered(bufferId, first, last, limit, additional, type, flags)
}
fun requestBacklogAll(first: MsgId = -1, last: MsgId = -1, limit: Int = -1, additional: Int = 0,
callback: (List<Message>) -> Unit) {
callback: (List<Message>) -> Boolean) {
if (loading.contains(-1)) return
loading[-1] = callback
requestBacklogAll(first, last, limit, additional)
......@@ -63,7 +65,7 @@ class BacklogManager(
fun requestBacklogAllFiltered(first: MsgId = -1, last: MsgId = -1, limit: Int = -1,
additional: Int = 0, type: Int = -1, flags: Int = -1,
callback: (List<Message>) -> Unit) {
callback: (List<Message>) -> Boolean) {
if (loading.contains(-1)) return
loadingFiltered[-1] = callback
requestBacklogAllFiltered(first, last, limit, additional, type, flags)
......@@ -71,25 +73,39 @@ class BacklogManager(
override fun receiveBacklog(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int,
additional: Int, messages: QVariantList) {
backlogStorage.storeMessages(session, messages.mapNotNull(QVariant_::value), initialLoad = true)
loading.remove(bufferId)?.invoke(messages.mapNotNull { it.value<Message?>(null) })
val list = messages.mapNotNull<QVariant_, Message>(QVariant_::value)
if (loading.remove(bufferId)?.invoke(list) == true) {
log(ERROR, "BacklogManager", "storeMessages(${list.size})")
backlogStorage.storeMessages(session, list)
}
}
override fun receiveBacklogAll(first: MsgId, last: MsgId, limit: Int, additional: Int,
messages: QVariantList) {
backlogStorage.storeMessages(session, messages.mapNotNull(QVariant_::value), initialLoad = true)
loading.remove(-1)?.invoke(messages.mapNotNull { it.value<Message?>(null) })
val list = messages.mapNotNull<QVariant_, Message>(QVariant_::value)
if (loading.remove(-1)?.invoke(list) == true) {
log(ERROR, "BacklogManager", "storeMessages(${list.size})")
backlogStorage.storeMessages(session, list)
}
}
override fun receiveBacklogFiltered(bufferId: BufferId, first: MsgId, last: MsgId, limit: Int,
additional: Int, type: Int, flags: Int,
messages: QVariantList) {
loadingFiltered.remove(bufferId)?.invoke(messages.mapNotNull { it.value<Message?>(null) })
val list = messages.mapNotNull<QVariant_, Message>(QVariant_::value)
if (loadingFiltered.remove(bufferId)?.invoke(list) == true) {
log(ERROR, "BacklogManager", "storeMessages(${list.size})")
backlogStorage.storeMessages(session, list)
}
}
override fun receiveBacklogAllFiltered(first: MsgId, last: MsgId, limit: Int, additional: Int,
type: Int, flags: Int, messages: QVariantList) {
loadingFiltered.remove(-1)?.invoke(messages.mapNotNull { it.value<Message?>(null) })
val list = messages.mapNotNull<QVariant_, Message>(QVariant_::value)
if (loadingFiltered.remove(-1)?.invoke(list) == true) {
log(ERROR, "BacklogManager", "storeMessages(${list.size})")
backlogStorage.storeMessages(session, list)
}
}
fun removeBuffer(buffer: BufferId) {
......
......@@ -25,8 +25,8 @@ import de.kuschku.libquassel.protocol.Message
interface BacklogStorage {
fun updateIgnoreRules(session: Session)
fun storeMessages(session: Session, vararg messages: Message, initialLoad: Boolean = false)
fun storeMessages(session: Session, messages: Iterable<Message>, initialLoad: Boolean = false)
fun storeMessages(session: Session, vararg messages: Message)
fun storeMessages(session: Session, messages: Iterable<Message>)
fun clearMessages(bufferId: BufferId, idRange: IntRange)
......
......@@ -55,6 +55,8 @@ interface ISession : Closeable {
val rpcHandler: RpcHandler?
val initStatus: Observable<Pair<Int, Int>>
fun network(networkId: NetworkId): Network?
val proxy: SignalProxy
val error: Flowable<Error>
val lag: Observable<Long>
......@@ -90,6 +92,8 @@ interface ISession : Closeable {
override val initStatus: Observable<Pair<Int, Int>> = Observable.just(0 to 0)
override val lag: Observable<Long> = Observable.just(0L)
override fun network(networkId: NetworkId) = null
override fun login(user: String, pass: String) = Unit
override fun close() = Unit
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment