Timeline: fix some crashes
This commit is contained in:
parent
588e5d6e63
commit
0582d0f641
@ -176,8 +176,8 @@ internal class DefaultTimeline(
|
|||||||
override fun start() {
|
override fun start() {
|
||||||
if (isStarted.compareAndSet(false, true)) {
|
if (isStarted.compareAndSet(false, true)) {
|
||||||
Timber.v("Start timeline for roomId: $roomId and eventId: $initialEventId")
|
Timber.v("Start timeline for roomId: $roomId and eventId: $initialEventId")
|
||||||
eventDecryptor.start()
|
|
||||||
BACKGROUND_HANDLER.post {
|
BACKGROUND_HANDLER.post {
|
||||||
|
eventDecryptor.start()
|
||||||
val realm = Realm.getInstance(realmConfiguration)
|
val realm = Realm.getInstance(realmConfiguration)
|
||||||
backgroundRealm.set(realm)
|
backgroundRealm.set(realm)
|
||||||
clearUnlinkedEvents(realm)
|
clearUnlinkedEvents(realm)
|
||||||
@ -212,7 +212,6 @@ internal class DefaultTimeline(
|
|||||||
isReady.set(false)
|
isReady.set(false)
|
||||||
Timber.v("Dispose timeline for roomId: $roomId and eventId: $initialEventId")
|
Timber.v("Dispose timeline for roomId: $roomId and eventId: $initialEventId")
|
||||||
cancelableBag.cancel()
|
cancelableBag.cancel()
|
||||||
BACKGROUND_HANDLER.removeCallbacksAndMessages(null)
|
|
||||||
BACKGROUND_HANDLER.post {
|
BACKGROUND_HANDLER.post {
|
||||||
roomEntity?.sendingTimelineEvents?.removeAllChangeListeners()
|
roomEntity?.sendingTimelineEvents?.removeAllChangeListeners()
|
||||||
eventRelations.removeAllChangeListeners()
|
eventRelations.removeAllChangeListeners()
|
||||||
@ -225,10 +224,10 @@ internal class DefaultTimeline(
|
|||||||
backgroundRealm.getAndSet(null).also {
|
backgroundRealm.getAndSet(null).also {
|
||||||
it.close()
|
it.close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
eventDecryptor.destroy()
|
eventDecryptor.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun restartWithEventId(eventId: String?) {
|
override fun restartWithEventId(eventId: String?) {
|
||||||
dispose()
|
dispose()
|
||||||
|
@ -23,24 +23,17 @@ import im.vector.riotx.features.home.room.detail.timeline.TimelineEventControlle
|
|||||||
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory
|
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory
|
||||||
import im.vector.riotx.features.home.room.detail.timeline.item.DefaultItem
|
import im.vector.riotx.features.home.room.detail.timeline.item.DefaultItem
|
||||||
import im.vector.riotx.features.home.room.detail.timeline.item.DefaultItem_
|
import im.vector.riotx.features.home.room.detail.timeline.item.DefaultItem_
|
||||||
|
import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DefaultItemFactory @Inject constructor(private val avatarSizeProvider: AvatarSizeProvider,
|
class DefaultItemFactory @Inject constructor(private val avatarSizeProvider: AvatarSizeProvider,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val informationDataFactory: MessageInformationDataFactory) {
|
private val informationDataFactory: MessageInformationDataFactory) {
|
||||||
|
|
||||||
fun create(event: TimelineEvent,
|
fun create(text: String,
|
||||||
|
informationData: MessageInformationData,
|
||||||
highlight: Boolean,
|
highlight: Boolean,
|
||||||
readMarkerVisible: Boolean,
|
callback: TimelineEventController.Callback?): DefaultItem? {
|
||||||
callback: TimelineEventController.Callback?,
|
|
||||||
exception: Exception? = null): DefaultItem? {
|
|
||||||
val text = if (exception == null) {
|
|
||||||
"${event.root.getClearType()} events are not yet handled"
|
|
||||||
} else {
|
|
||||||
"an exception occurred when rendering the event ${event.root.eventId}"
|
|
||||||
}
|
|
||||||
|
|
||||||
val informationData = informationDataFactory.create(event, null, readMarkerVisible)
|
|
||||||
|
|
||||||
return DefaultItem_()
|
return DefaultItem_()
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
@ -52,4 +45,18 @@ class DefaultItemFactory @Inject constructor(private val avatarSizeProvider: Ava
|
|||||||
.readReceiptsCallback(callback)
|
.readReceiptsCallback(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun create(event: TimelineEvent,
|
||||||
|
highlight: Boolean,
|
||||||
|
readMarkerVisible: Boolean,
|
||||||
|
callback: TimelineEventController.Callback?,
|
||||||
|
exception: Exception? = null): DefaultItem? {
|
||||||
|
val text = if (exception == null) {
|
||||||
|
"${event.root.getClearType()} events are not yet handled"
|
||||||
|
} else {
|
||||||
|
"an exception occurred when rendering the event ${event.root.eventId}"
|
||||||
|
}
|
||||||
|
val informationData = informationDataFactory.create(event, null, readMarkerVisible)
|
||||||
|
return create(text, informationData, highlight, callback)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -73,6 +73,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
private val messageInformationDataFactory: MessageInformationDataFactory,
|
private val messageInformationDataFactory: MessageInformationDataFactory,
|
||||||
private val messageItemAttributesFactory: MessageItemAttributesFactory,
|
private val messageItemAttributesFactory: MessageItemAttributesFactory,
|
||||||
private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder,
|
private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder,
|
||||||
|
private val defaultItemFactory: DefaultItemFactory,
|
||||||
private val noticeItemFactory: NoticeItemFactory,
|
private val noticeItemFactory: NoticeItemFactory,
|
||||||
private val avatarSizeProvider: AvatarSizeProvider) {
|
private val avatarSizeProvider: AvatarSizeProvider) {
|
||||||
|
|
||||||
@ -93,11 +94,11 @@ class MessageItemFactory @Inject constructor(
|
|||||||
return buildRedactedItem(attributes, highlight)
|
return buildRedactedItem(attributes, highlight)
|
||||||
}
|
}
|
||||||
|
|
||||||
val messageContent: MessageContent =
|
val messageContent = event.getLastMessageContent()
|
||||||
event.getLastMessageContent()
|
if (messageContent == null) {
|
||||||
?: //Malformed content, we should echo something on screen
|
val malformedText = stringProvider.getString(R.string.malformed_message)
|
||||||
return DefaultItem_().text(stringProvider.getString(R.string.malformed_message))
|
return defaultItemFactory.create(malformedText, informationData, highlight, callback)
|
||||||
|
}
|
||||||
if (messageContent.relatesTo?.type == RelationType.REPLACE
|
if (messageContent.relatesTo?.type == RelationType.REPLACE
|
||||||
|| event.isEncrypted() && event.root.content.toModel<EncryptedEventContent>()?.relatesTo?.type == RelationType.REPLACE
|
|| event.isEncrypted() && event.root.content.toModel<EncryptedEventContent>()?.relatesTo?.type == RelationType.REPLACE
|
||||||
) {
|
) {
|
||||||
@ -124,7 +125,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, highlight, callback, attributes)
|
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
is MessageFileContent -> buildFileMessageItem(messageContent, informationData, highlight, callback, attributes)
|
is MessageFileContent -> buildFileMessageItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, highlight, callback, attributes)
|
is MessageAudioContent -> buildAudioMessageItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
else -> buildNotHandledMessageItem(messageContent, highlight)
|
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,12 +167,12 @@ class MessageItemFactory @Inject constructor(
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildNotHandledMessageItem(messageContent: MessageContent, highlight: Boolean): DefaultItem? {
|
private fun buildNotHandledMessageItem(messageContent: MessageContent,
|
||||||
|
informationData: MessageInformationData,
|
||||||
|
highlight: Boolean,
|
||||||
|
callback: TimelineEventController.Callback?): DefaultItem? {
|
||||||
val text = "${messageContent.type} message events are not yet handled"
|
val text = "${messageContent.type} message events are not yet handled"
|
||||||
return DefaultItem_()
|
return defaultItemFactory.create(text, informationData, highlight, callback)
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
|
||||||
.text(text)
|
|
||||||
.highlighted(highlight)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildImageMessageItem(messageContent: MessageImageContent,
|
private fun buildImageMessageItem(messageContent: MessageImageContent,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user