Merge pull request #2485 from vector-im/feature/ons/fix_hide_state_events
Fix UTD when hiding member state events.
This commit is contained in:
commit
7828e3f501
@ -20,6 +20,7 @@ Bugfix 🐛:
|
|||||||
- Fix cancellation of sending event (#2438)
|
- Fix cancellation of sending event (#2438)
|
||||||
- Double bottomsheet effect after verify with passphrase
|
- Double bottomsheet effect after verify with passphrase
|
||||||
- EditText cursor jumps to the start while typing fast (#2469)
|
- EditText cursor jumps to the start while typing fast (#2469)
|
||||||
|
- UTD for events before invitation if member state events are hidden (#2486)
|
||||||
- No known servers error is given when joining rooms on new Gitter bridge (#2516)
|
- No known servers error is given when joining rooms on new Gitter bridge (#2516)
|
||||||
- Show preview when sending attachment from the keyboard (#2440)
|
- Show preview when sending attachment from the keyboard (#2440)
|
||||||
- Do not compress GIFs (#1616, #1254)
|
- Do not compress GIFs (#1616, #1254)
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.matrix.android.sdk.api.session.room.timeline
|
||||||
|
|
||||||
|
data class EventTypeFilter(
|
||||||
|
/**
|
||||||
|
* Allowed event type.
|
||||||
|
*/
|
||||||
|
val eventType: String,
|
||||||
|
/**
|
||||||
|
* Allowed state key. Set null if you want to allow all events,
|
||||||
|
* otherwise allowed events will be filtered according to the given stateKey.
|
||||||
|
*/
|
||||||
|
val stateKey: String?
|
||||||
|
)
|
@ -36,5 +36,5 @@ data class TimelineEventFilters(
|
|||||||
/**
|
/**
|
||||||
* If [filterTypes] is true, the list of types allowed by the list.
|
* If [filterTypes] is true, the list of types allowed by the list.
|
||||||
*/
|
*/
|
||||||
val allowedTypes: List<String> = emptyList()
|
val allowedTypes: List<EventTypeFilter> = emptyList()
|
||||||
)
|
)
|
||||||
|
@ -71,8 +71,23 @@ internal fun TimelineEventEntity.Companion.latestEvent(realm: Realm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun RealmQuery<TimelineEventEntity>.filterEvents(filters: TimelineEventFilters): RealmQuery<TimelineEventEntity> {
|
internal fun RealmQuery<TimelineEventEntity>.filterEvents(filters: TimelineEventFilters): RealmQuery<TimelineEventEntity> {
|
||||||
if (filters.filterTypes) {
|
if (filters.filterTypes && filters.allowedTypes.isNotEmpty()) {
|
||||||
`in`(TimelineEventEntityFields.ROOT.TYPE, filters.allowedTypes.toTypedArray())
|
beginGroup()
|
||||||
|
filters.allowedTypes.forEachIndexed { index, filter ->
|
||||||
|
if (filter.stateKey == null) {
|
||||||
|
equalTo(TimelineEventEntityFields.ROOT.TYPE, filter.eventType)
|
||||||
|
} else {
|
||||||
|
beginGroup()
|
||||||
|
equalTo(TimelineEventEntityFields.ROOT.TYPE, filter.eventType)
|
||||||
|
and()
|
||||||
|
equalTo(TimelineEventEntityFields.ROOT.STATE_KEY, filter.stateKey)
|
||||||
|
endGroup()
|
||||||
|
}
|
||||||
|
if (index != filters.allowedTypes.size - 1) {
|
||||||
|
or()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endGroup()
|
||||||
}
|
}
|
||||||
if (filters.filterUseless) {
|
if (filters.filterUseless) {
|
||||||
not()
|
not()
|
||||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.summary
|
|||||||
|
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import org.matrix.android.sdk.api.session.room.summary.RoomSummaryConstants
|
import org.matrix.android.sdk.api.session.room.summary.RoomSummaryConstants
|
||||||
|
import org.matrix.android.sdk.api.session.room.timeline.EventTypeFilter
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEventFilters
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEventFilters
|
||||||
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
||||||
import org.matrix.android.sdk.internal.database.query.latestEvent
|
import org.matrix.android.sdk.internal.database.query.latestEvent
|
||||||
@ -26,7 +27,7 @@ internal object RoomSummaryEventsHelper {
|
|||||||
|
|
||||||
private val previewFilters = TimelineEventFilters(
|
private val previewFilters = TimelineEventFilters(
|
||||||
filterTypes = true,
|
filterTypes = true,
|
||||||
allowedTypes = RoomSummaryConstants.PREVIEWABLE_TYPES,
|
allowedTypes = RoomSummaryConstants.PREVIEWABLE_TYPES.map { EventTypeFilter(eventType = it, stateKey = null) },
|
||||||
filterUseless = true,
|
filterUseless = true,
|
||||||
filterRedacted = false,
|
filterRedacted = false,
|
||||||
filterEdits = true
|
filterEdits = true
|
||||||
|
@ -784,19 +784,20 @@ internal class DefaultTimeline(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun List<TimelineEvent>.filterEventsWithSettings(): List<TimelineEvent> {
|
private fun List<TimelineEvent>.filterEventsWithSettings(): List<TimelineEvent> {
|
||||||
return filter {
|
return filter { event ->
|
||||||
val filterType = !settings.filters.filterTypes || settings.filters.allowedTypes.contains(it.root.type)
|
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
|
if (!filterType) return@filter false
|
||||||
|
|
||||||
val filterEdits = if (settings.filters.filterEdits && it.root.getClearType() == EventType.MESSAGE) {
|
val filterEdits = if (settings.filters.filterEdits && event.root.getClearType() == EventType.MESSAGE) {
|
||||||
val messageContent = it.root.getClearContent().toModel<MessageContent>()
|
val messageContent = event.root.getClearContent().toModel<MessageContent>()
|
||||||
messageContent?.relatesTo?.type != RelationType.REPLACE && messageContent?.relatesTo?.type != RelationType.RESPONSE
|
messageContent?.relatesTo?.type != RelationType.REPLACE && messageContent?.relatesTo?.type != RelationType.RESPONSE
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
if (!filterEdits) return@filter false
|
if (!filterEdits) return@filter false
|
||||||
|
|
||||||
val filterRedacted = settings.filters.filterRedacted && it.root.isRedacted()
|
val filterRedacted = settings.filters.filterRedacted && event.root.isRedacted()
|
||||||
!filterRedacted
|
!filterRedacted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,25 @@ internal class TimelineHiddenReadReceipts constructor(private val readReceiptsSu
|
|||||||
beginGroup()
|
beginGroup()
|
||||||
var needOr = false
|
var needOr = false
|
||||||
if (settings.filters.filterTypes) {
|
if (settings.filters.filterTypes) {
|
||||||
val allowedTypes = settings.filters.allowedTypes.toTypedArray()
|
beginGroup()
|
||||||
not().`in`("${ReadReceiptsSummaryEntityFields.TIMELINE_EVENT}.${TimelineEventEntityFields.ROOT.TYPE}", allowedTypes)
|
// 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
|
needOr = true
|
||||||
}
|
}
|
||||||
if (settings.filters.filterUseless) {
|
if (settings.filters.filterUseless) {
|
||||||
|
@ -17,12 +17,17 @@
|
|||||||
package im.vector.app.features.home.room.detail.timeline.helper
|
package im.vector.app.features.home.room.detail.timeline.helper
|
||||||
|
|
||||||
import im.vector.app.core.resources.UserPreferencesProvider
|
import im.vector.app.core.resources.UserPreferencesProvider
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
|
import org.matrix.android.sdk.api.session.room.timeline.EventTypeFilter
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEventFilters
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineEventFilters
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class TimelineSettingsFactory @Inject constructor(private val userPreferencesProvider: UserPreferencesProvider) {
|
class TimelineSettingsFactory @Inject constructor(
|
||||||
|
private val userPreferencesProvider: UserPreferencesProvider,
|
||||||
|
private val session: Session
|
||||||
|
) {
|
||||||
|
|
||||||
fun create(): TimelineSettings {
|
fun create(): TimelineSettings {
|
||||||
return if (userPreferencesProvider.shouldShowHiddenEvents()) {
|
return if (userPreferencesProvider.shouldShowHiddenEvents()) {
|
||||||
@ -35,7 +40,7 @@ class TimelineSettingsFactory @Inject constructor(private val userPreferencesPro
|
|||||||
filterTypes = false),
|
filterTypes = false),
|
||||||
buildReadReceipts = userPreferencesProvider.shouldShowReadReceipts())
|
buildReadReceipts = userPreferencesProvider.shouldShowReadReceipts())
|
||||||
} else {
|
} else {
|
||||||
val allowedTypes = TimelineDisplayableEvents.DISPLAYABLE_TYPES.filterDisplayableTypes()
|
val allowedTypes = TimelineDisplayableEvents.DISPLAYABLE_TYPES.createAllowedEventTypeFilters()
|
||||||
TimelineSettings(
|
TimelineSettings(
|
||||||
initialSize = 30,
|
initialSize = 30,
|
||||||
filters = TimelineEventFilters(
|
filters = TimelineEventFilters(
|
||||||
@ -48,12 +53,12 @@ class TimelineSettingsFactory @Inject constructor(private val userPreferencesPro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<String>.filterDisplayableTypes(): List<String> {
|
private fun List<String>.createAllowedEventTypeFilters(): List<EventTypeFilter> {
|
||||||
return filter { type ->
|
return map {
|
||||||
when (type) {
|
EventTypeFilter(
|
||||||
EventType.STATE_ROOM_MEMBER -> userPreferencesProvider.shouldShowRoomMemberStateEvents()
|
eventType = it,
|
||||||
else -> true
|
stateKey = if (it == EventType.STATE_ROOM_MEMBER && userPreferencesProvider.shouldShowRoomMemberStateEvents()) session.myUserId else null
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user