Skip to content

saving sync filter changed #7627

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

Merged
merged 10 commits into from
Nov 28, 2022
Merged

saving sync filter changed #7627

merged 10 commits into from
Nov 28, 2022

Conversation

fedrunov
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Currently sync filter doesn't take in account home server capability, so we can't add params which depends on homeserver version like unread_thread_notifications, also we need to update filter when those capabilities changing and so we need to store filter parameters to be able to build filter with new capabilities and compare with stored one

Motivation and context

closes #7626

@fedrunov fedrunov requested a review from bmarty November 22, 2022 11:58
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Nice work, thanks! A few remarks, also there are some errors reported by detekt. You can run locally by calling ./gradlew detekt.


package org.matrix.android.sdk.api.session.sync.filter

internal data class SyncFilterParams(
Copy link
Member

Choose a reason for hiding this comment

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

if it's internal it should be moved to the internal package.

listOfSupportedEventTypes = params.listOfSupportedEventTypes.toRealmList(),
listOfSupportedEventTypesHasSet = params.listOfSupportedEventTypes != null,
listOfSupportedStateEventTypes = params.listOfSupportedStateEventTypes.toRealmList(),
listOfSupportedStateEventTypesHasSet = params.listOfSupportedEventTypes != null,
Copy link
Member

Choose a reason for hiding this comment

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

Copy paste bug here:

Suggested change
listOfSupportedStateEventTypesHasSet = params.listOfSupportedEventTypes != null,
listOfSupportedStateEventTypesHasSet = params.listOfSupportedStateEventTypes != null,

var lazyLoadMembersForMessageEvents: Boolean? = null,
var useThreadNotifications: Boolean? = null,
var listOfSupportedEventTypes: RealmList<String>? = null,
var listOfSupportedEventTypesHasSet: Boolean = false,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename to

Suggested change
var listOfSupportedEventTypesHasSet: Boolean = false,
var listOfSupportedEventTypesHasBeenSet: Boolean = false,

var listOfSupportedEventTypes: RealmList<String>? = null,
var listOfSupportedEventTypesHasSet: Boolean = false,
var listOfSupportedStateEventTypes: RealmList<String>? = null,
var listOfSupportedStateEventTypesHasSet: Boolean = false,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename to

Suggested change
var listOfSupportedStateEventTypesHasSet: Boolean = false,
var listOfSupportedStateEventTypesHasBeenSet: Boolean = false,

return monarchy.awaitTransaction { realm ->
realm.where<SyncFilterParamsEntity>().findFirst()?.let {
val params = FilterParamsMapper().map(it)
params
Copy link
Member

Choose a reason for hiding this comment

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

maybe simplify those two lines to

FilterParamsMapper().map(it)

(will also remove the indentation issue)


override suspend fun storeFilterParams(params: SyncFilterParams) {
return monarchy.awaitTransaction { realm ->
val entity = FilterParamsMapper().map(params)
Copy link
Member

Choose a reason for hiding this comment

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

Use injected FilterParamsMapper

saveFilterTask
.configureWith(SaveFilterTask.Params(filterPreset))
.executeBy(taskExecutor)
override fun setSyncFilter(filterBuilder: SyncFilterBuilder) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe take the opportunity to make this fun suspendable?

filterRepository.storeSyncFilter(
filter = filter,
filterId = filterResponse.filterId,
roomEventFilter = FilterFactory.createDefaultRoomFilter()
Copy link
Member

Choose a reason for hiding this comment

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

It's weird to call createDefaultRoomFilter. Can you explain please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is currently no difference between ElementRoomFilter and DefaultRoomFilter so basically there is no need to introduce any options here. It's also looks like we could utilise Filter.room.timeline filter for the purpose of roomEventFilter, which will mean that we don't need this separate filter at all. But currently no one can say for sure if we could/should do so or no, so for now I decided to do as little change to this area as possible, since the task was mostly about SyncFilter. I just wanted to remove referencing Element from the sdk, since there was no real difference between Default and Element room filters

)
}

internal fun build(homeServerCapabilities: HomeServerCapabilities): Filter {
Copy link
Member

Choose a reason for hiding this comment

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

I understand the logic, but from an app developer, it's weird to provide a builder without calling build().
So maybe refactor a bit and create a SyncFilterParam with a SyncFilterParamBuilder in the API.

then we can have an internal SyncFilterBuilder which takes a SyncFilterParam and build with HomeServerCapabilities, retrieved using an injected HomeServerCapabilitiesDataSource in the constructor.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also had doubts making it internal, but then I decided that introducing extra entities could make it more difficult to understand the flow and maintain it in the future. I don't have any strong opinion on that though, more like personal preference, so if you think it will be better to separate to two builders - I'll do the change

)

@ExperimentalCoroutinesApi
class DefaultGetCurrentFilterTaskTest {
Copy link
Member

Choose a reason for hiding this comment

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

Please rename the file to match this class name.

@fedrunov fedrunov requested a review from bmarty November 24, 2022 15:11
filter = filterBuilder.build(homeServerCapabilities)
)
)
.executeBy(taskExecutor)
Copy link
Member

Choose a reason for hiding this comment

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

Since you are in a suspend fun, I think you do not need to use the taskExecutor (it can be removed from the constructor).
Just call

saveFilterTask.execute(
    SaveFilterTask.Params(
        filter = filterBuilder.build(homeServerCapabilities)
    )
)

Should be fine

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for the update. One last remark.

NIkita Fedrunov added 2 commits November 24, 2022 16:55
# Conflicts:
#	matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo043.kt
NIkita Fedrunov added 3 commits November 27, 2022 21:16
# Conflicts:
#	matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo044.kt
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

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

72.5% 72.5% Coverage
0.0% 0.0% Duplication

@fedrunov fedrunov merged commit 5aeca1f into develop Nov 28, 2022
@fedrunov fedrunov deleted the bugfix/nfe/storing_sync_filter branch November 28, 2022 08:48
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.

Make sync filter consider homeserver capabilities
2 participants