@@ -147,22 +147,24 @@ class LocationRepository @Inject constructor(
147147
148148 // Send locations for the current event
149149 val event = locations[0 ].event
150- val eventLocations = locations.filter { it.event == event }
150+ val localLocations = locations.filter { it.event == event }
151151
152152 try {
153- val response = locationService.pushLocations(event.remoteId, eventLocations )
153+ val response = locationService.pushLocations(event.remoteId, localLocations )
154154 if (response.isSuccessful) {
155- val pushedLocations = response.body() ? : emptyList()
155+ val remoteLocations = response.body() ? : emptyList()
156156 // We've sync-ed locations to the server, lets remove the locations we synced from the database
157- Log .d(LOG_NAME , " Pushed " + pushedLocations .size + " locations." )
157+ Log .d(LOG_NAME , " Pushed " + remoteLocations .size + " locations." )
158158 try {
159- eventLocations .forEachIndexed { index, location ->
160- val remoteId = pushedLocations .getOrNull(index)?.remoteId
161- if (remoteId == null ) {
162- locationLocalDataSource.delete(listOf (location ))
159+ localLocations .forEachIndexed { index, localLocation ->
160+ val remoteLocation = remoteLocations .getOrNull(index)
161+ if (remoteLocation == null ) {
162+ locationLocalDataSource.delete(listOf (localLocation ))
163163 } else {
164- location.remoteId = remoteId
165- locationLocalDataSource.update(location)
164+ remoteLocation.id = localLocation.id
165+ remoteLocation.user = currentUser
166+ remoteLocation.event = event
167+ locationLocalDataSource.update(remoteLocation)
166168 }
167169 }
168170
0 commit comments