Skip to content

Commit

Permalink
do not require READ_GPS_TRACES permission (fixes #4141)
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Jun 20, 2022
1 parent 5c3c43a commit 857f810
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import de.westnordost.streetcomplete.data.osmtracks.Trackpoint
import de.westnordost.streetcomplete.data.osmtracks.TracksApi
import de.westnordost.streetcomplete.data.upload.ConflictException
import de.westnordost.streetcomplete.data.upload.OnUploadedChangeListener
import de.westnordost.streetcomplete.data.user.UserDataSource
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -23,6 +24,7 @@ import java.net.URLEncoder
class NoteEditsUploader(
private val noteEditsController: NoteEditsController,
private val noteController: NoteController,
private val userDataSource: UserDataSource,
private val notesApi: NotesApi,
private val tracksApi: TracksApi,
private val imageUploader: StreetCompleteImageUploader
Expand Down Expand Up @@ -125,9 +127,9 @@ class NoteEditsUploader(
noteText: String?
): String {
if (trackpoints.isEmpty()) return ""
val track = tracksApi.create(trackpoints, noteText)
val encodedUsername = URLEncoder.encode(track.userName, "utf-8").replace("+", "%20")
return "\n\nGPS Trace: https://www.openstreetmap.org/user/$encodedUsername/traces/${track.id}\n"
val trackId = tracksApi.create(trackpoints, noteText)
val encodedUsername = URLEncoder.encode(userDataSource.userName, "utf-8").replace("+", "%20")
return "\n\nGPS Trace: https://www.openstreetmap.org/user/$encodedUsername/traces/$trackId\n"
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ package de.westnordost.streetcomplete.data.osmtracks
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
import kotlinx.serialization.Serializable

@Serializable
data class Track(
val id: Long,
val userName: String,
)

@Serializable
data class Trackpoint(
val position: LatLon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ interface TracksApi {
* @param noteText optional text appended to the track
*
* @throws AuthorizationException if this application is not authorized to write traces
* (Permission.READ_GPS_TRACES, Permission.WRITE_GPS_TRACES)
* (Permission.WRITE_GPS_TRACES)
* @throws ConnectionException if a temporary network connection problem occurs
*
* @return the new track
* @return id of the new track
*/
fun create(trackpoints: List<Trackpoint>, noteText: String?): Track
fun create(trackpoints: List<Trackpoint>, noteText: String?): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.time.format.DateTimeFormatter
class TracksApiImpl(osm: OsmConnection) : TracksApi {
private val api: GpsTracesApi = GpsTracesApi(osm)

override fun create(trackpoints: List<Trackpoint>, noteText: String?): Track = wrapExceptions {
override fun create(trackpoints: List<Trackpoint>, noteText: String?): Long = wrapExceptions {
// Filename is just the start of the track
// https://stackoverflow.com/a/49862573/7718197
val name = DateTimeFormatter
Expand All @@ -42,9 +42,7 @@ class TracksApiImpl(osm: OsmConnection) : TracksApi {
}

// Finally query the API and return!
val traceId = api.create(name, visibility, description, tags, history)
val details = api.get(traceId)
Track(details.id, details.userName)
api.create(name, visibility, description, tags, history)
}
}

Expand Down

0 comments on commit 857f810

Please sign in to comment.