change : Hide UserLocaitonPuck when currentlySharing from this device (and follow the marker instead of the puck)

This commit is contained in:
ganfra
2026-06-03 21:54:29 +02:00
parent 930aa4f1db
commit f800bb5586
2 changed files with 36 additions and 2 deletions
@@ -200,7 +200,15 @@ import kotlinx.coroutines.launch
}
}
}
val userLocationState = userLocationStateFactory.create(hasLocationPermission = permissionsState.isAnyGranted)
val isCurrentlySharing by liveLocationShareManager.isCurrentlySharing(roomId = joinedRoom.roomId).collectAsState()
val hideUserLocationPuck = mode is ShowLocationMode.Live && isCurrentlySharing
val userLocationState = if (hideUserLocationPuck) {
// When sharing with this device, use the user LocationShareItem as source of data instead of the device.
val ownLocationShare by remember { derivedStateOf { updatedLocationShares.find { it.isOwnUser }?.location?.asMapLibreLocation() } }
UserLocationState(ownLocationShare)
} else {
userLocationStateFactory.create(hasLocationPermission = permissionsState.isAnyGranted)
}
return ShowLocationState(
customMapStyleUrl = customMapStyleUrl,
dialogState = dialogState,
@@ -210,7 +218,7 @@ import kotlinx.coroutines.launch
userLocationState = userLocationState,
isLive = mode is ShowLocationMode.Live,
appName = appName,
hideUserLocationPuck = false,
hideUserLocationPuck = hideUserLocationPuck,
eventSink = ::handleEvent,
)
}
@@ -460,4 +460,30 @@ class ShowLocationPresenterTest {
}
}
@Test
fun `live mode user location state uses own share position when sharing`() = runTest {
val ownLiveLocationShare = aLiveLocationShare()
val fakeRoom = FakeJoinedRoom(
liveLocationSharesFlow = MutableStateFlow(listOf(ownLiveLocationShare))
)
val manager = FakeActiveLiveLocationShareManager(
startShareLambda = { _, _ -> Result.success(Unit) }
)
manager.startShare(fakeRoom.roomId, 1.hours)
val presenter = createShowLocationPresenter(
mode = ShowLocationMode.Live(senderId = A_USER_ID),
joinedRoom = fakeRoom,
liveLocationShareManager = manager,
)
val ownLocation = ownLiveLocationShare.lastLocation?.geoUri?.let(Location::fromGeoUri)
presenter.test {
skipItems(1)
val state = awaitItem()
assertThat(state.hideUserLocationPuck).isTrue()
val location = requireNotNull(state.userLocationState.location)
assertThat(location.position.value.latitude).isEqualTo(ownLocation?.lat)
assertThat(location.position.value.longitude).isEqualTo(ownLocation?.lon)
}
}
}