Improve thread message deletion

Fix thread summary after isLimited events
This commit is contained in:
ariskotsomitopoulos 2022-01-26 14:07:07 +02:00
parent c19b52cded
commit 92d082c26a
6 changed files with 29 additions and 17 deletions

View file

@ -200,6 +200,7 @@ data class Event(
* It will return a decrypted text message or an empty string otherwise.
*/
fun getDecryptedTextSummary(): String? {
if (isRedacted()) return "Message Deleted"
val text = getDecryptedValue() ?: return null
return when {
isReplyRenderedInThread() || isQuote() -> ContentUtils.extractUsefulTextFromReply(text)

View file

@ -41,10 +41,11 @@ private typealias ThreadSummary = Pair<Int, TimelineEventEntity>?
internal fun Map<String, EventEntity>.updateThreadSummaryIfNeeded(
roomId: String,
realm: Realm, currentUserId: String,
chunkEntity: ChunkEntity? = null,
shouldUpdateNotifications: Boolean = true) {
for ((rootThreadEventId, eventEntity) in this) {
eventEntity.threadSummaryInThread(eventEntity.realm, rootThreadEventId)?.let { threadSummary ->
eventEntity.threadSummaryInThread(eventEntity.realm, rootThreadEventId, chunkEntity)?.let { threadSummary ->
val numberOfMessages = threadSummary.first
val latestEventInThread = threadSummary.second
@ -103,7 +104,7 @@ internal fun EventEntity.markEventAsRoot(
* @param rootThreadEventId The root eventId that will find the number of threads
* @return A ThreadSummary containing the counted threads and the latest event message
*/
internal fun EventEntity.threadSummaryInThread(realm: Realm, rootThreadEventId: String): ThreadSummary {
internal fun EventEntity.threadSummaryInThread(realm: Realm, rootThreadEventId: String, chunkEntity: ChunkEntity?): ThreadSummary {
// Number of messages
val messages = TimelineEventEntity
@ -115,7 +116,7 @@ internal fun EventEntity.threadSummaryInThread(realm: Realm, rootThreadEventId:
if (messages <= 0) return null
// Find latest thread event, we know it exists
var chunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: return null
var chunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: chunkEntity ?: return null
var result: TimelineEventEntity? = null
// Iterate the chunk until we find our latest event
@ -125,7 +126,6 @@ internal fun EventEntity.threadSummaryInThread(realm: Realm, rootThreadEventId:
}
chunk = ChunkEntity.find(realm, roomId, nextToken = chunk.prevToken) ?: break
}
result ?: return null
return ThreadSummary(messages, result)

View file

@ -84,7 +84,9 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
// }
val modified = unsignedData.copy(redactedEvent = redactionEvent)
eventToPrune.content = ContentMapper.map(emptyMap())
// I Commented the line below, it should not be empty while we lose all the previous info about
// the redacted event
// eventToPrune.content = ContentMapper.map(emptyMap())
eventToPrune.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified)
eventToPrune.decryptionResultJson = null
eventToPrune.decryptionErrorCode = null

View file

@ -200,7 +200,10 @@ internal class TokenChunkEventPersistor @Inject constructor(
}
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(roomId = roomId, realm = realm, currentUserId = userId)
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(
roomId = roomId,
realm = realm,
currentUserId = userId)
}
}
}

View file

@ -416,7 +416,6 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity
}
}
// Give info to crypto module
cryptoService.onLiveEvent(roomEntity.roomId, event)
@ -443,11 +442,11 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
}
// Handle deletion of [stuck] local echos if needed
deleteLocalEchosIfNeeded(insertType, roomEntity, eventList)
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(
roomId = roomId,
realm = realm,
chunkEntity = chunkEntity,
currentUserId = userId)
}

View file

@ -146,10 +146,17 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen
// We should not display deleted thread messages within the normal timeline
if (root.isRedacted() &&
userPreferencesProvider.areThreadMessagesEnabled() &&
root.threadDetails?.isThread == true){
!isFromThreadTimeline &&
(root.isThread() || root.threadDetails?.isThread == true)){
return true
}
if (root.isRedacted() &&
!userPreferencesProvider.shouldShowRedactedMessages() &&
userPreferencesProvider.areThreadMessagesEnabled() &&
isFromThreadTimeline &&
root.isThread()){
return true
}
if (root.getRelationContent()?.type == RelationType.REPLACE) {
return true