Code review

This commit is contained in:
Valere 2021-09-02 11:31:13 +02:00
parent 97114b4f48
commit 9687a59371
10 changed files with 17 additions and 18 deletions

View file

@ -20,7 +20,7 @@ import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
data class SpaceHierarchySummary( data class SpaceHierarchyData(
val rootSummary: RoomSummary, val rootSummary: RoomSummary,
val children: List<SpaceChildInfo>, val children: List<SpaceChildInfo>,
val childrenState: List<Event>, val childrenState: List<Event>,

View file

@ -21,7 +21,6 @@ import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.internal.session.space.SpaceHierarchySummary
import org.matrix.android.sdk.internal.session.space.peeking.SpacePeekResult import org.matrix.android.sdk.internal.session.space.peeking.SpacePeekResult
typealias SpaceSummaryQueryParams = RoomSummaryQueryParams typealias SpaceSummaryQueryParams = RoomSummaryQueryParams
@ -61,7 +60,6 @@ interface SpaceService {
* Get's information of a space by querying the server * Get's information of a space by querying the server
* @param suggestedOnly If true, return only child events and rooms where the m.space.child event has suggested: true. * @param suggestedOnly If true, return only child events and rooms where the m.space.child event has suggested: true.
* @param limit a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer. * @param limit a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer.
* @param maxDepth: Optional: The maximum depth in the tree (from the root room) to return.
* @param from: Optional. Pagination token given to retrieve the next set of rooms. Note that if a pagination token is provided, * @param from: Optional. Pagination token given to retrieve the next set of rooms. Note that if a pagination token is provided,
* then the parameters given for suggested_only and max_depth must be the same. * then the parameters given for suggested_only and max_depth must be the same.
*/ */
@ -70,7 +68,7 @@ interface SpaceService {
limit: Int? = null, limit: Int? = null,
from: String? = null, from: String? = null,
// when paginating, pass back the m.space.child state events // when paginating, pass back the m.space.child state events
knownStateList: List<Event>? = null): SpaceHierarchySummary knownStateList: List<Event>? = null): SpaceHierarchyData
/** /**
* Get a live list of space summaries. This list is refreshed as soon as the data changes. * Get a live list of space summaries. This list is refreshed as soon as the data changes.

View file

@ -36,6 +36,7 @@ import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
import org.matrix.android.sdk.api.session.space.CreateSpaceParams import org.matrix.android.sdk.api.session.space.CreateSpaceParams
import org.matrix.android.sdk.api.session.space.JoinSpaceResult import org.matrix.android.sdk.api.session.space.JoinSpaceResult
import org.matrix.android.sdk.api.session.space.Space import org.matrix.android.sdk.api.session.space.Space
import org.matrix.android.sdk.api.session.space.SpaceHierarchyData
import org.matrix.android.sdk.api.session.space.SpaceService import org.matrix.android.sdk.api.session.space.SpaceService
import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
import org.matrix.android.sdk.api.session.space.model.SpaceChildContent import org.matrix.android.sdk.api.session.space.model.SpaceChildContent
@ -112,7 +113,7 @@ internal class DefaultSpaceService @Inject constructor(
suggestedOnly: Boolean?, suggestedOnly: Boolean?,
limit: Int?, limit: Int?,
from: String?, from: String?,
knownStateList: List<Event>?): SpaceHierarchySummary { knownStateList: List<Event>?): SpaceHierarchyData {
return resolveSpaceInfoTask.execute( return resolveSpaceInfoTask.execute(
ResolveSpaceInfoTask.Params( ResolveSpaceInfoTask.Params(
spaceId = spaceId, limit = limit, maxDepth = 1, from = from, suggestedOnly = suggestedOnly spaceId = spaceId, limit = limit, maxDepth = 1, from = from, suggestedOnly = suggestedOnly
@ -164,7 +165,7 @@ internal class DefaultSpaceService @Inject constructor(
}.orEmpty() }.orEmpty()
} }
.orEmpty() .orEmpty()
SpaceHierarchySummary( SpaceHierarchyData(
rootSummary = root, rootSummary = root,
children = children, children = children,
childrenState = spaceDesc?.childrenState.orEmpty(), childrenState = spaceDesc?.childrenState.orEmpty(),

View file

@ -24,10 +24,10 @@ import retrofit2.http.Query
internal interface SpaceApi { internal interface SpaceApi {
/** /**
* @param suggestedOnly Optional. If true, return only child events and rooms where the m.space.child event has suggested: true.
* @param limit: Optional: a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer. * @param limit: Optional: a client-defined limit to the maximum number of rooms to return per page. Must be a non-negative integer.
* @param max_depth: Optional: The maximum depth in the tree (from the root room) to return. * @param maxDepth: Optional: The maximum depth in the tree (from the root room) to return.
* The deepest depth returned will not include children events. Defaults to no-limit. Must be a non-negative integer. * The deepest depth returned will not include children events. Defaults to no-limit. Must be a non-negative integer.
*
* @param from: Optional. Pagination token given to retrieve the next set of rooms. * @param from: Optional. Pagination token given to retrieve the next set of rooms.
* Note that if a pagination token is provided, then the parameters given for suggested_only and max_depth must be the same. * Note that if a pagination token is provided, then the parameters given for suggested_only and max_depth must be the same.
*/ */

View file

@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.session.events.model.Event
* The fields are the same as those returned by /publicRooms (see spec), with the addition of: * The fields are the same as those returned by /publicRooms (see spec), with the addition of:
* room_type: the value of the m.type field from the room's m.room.create event, if any. * room_type: the value of the m.type field from the room's m.room.create event, if any.
* children_state: The m.space.child events of the room. * children_state: The m.space.child events of the room.
* For each event, only the following fields are included1: type, state_key, content, room_id, sender, * For each event, only the following fields are included: type, state_key, content, room_id, sender,
* with the addition of: origin_server_ts: This is required for sorting of rooms as specified below. * with the addition of: origin_server_ts: This is required for sorting of rooms as specified below.
*/ */
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)

View file

@ -62,7 +62,7 @@ class SpaceCardRenderer @Inject constructor(
inCard.matrixToAccessImage.isVisible = true inCard.matrixToAccessImage.isVisible = true
inCard.matrixToAccessImage.setImageResource(R.drawable.ic_room_private) inCard.matrixToAccessImage.setImageResource(R.drawable.ic_room_private)
} }
val memberCount = spaceSummary.joinedMembersCount?.let { it - 1 } ?: 0 val memberCount = spaceSummary.joinedMembersCount ?: 0
if (memberCount != 0) { if (memberCount != 0) {
inCard.matrixToMemberPills.isVisible = true inCard.matrixToMemberPills.isVisible = true
inCard.spaceChildMemberCountText.text = stringProvider.getQuantityString(R.plurals.room_title_members, memberCount, memberCount) inCard.spaceChildMemberCountText.text = stringProvider.getQuantityString(R.plurals.room_title_members, memberCount, memberCount)

View file

@ -175,7 +175,7 @@ class SpaceDirectoryController @Inject constructor(
errorWithRetryItem { errorWithRetryItem {
id("error_${currentRootId}_${hierarchySummary.nextToken}") id("error_${currentRootId}_${hierarchySummary.nextToken}")
text(host.errorFormatter.toHumanReadable(paginationStatus.error)) text(host.errorFormatter.toHumanReadable(paginationStatus.error))
listener { host.listener?.retry() } listener { host.listener?.loadAdditionalItemsIfNeeded() }
} }
} else { } else {
loadingItem { loadingItem {

View file

@ -21,13 +21,13 @@ import com.airbnb.mvrx.MvRxState
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo
import org.matrix.android.sdk.internal.session.space.SpaceHierarchySummary import org.matrix.android.sdk.api.session.space.SpaceHierarchyData
data class SpaceDirectoryState( data class SpaceDirectoryState(
// The current filter // The current filter
val spaceId: String, val spaceId: String,
val currentFilter: String = "", val currentFilter: String = "",
val apiResults: Map<String, Async<SpaceHierarchySummary>> = emptyMap(), val apiResults: Map<String, Async<SpaceHierarchyData>> = emptyMap(),
val currentRootSummary: RoomSummary? = null, val currentRootSummary: RoomSummary? = null,
val childList: List<SpaceChildInfo> = emptyList(), val childList: List<SpaceChildInfo> = emptyList(),
val hierarchyStack: List<String> = emptyList(), val hierarchyStack: List<String> = emptyList(),
@ -37,7 +37,7 @@ data class SpaceDirectoryState(
val changeMembershipStates: Map<String, ChangeMembershipState> = emptyMap(), val changeMembershipStates: Map<String, ChangeMembershipState> = emptyMap(),
val canAddRooms: Boolean = false, val canAddRooms: Boolean = false,
// cached room summaries of known rooms, we use it because computed room name would be better using it // cached room summaries of known rooms, we use it because computed room name would be better using it
val knownRoomSummaries : List<RoomSummary> = emptyList(), val knownRoomSummaries: List<RoomSummary> = emptyList(),
val paginationStatus: Map<String, Async<Unit>> = emptyMap() val paginationStatus: Map<String, Async<Unit>> = emptyMap()
) : MvRxState { ) : MvRxState {
constructor(args: SpaceDirectoryArgs) : this( constructor(args: SpaceDirectoryArgs) : this(

View file

@ -20,18 +20,18 @@ import com.airbnb.mvrx.Async
import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.Uninitialized
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.internal.session.space.SpaceHierarchySummary import org.matrix.android.sdk.api.session.space.SpaceHierarchyData
data class SpaceManageRoomViewState( data class SpaceManageRoomViewState(
val spaceId: String, val spaceId: String,
val spaceSummary: Async<RoomSummary> = Uninitialized, val spaceSummary: Async<RoomSummary> = Uninitialized,
val childrenInfo: Async<SpaceHierarchySummary> = Uninitialized, val childrenInfo: Async<SpaceHierarchyData> = Uninitialized,
val selectedRooms: List<String> = emptyList(), val selectedRooms: List<String> = emptyList(),
val currentFilter: String = "", val currentFilter: String = "",
val actionState: Async<Unit> = Uninitialized, val actionState: Async<Unit> = Uninitialized,
val paginationStatus: Async<Unit> = Uninitialized, val paginationStatus: Async<Unit> = Uninitialized,
// cached room summaries of known rooms, we use it because computed room name would be better using it // cached room summaries of known rooms, we use it because computed room name would be better using it
val knownRoomSummaries : List<RoomSummary> = emptyList() val knownRoomSummaries: List<RoomSummary> = emptyList()
) : MvRxState { ) : MvRxState {
constructor(args: SpaceManageArgs) : this( constructor(args: SpaceManageArgs) : this(
spaceId = args.spaceId spaceId = args.spaceId

View file

@ -101,7 +101,7 @@ class SpaceManageRoomsController @Inject constructor(
errorWithRetryItem { errorWithRetryItem {
id("error_$nextToken") id("error_$nextToken")
text(host.errorFormatter.toHumanReadable(paginationStatus.error)) text(host.errorFormatter.toHumanReadable(paginationStatus.error))
listener { host.listener?.retry() } listener { host.listener?.loadAdditionalItemsIfNeeded() }
} }
} else { } else {
loadingItem { loadingItem {