Thread awareness, map threads events to replies

This commit is contained in:
ariskotsomitopoulos 2021-10-26 18:59:01 +03:00
parent 8f0074911a
commit d1f3e3f958
2 changed files with 13 additions and 6 deletions

View File

@ -363,11 +363,18 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
}
eventIds.add(event.eventId)
if (event.isEncrypted() && insertType != EventInsertType.INITIAL_SYNC) {
val isInitialSync = insertType == EventInsertType.INITIAL_SYNC
if (event.isEncrypted() && !isInitialSync) {
decryptIfNeeded(event, roomId)
}
threadsAwarenessHandler.handleIfNeeded(realm, roomId, event, ::decryptIfNeeded)
threadsAwarenessHandler.handleIfNeeded(
realm = realm,
roomId = roomId,
event = event,
isInitialSync = isInitialSync,
::decryptIfNeeded)
val ageLocalTs = event.unsignedData?.age?.let { syncLocalTimestampMillis - it }
val eventEntity = event.toEntity(roomId, SendState.SYNCED, ageLocalTs).copyToRealmOrIgnore(realm, insertType)

View File

@ -41,7 +41,7 @@ import javax.inject.Inject
/**
* This handler is responsible for a smooth threads migration. It will map all incoming
* threads as replies. So a device without threads enabled/updated will be able to view
* threads response as replies to the orighinal message
* threads response as replies to the original message
*/
internal class ThreadsAwarenessHandler @Inject constructor(
private val permalinkFactory: PermalinkFactory
@ -50,6 +50,7 @@ internal class ThreadsAwarenessHandler @Inject constructor(
fun handleIfNeeded(realm: Realm,
roomId: String,
event: Event,
isInitialSync: Boolean,
decryptIfNeeded: (event: Event, roomId: String) -> Unit) {
if (!isThreadEvent(event)) return
@ -60,9 +61,8 @@ internal class ThreadsAwarenessHandler @Inject constructor(
val rootThreadEventEntity = EventEntity.where(realm, eventId = rootThreadEventId).findFirst() ?: return
val rootThreadEvent = EventMapper.map(rootThreadEventEntity)
val rootThreadEventSenderId = rootThreadEvent.senderId ?: return
val rootThreadEventEventId = rootThreadEvent.eventId ?: return
Timber.i("------> Thread event detected!")
Timber.i("------> Thread event detected! - isInitialSync: $isInitialSync")
if (rootThreadEvent.isEncrypted()) {
decryptIfNeeded(rootThreadEvent, roomId)
@ -70,7 +70,7 @@ internal class ThreadsAwarenessHandler @Inject constructor(
val rootThreadEventBody = getValueFromPayload(rootThreadEvent.mxDecryptionResult?.payload?.toMutableMap(),"body")
val permalink = permalinkFactory.createPermalink(roomId, rootThreadEventEventId, false)
val permalink = permalinkFactory.createPermalink(roomId, rootThreadEventId, false)
val userLink = permalinkFactory.createPermalink(rootThreadEventSenderId, false) ?: ""
val replyFormatted = LocalEchoEventFactory.REPLY_PATTERN.format(