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

Handle account data removal (PSG-865, PSG-867) #7740

Merged
merged 7 commits into from Dec 12, 2022

Conversation

onurays
Copy link
Contributor

@onurays onurays commented Dec 7, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Synapse will start to support deleting account data events. If a client removes an account data event then it will be reported in sync response with an empty content {}. This PR adds delete endpoints (will be used in next PR) and also handles them in the sync response.

Motivation and context

Implement MSC-3391

Screenshots / GIFs

Tests

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@ElementBot
Copy link

Warnings
⚠️

Please add a changelog. See instructions here

Generated by 🚫 dangerJS against f4429d4

@ElementBot
Copy link

Warnings
⚠️

Please add a changelog. See instructions here

Generated by 🚫 dangerJS against 055bf6d

@onurays onurays requested review from a team and bmarty and removed request for a team December 8, 2022 10:47
@onurays onurays marked this pull request as ready for review December 8, 2022 10:51
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. Some feedback. OOI in the context of which feature are you implementing this MSC?

* @param roomId the room id
* @param type the type
*/
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE + "org.matrix.msc3391/user/{userId}/rooms/{roomId}/account_data/{type}")
Copy link
Member

Choose a reason for hiding this comment

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

Error in the path:

Suggested change
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE + "org.matrix.msc3391/user/{userId}/rooms/{roomId}/account_data/{type}")
@DELETE(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc3391/user/{userId}/rooms/{roomId}/account_data/{type}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ups, good catch. Done.

UserAccountDataTypes.TYPE_IGNORED_USER_LIST -> handleIgnoredUsers(realm, event)
UserAccountDataTypes.TYPE_BREADCRUMBS -> handleBreadcrumbs(realm, event)
if (event.content.isEmpty()) {
UserAccountDataEntity.delete(realm, event.type)
Copy link
Member

Choose a reason for hiding this comment

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

Should we do some treatment on specific Account data as per the when block in the else block below?

So I would keep the existing code, and move the removal from DB to the handleGenericAccountData() method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. That was also my initial intention. We can trust all when cases check the content.

@@ -36,4 +37,16 @@ internal interface AccountDataAPI {
@Path("type") type: String,
@Body params: Any
)

/**
* Remove an account_data for the client.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a bit better, but we may found better.

Suggested change
* Remove an account_data for the client.
* Remove an account_data for the user.

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 agree, done.

} else if (eventType == RoomAccountDataTypes.EVENT_TYPE_FULLY_READ) {
val content = event.getClearContent().toModel<FullyReadContent>()
roomFullyReadHandler.handle(realm, roomId, content)
}
Copy link
Member

Choose a reason for hiding this comment

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

Same remark about dealing with specific room account data event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ElementBot
Copy link

Warnings
⚠️ Please add a reviewer to your PR.

Generated by 🚫 dangerJS against b09a00e

@onurays onurays requested a review from bmarty December 8, 2022 14:14
@onurays
Copy link
Contributor Author

onurays commented Dec 8, 2022

Thanks. Some feedback. OOI in the context of which feature are you implementing this MSC?

We started to store device information in account data and we need to delete it when session is logged out / deleted. Otherwise they will live in backend forever.

@@ -256,8 +257,14 @@ internal class UserAccountDataSyncHandler @Inject constructor(
.equalTo(UserAccountDataEntityFields.TYPE, type)
.findFirst()
if (existing != null) {
// Update current value
existing.contentStr = ContentMapper.map(content)
if (content.isNullOrEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

Still not good to me. If the account data does not exist yet, it will be added to the DB, and we want to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right. Please check my last commit.

@@ -58,7 +59,13 @@ internal class RoomSyncAccountDataHandler @Inject constructor(
private fun handleGeneric(roomEntity: RoomEntity, content: JsonDict?, eventType: String) {
val existing = roomEntity.accountData.where().equalTo(RoomAccountDataEntityFields.TYPE, eventType).findFirst()
if (existing != null) {
existing.contentStr = ContentMapper.map(content)
if (content.isNullOrEmpty()) {
Copy link
Member

@bmarty bmarty Dec 12, 2022

Choose a reason for hiding this comment

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

Same remark. Please reorder your if statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@onurays onurays requested a review from bmarty December 12, 2022 10:41
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.

Perfect, thanks. Maybe squash and merge to avoid noisy git history.

@sonarcloud
Copy link

sonarcloud bot commented Dec 12, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

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

10.8% 10.8% Coverage
0.0% 0.0% Duplication

@onurays onurays merged commit 9954045 into develop Dec 12, 2022
@onurays onurays deleted the feature/ons/remove_account_data branch December 12, 2022 16:31
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.

None yet

3 participants