Code review fixes.

This commit is contained in:
Onuray Sahin 2020-12-11 15:08:32 +03:00
parent 752bde413d
commit 60aaa2a39c
3 changed files with 27 additions and 9 deletions

View file

@ -784,19 +784,20 @@ internal class DefaultTimeline(
}
private fun List<TimelineEvent>.filterEventsWithSettings(): List<TimelineEvent> {
return filter {
val filterType = !settings.filters.filterTypes || settings.filters.allowedTypes.map { it.eventType }.contains(it.root.type)
return filter { event ->
val filterType = !settings.filters.filterTypes
|| settings.filters.allowedTypes.any { it.eventType == event.root.type && (it.stateKey == null || it.stateKey == event.root.senderId) }
if (!filterType) return@filter false
val filterEdits = if (settings.filters.filterEdits && it.root.getClearType() == EventType.MESSAGE) {
val messageContent = it.root.getClearContent().toModel<MessageContent>()
val filterEdits = if (settings.filters.filterEdits && event.root.getClearType() == EventType.MESSAGE) {
val messageContent = event.root.getClearContent().toModel<MessageContent>()
messageContent?.relatesTo?.type != RelationType.REPLACE && messageContent?.relatesTo?.type != RelationType.RESPONSE
} else {
true
}
if (!filterEdits) return@filter false
val filterRedacted = settings.filters.filterRedacted && it.root.isRedacted()
val filterRedacted = settings.filters.filterRedacted && event.root.isRedacted()
!filterRedacted
}
}

View file

@ -151,8 +151,25 @@ internal class TimelineHiddenReadReceipts constructor(private val readReceiptsSu
beginGroup()
var needOr = false
if (settings.filters.filterTypes) {
val allowedTypes = settings.filters.allowedTypes.map { it.eventType }.toTypedArray()
not().`in`("${ReadReceiptsSummaryEntityFields.TIMELINE_EVENT}.${TimelineEventEntityFields.ROOT.TYPE}", allowedTypes)
beginGroup()
// Events: A, B, C, D, (E and S1), F, G, (H and S1), I
// Allowed: A, B, C, (E and S1), G, (H and S2)
// Result: D, F, H, I
settings.filters.allowedTypes.forEachIndexed { index, filter ->
if (filter.stateKey == null) {
notEqualTo("${ReadReceiptsSummaryEntityFields.TIMELINE_EVENT}.${TimelineEventEntityFields.ROOT.TYPE}", filter.eventType)
} else {
beginGroup()
notEqualTo("${ReadReceiptsSummaryEntityFields.TIMELINE_EVENT}.${TimelineEventEntityFields.ROOT.TYPE}", filter.eventType)
or()
notEqualTo("${ReadReceiptsSummaryEntityFields.TIMELINE_EVENT}.${TimelineEventEntityFields.ROOT.STATE_KEY}", filter.stateKey)
endGroup()
}
if (index != settings.filters.allowedTypes.size - 1) {
and()
}
}
endGroup()
needOr = true
}
if (settings.filters.filterUseless) {

View file

@ -40,7 +40,7 @@ class TimelineSettingsFactory @Inject constructor(
filterTypes = false),
buildReadReceipts = userPreferencesProvider.shouldShowReadReceipts())
} else {
val allowedTypes = TimelineDisplayableEvents.DISPLAYABLE_TYPES.filterDisplayableTypes()
val allowedTypes = TimelineDisplayableEvents.DISPLAYABLE_TYPES.createAllowedEventTypeFilters()
TimelineSettings(
initialSize = 30,
filters = TimelineEventFilters(
@ -53,7 +53,7 @@ class TimelineSettingsFactory @Inject constructor(
}
}
private fun List<String>.filterDisplayableTypes(): List<EventTypeFilter> {
private fun List<String>.createAllowedEventTypeFilters(): List<EventTypeFilter> {
return map {
EventTypeFilter(
eventType = it,