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

Deferred DMs - Handle the local rooms within the new AppLayout #7154

Merged
merged 7 commits into from
Sep 20, 2022

Conversation

Florian14
Copy link
Contributor

@Florian14 Florian14 commented Sep 16, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

This PR adds the deletion of the local rooms from the database when the room list is shown within the new AppLayout feature enabled.

Motivation and context

Close #7153

Tests

  • Start creating a DM with the start DM feature flag and the new App Layout enabled
  • Activate the recent rooms display from the AppLayout configuration
  • Write some text without sending it
  • Abort the DM creation and go back to the home list
  • Verify that the local rooms does not appear in the recent rooms
  • Start creating again a DM with the same person
  • Verify that the local room has not been retrieved (the draft is not persisted)

We can also observe logs in the console about the deletion of the local rooms when the home room list is shown again.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Florian14 Florian14 requested review from a team and onurays and removed request for a team September 16, 2022 07:59
@Florian14 Florian14 force-pushed the bugfix/fre/start_dm_app_layout branch from 352b872 to babe178 Compare September 16, 2022 08:06
@Florian14 Florian14 requested a review from bmarty September 16, 2022 08:08
@Florian14 Florian14 added PR-Small PR with less than 20 updated lines Z-NextRelease For issues and PRs which should be included in the NextRelease. labels Sep 16, 2022

roomListViewModel.onEach(HomeRoomListViewState::localRoomIds) {
// Local rooms should not exist anymore when the room list is shown
roomListViewModel.deleteLocalRooms(it)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think HomeRoomListViewModel should decide this business logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My problem is that the VM is still alive while the local room is opened, so moving this logic to the VM means that the local room will be deleted too early. I trigger it from the fragment to delete the rooms only when the room list is visible to the user (ie. the local timeline is closed).
It would be nice to have a foreground/background state to decide when a ViewModel should be "alive".
Do you have any suggestions about it?

Copy link
Member

Choose a reason for hiding this comment

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

You could add an Action to the ViewModel, triggered in the onResume of the Fragment, which delete all the local rooms. So HomeRoomListViewState.localRoomIds could even be removed I think.

Also we do not add public API to the ViewModels, please call handle() and add an action.

So we will have in the Fragment:

    override fun onResume() {
        super.onResume()
        roomListViewModel.handle(HomeRoomListAction.DeleteAllLocalRoom)
    }

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 8999b40 I moved to onStart instead of onResume

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. If you take my suggestion, please also update the "legacy" code.

@@ -41,6 +42,8 @@ internal class DefaultUpdateBreadcrumbsTask @Inject constructor(
) : UpdateBreadcrumbsTask {

override suspend fun execute(params: UpdateBreadcrumbsTask.Params) {
// Do not add local rooms to the recent rooms list as they should not be known by the server
if (RoomLocalEcho.isLocalEchoId(params.newTopRoomId)) return
Copy link
Member

Choose a reason for hiding this comment

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

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 648498e
I was hesitating between both places, I choose the task to be sure it would never be sent to the server but the task is only called by the service until now


roomListViewModel.onEach(HomeRoomListViewState::localRoomIds) {
// Local rooms should not exist anymore when the room list is shown
roomListViewModel.deleteLocalRooms(it)
Copy link
Member

Choose a reason for hiding this comment

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

You could add an Action to the ViewModel, triggered in the onResume of the Fragment, which delete all the local rooms. So HomeRoomListViewState.localRoomIds could even be removed I think.

Also we do not add public API to the ViewModels, please call handle() and add an action.

So we will have in the Fragment:

    override fun onResume() {
        super.onResume()
        roomListViewModel.handle(HomeRoomListAction.DeleteAllLocalRoom)
    }

@Florian14 Florian14 force-pushed the bugfix/fre/start_dm_app_layout branch from 14ab616 to 5e50494 Compare September 19, 2022 13:58
@Florian14 Florian14 requested a review from bmarty September 19, 2022 14:03
@Florian14
Copy link
Contributor Author

I also added this commit to remove the read receipts from the DB (they're not sent to the server as they are only attached to local events but they were persisted in the database)

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.

LGTM, thanks!


viewModelScope.launch {
localRoomIds.forEach {
session.roomService().deleteLocalRoom(it)
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but having a method RoomService.deleteAllLocalRooms() would be handy.

@Florian14 Florian14 enabled auto-merge September 19, 2022 15:05
@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 0 Code Smells

21.7% 21.7% Coverage
0.0% 0.0% Duplication

@Florian14 Florian14 merged commit 8624199 into develop Sep 20, 2022
@Florian14 Florian14 deleted the bugfix/fre/start_dm_app_layout branch September 20, 2022 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Small PR with less than 20 updated lines Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deferred DMs - Locals are not deleted anymore within the new AppLayout
3 participants