Cleanup (PR review)
Also add some doc and add missing `internal` keyword
This commit is contained in:
parent
36b1a1471a
commit
5a0d62db6f
@ -21,20 +21,34 @@ import com.squareup.moshi.JsonClass
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class EventContextResponse(
|
||||
internal data class EventContextResponse(
|
||||
/**
|
||||
* Details of the requested event.
|
||||
*/
|
||||
@Json(name = "event") val event: Event,
|
||||
/**
|
||||
* A token that can be used to paginate backwards with.
|
||||
*/
|
||||
@Json(name = "start") override val start: String? = null,
|
||||
@Json(name = "events_before") val eventsBefore: List<Event>? = emptyList(),
|
||||
@Json(name = "events_after") val eventsAfter: List<Event>? = emptyList(),
|
||||
/**
|
||||
* A list of room events that happened just before the requested event, in reverse-chronological order.
|
||||
*/
|
||||
@Json(name = "events_before") val eventsBefore: List<Event>? = null,
|
||||
/**
|
||||
* A list of room events that happened just after the requested event, in chronological order.
|
||||
*/
|
||||
@Json(name = "events_after") val eventsAfter: List<Event>? = null,
|
||||
/**
|
||||
* A token that can be used to paginate forwards with.
|
||||
*/
|
||||
@Json(name = "end") override val end: String? = null,
|
||||
@Json(name = "state") override val stateEvents: List<Event>? = emptyList()
|
||||
/**
|
||||
* The state of the room at the last event returned.
|
||||
*/
|
||||
@Json(name = "state") override val stateEvents: List<Event>? = null
|
||||
) : TokenChunkEvent {
|
||||
|
||||
override val events: List<Event> by lazy {
|
||||
mutableListOf<Event>().apply {
|
||||
eventsAfter?.let { addAll(it.reversed()) }
|
||||
add(event)
|
||||
eventsBefore?.let { addAll(it) }
|
||||
}
|
||||
eventsAfter.orEmpty().reversed() + event + eventsBefore.orEmpty()
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,28 @@ import org.matrix.android.sdk.api.session.events.model.Event
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class PaginationResponse(
|
||||
/**
|
||||
* The token the pagination starts from. If dir=b this will be the token supplied in from.
|
||||
*/
|
||||
@Json(name = "start") override val start: String? = null,
|
||||
/**
|
||||
* The token the pagination ends at. If dir=b this token should be used again to request even earlier events.
|
||||
*/
|
||||
@Json(name = "end") override val end: String? = null,
|
||||
@Json(name = "chunk") override val events: List<Event>? = emptyList(),
|
||||
@Json(name = "state") override val stateEvents: List<Event>? = emptyList()
|
||||
) : TokenChunkEvent
|
||||
/**
|
||||
* A list of room events. The order depends on the dir parameter. For dir=b events will be in
|
||||
* reverse-chronological order, for dir=f in chronological order, so that events start at the from point.
|
||||
*/
|
||||
@Json(name = "chunk") val chunk: List<Event>? = null,
|
||||
/**
|
||||
* A list of state events relevant to showing the chunk. For example, if lazy_load_members is enabled
|
||||
* in the filter then this may contain the membership events for the senders of events in the chunk.
|
||||
*
|
||||
* Unless include_redundant_members is true, the server may remove membership events which would have
|
||||
* already been sent to the client in prior calls to this endpoint, assuming the membership of those members has not changed.
|
||||
*/
|
||||
@Json(name = "state") override val stateEvents: List<Event>? = null
|
||||
) : TokenChunkEvent {
|
||||
override val events: List<Event>
|
||||
get() = chunk.orEmpty()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.Event
|
||||
internal interface TokenChunkEvent {
|
||||
val start: String?
|
||||
val end: String?
|
||||
val events: List<Event>?
|
||||
val events: List<Event>
|
||||
val stateEvents: List<Event>?
|
||||
|
||||
fun hasMore() = start != end
|
||||
|
@ -124,7 +124,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
|
||||
direction: PaginationDirection): Result {
|
||||
monarchy
|
||||
.awaitTransaction { realm ->
|
||||
Timber.v("Start persisting ${receivedChunk.events?.size} events in $roomId towards $direction")
|
||||
Timber.v("Start persisting ${receivedChunk.events.size} events in $roomId towards $direction")
|
||||
|
||||
val nextToken: String?
|
||||
val prevToken: String?
|
||||
@ -149,14 +149,14 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
|
||||
}
|
||||
?: ChunkEntity.create(realm, prevToken, nextToken)
|
||||
|
||||
if (receivedChunk.events.isNullOrEmpty() && !receivedChunk.hasMore()) {
|
||||
if (receivedChunk.events.isEmpty() && !receivedChunk.hasMore()) {
|
||||
handleReachEnd(realm, roomId, direction, currentChunk)
|
||||
} else {
|
||||
handlePagination(realm, roomId, direction, receivedChunk, currentChunk)
|
||||
}
|
||||
}
|
||||
return if (receivedChunk.events.isNullOrEmpty()) {
|
||||
if (receivedChunk.start != receivedChunk.end) {
|
||||
return if (receivedChunk.events.isEmpty()) {
|
||||
if (receivedChunk.hasMore()) {
|
||||
Result.SHOULD_FETCH_MORE
|
||||
} else {
|
||||
Result.REACHED_END
|
||||
@ -189,7 +189,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
|
||||
receivedChunk: TokenChunkEvent,
|
||||
currentChunk: ChunkEntity
|
||||
) {
|
||||
Timber.v("Add ${receivedChunk.events?.size} events in chunk(${currentChunk.nextToken} | ${currentChunk.prevToken}")
|
||||
Timber.v("Add ${receivedChunk.events.size} events in chunk(${currentChunk.nextToken} | ${currentChunk.prevToken}")
|
||||
val roomMemberContentsByUser = HashMap<String, RoomMemberContent?>()
|
||||
val eventList = receivedChunk.events
|
||||
val stateEvents = receivedChunk.stateEvents
|
||||
@ -204,8 +204,8 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
|
||||
roomMemberContentsByUser[stateEvent.stateKey] = stateEvent.content.toModel<RoomMemberContent>()
|
||||
}
|
||||
}
|
||||
val eventIds = ArrayList<String>(eventList?.size ?: 0)
|
||||
eventList?.forEach { event ->
|
||||
val eventIds = ArrayList<String>(eventList.size)
|
||||
eventList.forEach { event ->
|
||||
if (event.eventId == null || event.senderId == null) {
|
||||
return@forEach
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ internal class DefaultGetUploadsTask @Inject constructor(
|
||||
private val roomAPI: RoomAPI,
|
||||
private val tokenStore: SyncTokenStore,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val globalErrorReceiver: GlobalErrorReceiver)
|
||||
: GetUploadsTask {
|
||||
private val globalErrorReceiver: GlobalErrorReceiver
|
||||
) : GetUploadsTask {
|
||||
|
||||
override suspend fun execute(params: GetUploadsTask.Params): GetUploadsResult {
|
||||
val result: GetUploadsResult
|
||||
@ -95,7 +95,7 @@ internal class DefaultGetUploadsTask @Inject constructor(
|
||||
nextToken = chunk.end ?: "",
|
||||
hasMore = chunk.hasMore()
|
||||
)
|
||||
events = chunk.events ?: emptyList()
|
||||
events = chunk.events
|
||||
}
|
||||
|
||||
var uploadEvents = listOf<UploadEvent>()
|
||||
|
Loading…
Reference in New Issue
Block a user