Add a setting to hide redacted events (#951)

This commit is contained in:
Benoit Marty 2020-05-15 10:16:01 +02:00
parent 05d1e64cb5
commit e542e4ba22
9 changed files with 61 additions and 1 deletions

View File

@ -6,6 +6,7 @@ Features ✨:
Improvements 🙌:
- Better connectivity lost indicator when airplane mode is on
- Add a setting to hide redacted events (#951)
Bugfix 🐛:
- Fix issues with FontScale switch (#69, #645)

View File

@ -28,6 +28,10 @@ data class TimelineSettings(
* A flag to filter edit events
*/
val filterEdits: Boolean = false,
/**
* A flag to filter redacted events
*/
val filterRedacted: Boolean = false,
/**
* A flag to filter by types. It should be used with [allowedTypes] field
*/

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2020 New Vector Ltd
*
* 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 im.vector.matrix.android.internal.database.query
internal object UnsignedContent {
internal const val REDACTED_TYPE = """{*"redacted_because":*}"""
}

View File

@ -36,6 +36,7 @@ import im.vector.matrix.android.internal.database.model.RoomEntity
import im.vector.matrix.android.internal.database.model.TimelineEventEntity
import im.vector.matrix.android.internal.database.model.TimelineEventEntityFields
import im.vector.matrix.android.internal.database.query.FilterContent
import im.vector.matrix.android.internal.database.query.UnsignedContent
import im.vector.matrix.android.internal.database.query.findAllInRoomWithSendStates
import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.database.query.whereInRoom
@ -727,6 +728,9 @@ internal class DefaultTimeline(
not().like(TimelineEventEntityFields.ROOT.CONTENT, FilterContent.EDIT_TYPE)
not().like(TimelineEventEntityFields.ROOT.CONTENT, FilterContent.RESPONSE_TYPE)
}
if (settings.filterRedacted) {
not().like(TimelineEventEntityFields.ROOT.UNSIGNED_DATA, UnsignedContent.REDACTED_TYPE)
}
return this
}
@ -737,13 +741,19 @@ internal class DefaultTimeline(
} else {
true
}
if (!filterType) return@filter false
val filterEdits = if (settings.filterEdits && it.root.type == EventType.MESSAGE) {
val messageContent = it.root.content.toModel<MessageContent>()
messageContent?.relatesTo?.type != RelationType.REPLACE
} else {
true
}
filterType && filterEdits
if (!filterEdits) return@filter false
val filterRedacted = settings.filterRedacted && it.root.isRedacted()
filterRedacted
}
}

View File

@ -29,6 +29,10 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences:
return vectorPreferences.showReadReceipts()
}
fun shouldShowRedactedMessages(): Boolean {
return vectorPreferences.showRedactedMessages()
}
fun shouldShowLongClickOnRoomHelp(): Boolean {
return vectorPreferences.shouldShowLongClickOnRoomHelp()
}

View File

@ -99,11 +99,13 @@ class RoomDetailViewModel @AssistedInject constructor(
private val timelineSettings = if (userPreferencesProvider.shouldShowHiddenEvents()) {
TimelineSettings(30,
filterEdits = false,
filterRedacted = userPreferencesProvider.shouldShowRedactedMessages().not(),
filterTypes = false,
buildReadReceipts = userPreferencesProvider.shouldShowReadReceipts())
} else {
TimelineSettings(30,
filterEdits = true,
filterRedacted = userPreferencesProvider.shouldShowRedactedMessages().not(),
filterTypes = true,
allowedTypes = TimelineDisplayableEvents.DISPLAYABLE_TYPES,
buildReadReceipts = userPreferencesProvider.shouldShowReadReceipts())

View File

@ -88,6 +88,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY = "SETTINGS_ALWAYS_SHOW_TIMESTAMPS_KEY"
private const val SETTINGS_12_24_TIMESTAMPS_KEY = "SETTINGS_12_24_TIMESTAMPS_KEY"
private const val SETTINGS_SHOW_READ_RECEIPTS_KEY = "SETTINGS_SHOW_READ_RECEIPTS_KEY"
private const val SETTINGS_SHOW_REDACTED_KEY = "SETTINGS_SHOW_REDACTED_KEY"
private const val SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY = "SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY"
private const val SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY = "SETTINGS_SHOW_AVATAR_DISPLAY_NAME_CHANGES_MESSAGES_KEY"
private const val SETTINGS_VIBRATE_ON_MENTION_KEY = "SETTINGS_VIBRATE_ON_MENTION_KEY"
@ -625,6 +626,15 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return defaultPrefs.getBoolean(SETTINGS_SHOW_READ_RECEIPTS_KEY, true)
}
/**
* Tells if the redacted message should be shown
*
* @return true if the redacted should be shown
*/
fun showRedactedMessages(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_SHOW_REDACTED_KEY, true)
}
/**
* Tells if the help on room list should be shown
*

View File

@ -1564,6 +1564,8 @@ Why choose Riot.im?
<string name="reactions">Reactions</string>
<string name="event_redacted">Message deleted</string>
<string name="settings_show_redacted">Show removed messages</string>
<string name="settings_show_redacted_summary">Show a placeholder for removed messages</string>
<string name="event_redacted_by_user_reason">Event deleted by user</string>
<string name="event_redacted_by_admin_reason">Event moderated by room admin</string>
<string name="last_edited_info_message">Last edited by %1$s on %2$s</string>

View File

@ -70,6 +70,12 @@
android:summary="@string/settings_show_read_receipts_summary"
android:title="@string/settings_show_read_receipts" />
<im.vector.riotx.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:key="SETTINGS_SHOW_REDACTED_KEY"
android:summary="@string/settings_show_redacted_summary"
android:title="@string/settings_show_redacted" />
<im.vector.riotx.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:key="SETTINGS_SHOW_JOIN_LEAVE_MESSAGES_KEY"