mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 01:45:52 +03:00
Improve thread message deletion
Fix thread summary after isLimited events
This commit is contained in:
parent
c19b52cded
commit
92d082c26a
6 changed files with 29 additions and 17 deletions
|
@ -200,16 +200,17 @@ data class Event(
|
||||||
* It will return a decrypted text message or an empty string otherwise.
|
* It will return a decrypted text message or an empty string otherwise.
|
||||||
*/
|
*/
|
||||||
fun getDecryptedTextSummary(): String? {
|
fun getDecryptedTextSummary(): String? {
|
||||||
|
if (isRedacted()) return "Message Deleted"
|
||||||
val text = getDecryptedValue() ?: return null
|
val text = getDecryptedValue() ?: return null
|
||||||
return when {
|
return when {
|
||||||
isReplyRenderedInThread() || isQuote() -> ContentUtils.extractUsefulTextFromReply(text)
|
isReplyRenderedInThread() || isQuote() -> ContentUtils.extractUsefulTextFromReply(text)
|
||||||
isFileMessage() -> "sent a file."
|
isFileMessage() -> "sent a file."
|
||||||
isAudioMessage() -> "sent an audio file."
|
isAudioMessage() -> "sent an audio file."
|
||||||
isImageMessage() -> "sent an image."
|
isImageMessage() -> "sent an image."
|
||||||
isVideoMessage() -> "sent a video."
|
isVideoMessage() -> "sent a video."
|
||||||
isSticker() -> "sent a sticker"
|
isSticker() -> "sent a sticker"
|
||||||
isPoll() -> getPollQuestion() ?: "created a poll."
|
isPoll() -> getPollQuestion() ?: "created a poll."
|
||||||
else -> text
|
else -> text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,11 @@ private typealias ThreadSummary = Pair<Int, TimelineEventEntity>?
|
||||||
internal fun Map<String, EventEntity>.updateThreadSummaryIfNeeded(
|
internal fun Map<String, EventEntity>.updateThreadSummaryIfNeeded(
|
||||||
roomId: String,
|
roomId: String,
|
||||||
realm: Realm, currentUserId: String,
|
realm: Realm, currentUserId: String,
|
||||||
|
chunkEntity: ChunkEntity? = null,
|
||||||
shouldUpdateNotifications: Boolean = true) {
|
shouldUpdateNotifications: Boolean = true) {
|
||||||
|
|
||||||
for ((rootThreadEventId, eventEntity) in this) {
|
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 numberOfMessages = threadSummary.first
|
||||||
val latestEventInThread = threadSummary.second
|
val latestEventInThread = threadSummary.second
|
||||||
|
@ -103,7 +104,7 @@ internal fun EventEntity.markEventAsRoot(
|
||||||
* @param rootThreadEventId The root eventId that will find the number of threads
|
* @param rootThreadEventId The root eventId that will find the number of threads
|
||||||
* @return A ThreadSummary containing the counted threads and the latest event message
|
* @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
|
// Number of messages
|
||||||
val messages = TimelineEventEntity
|
val messages = TimelineEventEntity
|
||||||
|
@ -115,7 +116,7 @@ internal fun EventEntity.threadSummaryInThread(realm: Realm, rootThreadEventId:
|
||||||
if (messages <= 0) return null
|
if (messages <= 0) return null
|
||||||
|
|
||||||
// Find latest thread event, we know it exists
|
// 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
|
var result: TimelineEventEntity? = null
|
||||||
|
|
||||||
// Iterate the chunk until we find our latest event
|
// 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
|
chunk = ChunkEntity.find(realm, roomId, nextToken = chunk.prevToken) ?: break
|
||||||
}
|
}
|
||||||
|
|
||||||
result ?: return null
|
result ?: return null
|
||||||
|
|
||||||
return ThreadSummary(messages, result)
|
return ThreadSummary(messages, result)
|
||||||
|
|
|
@ -84,7 +84,9 @@ internal class RedactionEventProcessor @Inject constructor() : EventInsertLivePr
|
||||||
// }
|
// }
|
||||||
|
|
||||||
val modified = unsignedData.copy(redactedEvent = redactionEvent)
|
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.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified)
|
||||||
eventToPrune.decryptionResultJson = null
|
eventToPrune.decryptionResultJson = null
|
||||||
eventToPrune.decryptionErrorCode = null
|
eventToPrune.decryptionErrorCode = null
|
||||||
|
|
|
@ -200,7 +200,10 @@ internal class TokenChunkEventPersistor @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
|
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
|
||||||
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(roomId = roomId, realm = realm, currentUserId = userId)
|
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(
|
||||||
|
roomId = roomId,
|
||||||
|
realm = realm,
|
||||||
|
currentUserId = userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -416,7 +416,6 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||||
optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity
|
optimizedThreadSummaryMap[eventEntity.eventId] = eventEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give info to crypto module
|
// Give info to crypto module
|
||||||
cryptoService.onLiveEvent(roomEntity.roomId, event)
|
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
|
// Handle deletion of [stuck] local echos if needed
|
||||||
deleteLocalEchosIfNeeded(insertType, roomEntity, eventList)
|
deleteLocalEchosIfNeeded(insertType, roomEntity, eventList)
|
||||||
|
|
||||||
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
|
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
|
||||||
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(
|
optimizedThreadSummaryMap.updateThreadSummaryIfNeeded(
|
||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
realm = realm,
|
realm = realm,
|
||||||
|
chunkEntity = chunkEntity,
|
||||||
currentUserId = userId)
|
currentUserId = userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,10 +146,17 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen
|
||||||
// We should not display deleted thread messages within the normal timeline
|
// We should not display deleted thread messages within the normal timeline
|
||||||
if (root.isRedacted() &&
|
if (root.isRedacted() &&
|
||||||
userPreferencesProvider.areThreadMessagesEnabled() &&
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (root.getRelationContent()?.type == RelationType.REPLACE) {
|
if (root.getRelationContent()?.type == RelationType.REPLACE) {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue