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

Check user power level before sharing live location (PSG-620) #6587

Merged
merged 4 commits into from
Jul 20, 2022

Conversation

onurays
Copy link
Contributor

@onurays onurays commented Jul 18, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Wha a user tries to share their live location we need to check if the user has enough power level before showing duration bottom sheet or labs flag promotion bottom sheet.

Motivation and context

Screenshots / GIFs

lls_not_enough_permission

Tests

  • Make the power level of the user less than 50
  • Try to share a live location
  • You should see the above error dialog
  • Change the power level to >=50 again (don't need to close the map screen)
  • You should proceed sharing the live location

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@onurays onurays changed the title Check user power level before sharing live location. Check user power level before sharing live location (PSG-620) Jul 18, 2022
@onurays onurays requested review from a team and bmarty and removed request for a team July 18, 2022 15:53
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, some remarks.

.setTitle(R.string.live_location_not_enough_permission_dialog_title)
.setMessage(R.string.live_location_not_enough_permission_dialog_description)
.setPositiveButton(R.string.ok) { dialogInterface, _ ->
dialogInterface.dismiss()
Copy link
Member

Choose a reason for hiding this comment

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

I do not think this code is necessary. You can replace by

.setPositiveButton(R.string.ok, null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course, done.

checkPowerLevelsForLiveLocationSharing()
}

private fun checkPowerLevelsForLiveLocationSharing() {
Copy link
Member

Choose a reason for hiding this comment

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

Could be rename to observePowerLevelsForLiveLocationSharing since this is using a Flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

.map { beaconInfoType ->
powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, beaconInfoType)
}
.all { isUserAllowed -> isUserAllowed }
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit strange to map twice. You can reduce to:

                    val canShareLiveLocation = EventType.STATE_ROOM_BEACON_INFO
                            .all { beaconInfoType ->
                                powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, beaconInfoType)
                            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Silly mistake :) Fixed.

.all { isUserAllowed -> isUserAllowed }

setState { copy(canShareLiveLocation = canShareLiveLocation) }
}.launchIn(viewModelScope)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: You could use setOnEach for shorter code:

        PowerLevelsFlowFactory(room).createFlow()
                .distinctUntilChanged()
                .setOnEach {
                    val powerLevelsHelper = PowerLevelsHelper(it)
                    val canShareLiveLocation = EventType.STATE_ROOM_BEACON_INFO
                            .all { beaconInfoType ->
                                powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, beaconInfoType)
                            }
                    copy(canShareLiveLocation = canShareLiveLocation)
                }

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 didn't know that. Perfect, done.

@@ -3054,6 +3054,8 @@
<!-- TODO remove key -->
<string name="live_location_bottom_sheet_stop_sharing" tools:ignore="UnusedResources">Stop sharing</string>
<string name="live_location_bottom_sheet_last_updated_at">Updated %1$s ago</string>
<string name="live_location_not_enough_permission_dialog_title">You don’t have permission to share locations</string>
<string name="live_location_not_enough_permission_dialog_description">You need to have the right permissions in order to share locations in this room.</string>
Copy link
Member

Choose a reason for hiding this comment

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

Do those two wording mention live location instead of location? I think this is always possible to share (static) location, so this may be confusing 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, replaced.

@onurays onurays requested a review from bmarty July 19, 2022 10:43
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. Can you fix the conflict please?

@sonarcloud
Copy link

sonarcloud bot commented Jul 20, 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

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@onurays onurays merged commit 7f821f1 into develop Jul 20, 2022
@onurays onurays deleted the feature/ons/fix_live_location_sharing_permission branch July 20, 2022 12:01
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.

2 participants