Properly fix chatlist new entry sorting

parent af9d138d
Pipeline #520 passed with stages
in 32 minutes and 35 seconds
......@@ -497,7 +497,7 @@ class QuasselService : DaggerLifecycleService(),
session.bufferViewManager.requestCreateBufferView(
Defaults.bufferViewConfigInitial(translatedLocale).apply {
for (info in session.bufferSyncer.bufferInfos()) {
handleBuffer(info, session.bufferSyncer, session.networks)
handleBuffer(info, session.bufferSyncer)
}
}.toVariantMap()
)
......
......@@ -191,7 +191,7 @@ object BufferContextPresenter {
true
}
R.id.action_unhide -> {
bufferViewConfig?.insertBufferSorted(info, bufferSyncer, session.networks)
bufferViewConfig?.insertBufferSorted(info, bufferSyncer)
actionMode.finish()
true
}
......
......@@ -245,7 +245,7 @@ class BufferSyncer constructor(
live_bufferInfos.onNext(Unit)
if (oldInfo == null) {
session.bufferViewManager.handleBuffer(info, this, session.networks)
session.bufferViewManager.handleBuffer(info, this)
}
}
}
......@@ -282,7 +282,7 @@ class BufferSyncer constructor(
activity hasFlag Message_Type.Notice ||
activity hasFlag Message_Type.Action) {
bufferInfo(buffer)?.let {
session.bufferViewManager.handleBuffer(it, this, session.networks, true)
session.bufferViewManager.handleBuffer(it, this, true)
}
}
_bufferActivities[buffer] = activity
......
......@@ -325,33 +325,34 @@ class BufferViewConfig constructor(
(a?.bufferViewName() ?: "").compareTo((b?.bufferViewName() ?: ""), true)
}
fun insertBufferSorted(info: BufferInfo, bufferSyncer: BufferSyncer,
networks: Map<NetworkId, Network>) {
if (!_buffers.contains(info.bufferId)) {
requestAddBuffer(
info.bufferId,
sortBuffers(
_buffers.mapNotNull { bufferSyncer.bufferInfo(it) } + info,
sortAlphabetically(),
{ it.bufferName ?: "" },
{ networks[it.networkId]?.networkName() ?: "" },
{ it.type }
).indexOf(info)
)
fun insertBufferSorted(info: BufferInfo, bufferSyncer: BufferSyncer) {
if (sortAlphabetically()) {
var maxBuffer = -1
for (i in 0 until _buffers.size) {
val buffer = bufferSyncer.bufferInfo(_buffers[i])
?: continue
if (buffer.networkId != info.networkId)
continue
if (String.CASE_INSENSITIVE_ORDER.compare(buffer.bufferName, info.bufferName) > 0)
continue
maxBuffer = i
}
requestAddBuffer(info.bufferId, maxBuffer + 1)
} else {
requestAddBuffer(info.bufferId, _buffers.size)
}
}
fun handleBuffer(info: BufferInfo, bufferSyncer: BufferSyncer, networks: Map<NetworkId, Network>,
unhide: Boolean = false) {
fun handleBuffer(info: BufferInfo, bufferSyncer: BufferSyncer, unhide: Boolean = false) {
if (_addNewBuffersAutomatically &&
!_buffers.contains(info.bufferId) &&
!_temporarilyRemovedBuffers.contains(info.bufferId) &&
!_removedBuffers.contains(info.bufferId) &&
!info.type.hasFlag(Buffer_Type.StatusBuffer)) {
insertBufferSorted(info, bufferSyncer, networks)
insertBufferSorted(info, bufferSyncer)
} else if (unhide && !_buffers.contains(info.bufferId) &&
_temporarilyRemovedBuffers.contains(info.bufferId)) {
insertBufferSorted(info, bufferSyncer, networks)
insertBufferSorted(info, bufferSyncer)
}
}
......
......@@ -93,10 +93,9 @@ class BufferViewManager constructor(
private val live_bufferViewConfigs: BehaviorSubject<Set<Int>> = BehaviorSubject.createDefault(
emptySet())
fun handleBuffer(info: BufferInfo, bufferSyncer: BufferSyncer, networks: Map<NetworkId, Network>,
unhide: Boolean = false) {
fun handleBuffer(info: BufferInfo, bufferSyncer: BufferSyncer, unhide: Boolean = false) {
for (bufferViewConfig in bufferViewConfigs()) {
bufferViewConfig.handleBuffer(info, bufferSyncer, networks, unhide)
bufferViewConfig.handleBuffer(info, bufferSyncer, unhide)
}
}
......
......@@ -280,7 +280,7 @@ class Session(
initCallback?.invoke(this)
for (config in bufferViewManager.bufferViewConfigs()) {
for (info in bufferSyncer.bufferInfos()) {
config.handleBuffer(info, bufferSyncer, networks)
config.handleBuffer(info, bufferSyncer)
}
}
notificationManager?.init(this)
......
......@@ -43,7 +43,7 @@ class BufferViewConfigTest {
val bufferViewConfig = bufferViewManager.bufferViewConfig(0)!!
ensure {
bufferViewConfig.insertBufferSorted(bufferSyncer.bufferInfo(BufferId(4))!!, bufferSyncer, networks)
bufferViewConfig.insertBufferSorted(bufferSyncer.bufferInfo(BufferId(4))!!, bufferSyncer)
}.does {
callSync(bufferViewConfig, "requestAddBuffer", listOf(
QVariant_.of(BufferId(4), QType.BufferId),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment