mirror of
https://github.com/vector-im/riotX-android
synced 2025-10-06 00:02:48 +02:00
Compare commits
1 Commits
v1.5.8
...
feature/ar
Author | SHA1 | Date | |
---|---|---|---|
|
d7de38c2c1 |
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* 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 org.matrix.android.sdk.api.session.room.threads
|
||||
|
||||
data class FetchRootThreadsResult(
|
||||
// List of fetched Events, most recent first
|
||||
val events: List<RootThreadEvent>,
|
||||
// token to get more events
|
||||
val nextToken: String,
|
||||
// True if there are more event to load
|
||||
val hasMore: Boolean
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* 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 org.matrix.android.sdk.api.session.room.threads
|
||||
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent
|
||||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo
|
||||
|
||||
data class RootThreadEvent(
|
||||
val root: Event,
|
||||
val eventId: String,
|
||||
val senderInfo: SenderInfo?
|
||||
)
|
@@ -64,4 +64,12 @@ interface ThreadsService {
|
||||
* @param rootThreadEventId the root eventId of the current thread
|
||||
*/
|
||||
suspend fun markThreadAsRead(rootThreadEventId: String)
|
||||
|
||||
|
||||
/**
|
||||
* Fetches a list of thread root TimelineEvents that exists at the room level
|
||||
* @param numberOfEvents indicates the number of the events to fetch
|
||||
* @param since indicates the token that our filtering will start
|
||||
*/
|
||||
suspend fun fetchAllThreads(numberOfEvents: Int, since: String?): FetchRootThreadsResult
|
||||
}
|
||||
|
@@ -17,9 +17,18 @@
|
||||
package org.matrix.android.sdk.internal.session.filter
|
||||
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.RelationType
|
||||
|
||||
internal object FilterFactory {
|
||||
|
||||
fun createThreadsFilter(numberOfEvents: Int): RoomEventFilter {
|
||||
return RoomEventFilter(
|
||||
limit = numberOfEvents,
|
||||
types = listOf(EventType.MESSAGE),
|
||||
relationTypes = listOf(RelationType.IO_THREAD)
|
||||
)
|
||||
}
|
||||
|
||||
fun createUploadsFilter(numberOfEvents: Int): RoomEventFilter {
|
||||
return RoomEventFilter(
|
||||
limit = numberOfEvents,
|
||||
|
@@ -87,6 +87,8 @@ import org.matrix.android.sdk.internal.session.room.tags.AddTagToRoomTask
|
||||
import org.matrix.android.sdk.internal.session.room.tags.DefaultAddTagToRoomTask
|
||||
import org.matrix.android.sdk.internal.session.room.tags.DefaultDeleteTagFromRoomTask
|
||||
import org.matrix.android.sdk.internal.session.room.tags.DeleteTagFromRoomTask
|
||||
import org.matrix.android.sdk.internal.session.room.threads.DefaultFetchRootThreadsTask
|
||||
import org.matrix.android.sdk.internal.session.room.threads.FetchRootThreadsTask
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.DefaultFetchTokenAndPaginateTask
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.DefaultGetContextOfEventTask
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.DefaultGetEventTask
|
||||
@@ -265,6 +267,9 @@ internal abstract class RoomModule {
|
||||
@Binds
|
||||
abstract fun bindGetUploadsTask(task: DefaultGetUploadsTask): GetUploadsTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindFetchRootThreadsTask(task: DefaultFetchRootThreadsTask): FetchRootThreadsTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindAddTagToRoomTask(task: DefaultAddTagToRoomTask): AddTagToRoomTask
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.session.room.threads.FetchRootThreadsResult
|
||||
import org.matrix.android.sdk.api.session.room.threads.ThreadsService
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
import org.matrix.android.sdk.api.session.threads.ThreadNotificationState
|
||||
@@ -42,6 +43,7 @@ internal class DefaultThreadsService @AssistedInject constructor(
|
||||
@UserId private val userId: String,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val timelineEventMapper: TimelineEventMapper,
|
||||
private val fetchRootThreadsTask: FetchRootThreadsTask
|
||||
) : ThreadsService {
|
||||
|
||||
@AssistedFactory
|
||||
@@ -100,4 +102,12 @@ internal class DefaultThreadsService @AssistedInject constructor(
|
||||
eventId = rootThreadEventId).findFirst()?.threadNotificationState = ThreadNotificationState.NO_NEW_MESSAGE
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun fetchAllThreads(numberOfEvents: Int, since: String?): FetchRootThreadsResult {
|
||||
return fetchRootThreadsTask.execute(
|
||||
FetchRootThreadsTask.Params(
|
||||
roomId = roomId,
|
||||
since = since,
|
||||
numberOfEvents = numberOfEvents))
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* 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 org.matrix.android.sdk.internal.session.room.threads
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageWithAttachmentContent
|
||||
import org.matrix.android.sdk.api.session.room.sender.SenderInfo
|
||||
import org.matrix.android.sdk.api.session.room.threads.FetchRootThreadsResult
|
||||
import org.matrix.android.sdk.api.session.room.threads.RootThreadEvent
|
||||
import org.matrix.android.sdk.api.session.room.uploads.GetUploadsResult
|
||||
import org.matrix.android.sdk.api.session.room.uploads.UploadEvent
|
||||
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
||||
import org.matrix.android.sdk.internal.database.model.EventEntity
|
||||
import org.matrix.android.sdk.internal.database.model.EventEntityFields
|
||||
import org.matrix.android.sdk.internal.database.query.TimelineEventFilter
|
||||
import org.matrix.android.sdk.internal.database.query.whereType
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.filter.FilterFactory
|
||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||
import org.matrix.android.sdk.internal.session.room.membership.RoomMemberHelper
|
||||
import org.matrix.android.sdk.internal.session.room.timeline.PaginationDirection
|
||||
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface FetchRootThreadsTask : Task<FetchRootThreadsTask.Params, FetchRootThreadsResult> {
|
||||
|
||||
data class Params(
|
||||
val roomId: String,
|
||||
val numberOfEvents: Int,
|
||||
val since: String?
|
||||
)
|
||||
}
|
||||
|
||||
internal class DefaultFetchRootThreadsTask @Inject constructor(
|
||||
private val roomAPI: RoomAPI,
|
||||
private val tokenStore: SyncTokenStore,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val globalErrorReceiver: GlobalErrorReceiver
|
||||
) : FetchRootThreadsTask {
|
||||
|
||||
override suspend fun execute(params: FetchRootThreadsTask.Params): FetchRootThreadsResult {
|
||||
val result: FetchRootThreadsResult
|
||||
|
||||
val filter = FilterFactory.createThreadsFilter(params.numberOfEvents).toJSONString()
|
||||
val since = params.since ?: tokenStore.getLastToken() ?: throw IllegalStateException("No token available")
|
||||
|
||||
val chunk = executeRequest(globalErrorReceiver) {
|
||||
roomAPI.getRoomMessagesFrom(params.roomId, since, PaginationDirection.BACKWARDS.value, params.numberOfEvents, filter)
|
||||
}
|
||||
result = FetchRootThreadsResult(
|
||||
events = chunk.events.map {
|
||||
RootThreadEvent(it, it.eventId!!, null)
|
||||
},
|
||||
nextToken = chunk.end ?: "",
|
||||
hasMore = chunk.hasMore()
|
||||
)
|
||||
return result
|
||||
}
|
||||
}
|
@@ -28,9 +28,11 @@ import im.vector.app.core.platform.VectorViewModel
|
||||
import im.vector.app.features.home.room.threads.list.views.ThreadListFragment
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.threads.ThreadTimelineEvent
|
||||
import org.matrix.android.sdk.flow.flow
|
||||
import timber.log.Timber
|
||||
|
||||
class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState: ThreadListViewState,
|
||||
private val session: Session) :
|
||||
@@ -54,6 +56,7 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState
|
||||
|
||||
init {
|
||||
observeThreadsList()
|
||||
loadMore()
|
||||
}
|
||||
|
||||
override fun handle(action: EmptyAction) {}
|
||||
@@ -79,4 +82,10 @@ class ThreadListViewModel @AssistedInject constructor(@Assisted val initialState
|
||||
copy(shouldFilterThreads = shouldFilterThreads)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadMore() {
|
||||
viewModelScope.launch {
|
||||
room?.fetchAllThreads(2, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user