diff --git a/app/src/main/java/im/vector/riotredesign/core/extensions/Event.kt b/app/src/main/java/im/vector/riotredesign/core/extensions/Event.kt index 098d1af576..d93877a6bd 100644 --- a/app/src/main/java/im/vector/riotredesign/core/extensions/Event.kt +++ b/app/src/main/java/im/vector/riotredesign/core/extensions/Event.kt @@ -17,12 +17,9 @@ package im.vector.riotredesign.core.extensions import im.vector.matrix.android.api.session.events.model.Event -import org.threeten.bp.Instant +import im.vector.riotredesign.core.resources.DateProvider import org.threeten.bp.LocalDateTime -import org.threeten.bp.ZoneId - fun Event.localDateTime(): LocalDateTime { - val instant = Instant.ofEpochMilli(originServerTs ?: 0) - return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()) + return DateProvider.toLocalDateTime(originServerTs) } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/core/resources/DateProvider.kt b/app/src/main/java/im/vector/riotredesign/core/resources/DateProvider.kt new file mode 100644 index 0000000000..cc01bdf183 --- /dev/null +++ b/app/src/main/java/im/vector/riotredesign/core/resources/DateProvider.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2019 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.riotredesign.core.resources + +import org.threeten.bp.Instant +import org.threeten.bp.LocalDateTime +import org.threeten.bp.ZoneId + +object DateProvider { + + private val zoneId = ZoneId.systemDefault() + + fun toLocalDateTime(timestamp: Long?): LocalDateTime { + val instant = Instant.ofEpochMilli(timestamp ?: 0) + return LocalDateTime.ofInstant(instant, zoneId) + } + +} \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt b/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt index 7ffe463bb1..4fb84ea10d 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/HomeNavigator.kt @@ -30,13 +30,13 @@ class HomeNavigator { var activity: HomeActivity? = null - private var currentRoomId: String? = null + private var rootRoomId: String? = null fun openRoomDetail(roomId: String, eventId: String?, addToBackstack: Boolean = false) { Timber.v("Open room detail $roomId - $eventId - $addToBackstack") - if (!addToBackstack && isRoomOpened(roomId)) { + if (!addToBackstack && isRoot(roomId)) { return } activity?.let { @@ -46,7 +46,7 @@ class HomeNavigator { if (addToBackstack) { it.addFragmentToBackstack(roomDetailFragment, R.id.homeDetailFragmentContainer, roomId) } else { - currentRoomId = roomId + rootRoomId = roomId clearBackStack(it.supportFragmentManager) it.replaceFragment(roomDetailFragment, R.id.homeDetailFragmentContainer) } @@ -61,9 +61,7 @@ class HomeNavigator { Timber.v("Open user detail $userId") } - fun isRoomOpened(roomId: String): Boolean { - return currentRoomId == roomId - } + // Private Methods ***************************************************************************** private fun clearBackStack(fragmentManager: FragmentManager) { if (fragmentManager.backStackEntryCount > 0) { @@ -72,4 +70,8 @@ class HomeNavigator { } } + private fun isRoot(roomId: String): Boolean { + return rootRoomId == roomId + } + } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt index 0d12ae8e45..e610931c48 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt @@ -37,9 +37,6 @@ class TimelineEventController(private val roomId: String, EpoxyAsyncUtil.getAsyncBackgroundHandler(), EpoxyAsyncUtil.getAsyncBackgroundHandler() ) { - init { - setFilterDuplicates(true) - } private var isLoadingForward: Boolean = false private var isLoadingBackward: Boolean = false diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/members/RoomMemberExtractor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/members/RoomMemberExtractor.kt index 5ab8728506..79d4a17686 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/members/RoomMemberExtractor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/members/RoomMemberExtractor.kt @@ -34,22 +34,23 @@ internal class RoomMemberExtractor(private val monarchy: Monarchy, private val cached = HashMap() fun extractFrom(event: EventEntity): RoomMember? { - if (cached.containsKey(event.eventId)) { - return cached[event.eventId] - } val sender = event.sender ?: return null + val cacheKey = sender + event.stateIndex + if (cached.containsKey(cacheKey)) { + return cached[cacheKey] + } // If the event is unlinked we want to fetch unlinked state events val unlinked = event.isUnlinked // When stateIndex is negative, we try to get the next stateEvent prevContent() // If prevContent is null we fallback to the Int.MIN state events content() val content = if (event.stateIndex <= 0) { baseQuery(monarchy, roomId, sender, unlinked).next(from = event.stateIndex)?.prevContent - ?: baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content + ?: baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content } else { baseQuery(monarchy, roomId, sender, unlinked).last(since = event.stateIndex)?.content } val roomMember: RoomMember? = ContentMapper.map(content).toModel() - cached[event.eventId] = roomMember + cached[cacheKey] = roomMember return roomMember }