Skip to content
Snippets Groups Projects
Commit 1275a9d7 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Improved buffer activity tracking

- cleaned up code
- clicking a buffer now properly dimisses activity in it
parent d65bf005
No related branches found
No related tags found
No related merge requests found
...@@ -78,12 +78,13 @@ class BufferViewConfigFragment : ServiceBoundFragment() { ...@@ -78,12 +78,13 @@ class BufferViewConfigFragment : ServiceBoundFragment() {
chatList.adapter = BufferListAdapter( chatList.adapter = BufferListAdapter(
this, this,
viewModel.bufferList.zip(database.filtered().listen(accountId)).map { viewModel.bufferList.zip(database.filtered().listen(accountId)).map {
val (list, activityList) = it val (data, activityList) = it
val (config, list) = data ?: Pair(null, emptyList())
val minimumActivity = config?.minimumActivity() ?: Buffer_Activity.NONE
val activities = activityList.map { it.bufferId to it.filtered }.toMap() val activities = activityList.map { it.bufferId to it.filtered }.toMap()
list list.map {
?.map {
val activity = it.activity - (activities[it.info.bufferId] ?: 0) val activity = it.activity - (activities[it.info.bufferId] ?: 0)
it.bufferActivity to it.copy( it.copy(
description = ircFormatDeserializer?.formatString( description = ircFormatDeserializer?.formatString(
it.description.toString(), appearanceSettings.colorizeMirc it.description.toString(), appearanceSettings.colorizeMirc
) ?: it.description, ) ?: it.description,
...@@ -99,11 +100,9 @@ class BufferViewConfigFragment : ServiceBoundFragment() { ...@@ -99,11 +100,9 @@ class BufferViewConfigFragment : ServiceBoundFragment() {
} }
) )
) )
}?.filter { (minimumActivity, props) -> }.filter { props ->
minimumActivity.toInt() <= props.bufferActivity.toInt() || minimumActivity.toInt() <= props.bufferActivity.toInt() ||
props.info.type.hasFlag(Buffer_Type.StatusBuffer) props.info.type.hasFlag(Buffer_Type.StatusBuffer)
}?.map { (_, props) ->
props
} }
}, },
handlerThread::post, handlerThread::post,
......
...@@ -110,8 +110,11 @@ class MessageListFragment : ServiceBoundFragment() { ...@@ -110,8 +110,11 @@ class MessageListFragment : ServiceBoundFragment() {
val session = it?.first val session = it?.first
val buffer = it?.second val buffer = it?.second
val bufferSyncer = session?.bufferSyncer val bufferSyncer = session?.bufferSyncer
if (buffer != null && bufferSyncer != null && buffer != previous) { if (buffer != null && bufferSyncer != null) {
markAsRead(bufferSyncer, buffer, messageId)
if (buffer != previous) {
onBufferChange(previous, buffer, messageId, bufferSyncer) onBufferChange(previous, buffer, messageId, bufferSyncer)
}
lastBuffer = buffer lastBuffer = buffer
} }
} }
...@@ -147,15 +150,17 @@ class MessageListFragment : ServiceBoundFragment() { ...@@ -147,15 +150,17 @@ class MessageListFragment : ServiceBoundFragment() {
return view return view
} }
private fun markAsRead(bufferSyncer: BufferSyncer, buffer: BufferId, lastMessageId: MsgId?) {
bufferSyncer.requestMarkBufferAsRead(buffer)
if (lastMessageId != null)
bufferSyncer.requestSetLastSeenMsg(buffer, lastMessageId)
}
private fun onBufferChange(previous: BufferId?, current: BufferId, lastMessageId: MsgId?, private fun onBufferChange(previous: BufferId?, current: BufferId, lastMessageId: MsgId?,
bufferSyncer: BufferSyncer) { bufferSyncer: BufferSyncer) {
if (lastMessageId != null) { if (previous != null && lastMessageId != null) {
bufferSyncer.requestMarkBufferAsRead(current)
bufferSyncer.requestSetLastSeenMsg(current, lastMessageId)
if (previous != null) {
bufferSyncer.requestSetMarkerLine(previous, lastMessageId) bufferSyncer.requestSetMarkerLine(previous, lastMessageId)
} }
}
// Try loading messages when switching to isEmpty buffer // Try loading messages when switching to isEmpty buffer
if (database.message().bufferSize(current) == 0) { if (database.message().bufferSize(current) == 0) {
loadMore() loadMore()
......
...@@ -206,7 +206,9 @@ class QuasselViewModel : ViewModel() { ...@@ -206,7 +206,9 @@ class QuasselViewModel : ViewModel() {
} }
} }
val bufferList = session.zip(bufferViewConfig).switchMapRx { (session, config) -> val bufferList: LiveData<Pair<BufferViewConfig?, List<BufferListAdapter.BufferProps>>?> = session.zip(
bufferViewConfig
).switchMapRx { (session, config) ->
val bufferSyncer = session?.bufferSyncer val bufferSyncer = session?.bufferSyncer
if (bufferSyncer != null && config != null) { if (bufferSyncer != null && config != null) {
config.live_config.debounce(16, TimeUnit.MILLISECONDS).switchMap { currentConfig -> config.live_config.debounce(16, TimeUnit.MILLISECONDS).switchMap { currentConfig ->
...@@ -248,8 +250,7 @@ class QuasselViewModel : ViewModel() { ...@@ -248,8 +250,7 @@ class QuasselViewModel : ViewModel() {
}, },
description = realName, description = realName,
activity = activity, activity = activity,
highlights = highlights, highlights = highlights
bufferActivity = config.minimumActivity()
) )
} }
} }
...@@ -269,8 +270,7 @@ class QuasselViewModel : ViewModel() { ...@@ -269,8 +270,7 @@ class QuasselViewModel : ViewModel() {
}, },
description = topic, description = topic,
activity = activity, activity = activity,
highlights = highlights, highlights = highlights
bufferActivity = config.minimumActivity()
) )
} }
} }
...@@ -283,8 +283,7 @@ class QuasselViewModel : ViewModel() { ...@@ -283,8 +283,7 @@ class QuasselViewModel : ViewModel() {
bufferStatus = BufferListAdapter.BufferStatus.OFFLINE, bufferStatus = BufferListAdapter.BufferStatus.OFFLINE,
description = "", description = "",
activity = activity, activity = activity,
highlights = highlights, highlights = highlights
bufferActivity = config.minimumActivity()
) )
} }
} }
...@@ -295,8 +294,7 @@ class QuasselViewModel : ViewModel() { ...@@ -295,8 +294,7 @@ class QuasselViewModel : ViewModel() {
bufferStatus = BufferListAdapter.BufferStatus.OFFLINE, bufferStatus = BufferListAdapter.BufferStatus.OFFLINE,
description = "", description = "",
activity = activity, activity = activity,
highlights = highlights, highlights = highlights
bufferActivity = config.minimumActivity()
) )
) )
} }
...@@ -307,17 +305,21 @@ class QuasselViewModel : ViewModel() { ...@@ -307,17 +305,21 @@ class QuasselViewModel : ViewModel() {
} }
} }
).map { list -> ).map { list ->
Pair<BufferViewConfig?, List<BufferListAdapter.BufferProps>>(
config,
list.filter { list.filter {
(!config.hideInactiveBuffers()) || (!config.hideInactiveBuffers()) ||
it.bufferStatus != BufferListAdapter.BufferStatus.OFFLINE || it.bufferStatus != BufferListAdapter.BufferStatus.OFFLINE ||
it.info.type.hasFlag(Buffer_Type.StatusBuffer) it.info.type.hasFlag(Buffer_Type.StatusBuffer)
} })
} }
} }
} }
} }
} else { } else {
Observable.just(emptyList()) Observable.just(
Pair<BufferViewConfig?, List<BufferListAdapter.BufferProps>>(null, emptyList())
)
} }
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment