Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup room summary query params #6143

Merged
merged 18 commits into from
May 30, 2022

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented May 24, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

No functional change on this PR.

Mainly work on RoomSummaryQueryParams, to try to match what we will have on the Rust SDK.

Changes:

  • Remove RoomSummaryQueryParams.roomId. If you need to observe a single room, use the new API RoomService.getRoomSummaryLive(roomId: String)
  • ActiveSpaceFilter has been renamed to SpaceFilter
  • RoomCategoryFilter.ALL has been removed, just pass null to not filter on Room category.
  • Cleanup code, especially remove duplicated line of code.
  • Add some Kdoc

Remaining work:

Motivation and context

See content ^

Screenshots / GIFs

Tests

Tests are in progress

  • Test Space filtering: OK
  • Join a room after a preview, to check the new RoomService.getRoomSummaryLive(roomId: String): OK
  • Run the sanityTest: OK

image

Tested devices

  • Physical
  • Emulator
  • OS version(s):

@github-actions
Copy link

github-actions bot commented May 24, 2022

Unit Test Results

124 files  124 suites   2m 32s ⏱️
220 tests 220 ✔️ 0 💤 0
726 runs  726 ✔️ 0 💤 0

Results for commit ec498cf.

♻️ This comment has been updated with latest results.

}
).size

roomsInvite = session.roomService().getRoomSummaries(
roomSummaryQueryParams {
memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
spaceFilter = groupingMethod.spaceSummary?.roomId?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is equivalent (I think) to the previous code, hence, I am not sure why we would like to have OrphanRooms here. I am tempted to remove the fallback and pass null instead. WDYT @BillCarsonFr ?
Applicable to all the equivalent change in this file (and in other files too).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could reduce some of the noise by extracting a fun GroupingMethod.activeSpaceOrNull() / orOphans extension

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do.

Copy link
Member Author

@bmarty bmarty May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done c9a292c

)
} else {
copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
spaceFilter = SpaceFilter.ActiveSpace(currentSpace)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was tempted to rewrite to something like
spaceFilter = currentSpace?.let{ SpaceFilter.ActiveSpace(it) }
But I think this is better to keep it like that for code clarity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it's still very clear and it would be nice to be consistent with the change above in line 439. There would be a slight difference in functionality though. What happens if we get SpaceFilter.ActiveSpace(null)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using null in SpaceFilter.ActiveSpace(null) is not possible anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it.membership == Membership.JOIN
}
list.firstOrNull { it.roomId == initialState.roomId }?.roomType?.let {
.liveRoomSummary(initialState.roomId)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling a new API

// nop
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because the same code is at line 302 below. Line 287 in the new version of the file.

it.process(RoomSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
}
}
.process(RoomSummaryEntityFields.ROOM_ID, QueryStringValue.IsNotEmpty)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep this check, even if I think we cannot have a room in DB with an empty Id.
This PR is not supposed to bring functional changes.

@@ -168,9 +168,6 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
override fun handle(action: SpaceAddRoomActions) {
when (action) {
is SpaceAddRoomActions.UpdateFilter -> {
roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy(
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because the lines just below are the same.

@bmarty bmarty requested review from a team, Claire1817 and ericdecanini and removed request for a team May 25, 2022 08:58
@bmarty bmarty marked this pull request as ready for review May 25, 2022 08:58
@sonarcloud
Copy link

sonarcloud bot commented May 25, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
var memberships: List<Membership> = Membership.all()
var roomCategoryFilter: RoomCategoryFilter? = RoomCategoryFilter.ALL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I preferred the explicitness of the ALL but null is more consistent with the project conventions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also prefer using non-nullability. For this specific API, it's more consistent to use null.

@@ -28,65 +28,196 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
* It can be retrieved by [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]
*/
data class RoomSummary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@@ -333,6 +314,14 @@ internal class RoomSummaryDataSource @Inject constructor(
return query
}

private fun QueryStringValue.toDisplayNameField(): String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for extracting

})
} else {
listOfNotNull(
getRoomSummary(roomId)?.takeIf { it.membership == Membership.JOIN }
Copy link
Contributor

@ouchadam ouchadam May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a difference between listOf(getRoomSummary()) and getRoomSummaries { this.roomId = QueryStringValue.Equals(roomId) } ?

I'm wondering if all the roomSummaries fetching should be taking into account roomIdOrAlias

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoomSummaryQueryParams.roomId has been removed, so cannot be used anymore.
roomIdOrAlias can be used, but I think for this particular case roomId is enough.

Copy link
Contributor

@ericdecanini ericdecanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! Just a couple comments

* A live [RoomSummary] associated with the room with id [roomId].
* You can observe this summary to get dynamic data from this room, even if the room is not joined yet
*/
fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit weird that this uses Optional and the non-live version uses a nullable. Is it possible to use the same for both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LiveData cannot emit null value IIRC.

)
} else {
copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
spaceFilter = SpaceFilter.ActiveSpace(currentSpace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it's still very clear and it would be nice to be consistent with the change above in line 439. There would be a slight difference in functionality though. What happens if we get SpaceFilter.ActiveSpace(null)?

Copy link
Contributor

@ericdecanini ericdecanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

bmarty added 10 commits May 30, 2022 11:34
…ueryParams.Builder()`

Also format and add some Kdoc
…ueryParams.Builder()`

Also format and add some Kdoc
Create a new API in RoomService to observe a room summary from a roomId.
It was working fine since in the DB we always have a name using `RoomDisplayNameFallbackProvider`, which in our current implementation always return a non empty String.
Prefer nullability for API coherency of `RoomSummaryQueryParams`
Prefer nullability for API coherency of `RoomSummaryQueryParams`
@bmarty bmarty force-pushed the feature/bma/cleanup_RoomSummaryQueryParams branch from f5194d3 to ec498cf Compare May 30, 2022 09:38
@bmarty bmarty enabled auto-merge May 30, 2022 09:44
@bmarty bmarty merged commit 17ccccc into develop May 30, 2022
@bmarty bmarty deleted the feature/bma/cleanup_RoomSummaryQueryParams branch May 30, 2022 10:22
@github-actions
Copy link

Matrix SDK

Integration Tests Results:

  • [org.matrix.android.sdk.session]
    = passed=20 failures=0 errors=0 skipped=3
  • [org.matrix.android.sdk.account]
    = passed=3 failures=0 errors=0 skipped=2
  • [org.matrix.android.sdk.internal]
    = passed=20 failures=1 errors=0 skipped=1
  • [org.matrix.android.sdk.ordering]
    = passed=16 failures=0 errors=0 skipped=0
  • [org.matrix.android.sdk.PermalinkParserTest]
    = passed=2 failures=0 errors=0 skipped=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants