forked from MapComplete/MapComplete
Android: get login working
This commit is contained in:
parent
00c233a2eb
commit
88c76498b6
16 changed files with 199 additions and 171 deletions
|
|
@ -6,6 +6,7 @@ import Constants from "../../Models/Constants"
|
|||
import { Changes } from "./Changes"
|
||||
import { Utils } from "../../Utils"
|
||||
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
|
||||
import { AndroidPolyfill } from "../Web/AndroidPolyfill"
|
||||
|
||||
export interface ChangesetTag {
|
||||
key: string
|
||||
|
|
@ -52,7 +53,7 @@ export class ChangesetHandler {
|
|||
| { addAlias: (id0: string, id1: string) => void }
|
||||
| undefined,
|
||||
changes: Changes,
|
||||
reportError: (e: string | Error, extramessage: string) => void
|
||||
reportError: (e: string | Error, extramessage: string) => void,
|
||||
) {
|
||||
this.osmConnection = osmConnection
|
||||
this._reportError = reportError
|
||||
|
|
@ -113,7 +114,7 @@ export class ChangesetHandler {
|
|||
private async UploadWithNew(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
openChangeset: UIEventSource<number>,
|
||||
extraMetaTags: ChangesetTag[]
|
||||
extraMetaTags: ChangesetTag[],
|
||||
) {
|
||||
const csId = await this.OpenChangeset(extraMetaTags)
|
||||
openChangeset.setData(csId)
|
||||
|
|
@ -121,7 +122,7 @@ export class ChangesetHandler {
|
|||
console.log(
|
||||
"Opened a new changeset (openChangeset.data is undefined):",
|
||||
changeset,
|
||||
extraMetaTags
|
||||
extraMetaTags,
|
||||
)
|
||||
const changes = await this.UploadChange(csId, changeset)
|
||||
const hasSpecialMotivationChanges = ChangesetHandler.rewriteMetaTags(extraMetaTags, changes)
|
||||
|
|
@ -144,7 +145,7 @@ export class ChangesetHandler {
|
|||
public async UploadChangeset(
|
||||
generateChangeXML: (csid: number, remappings: Map<string, string>) => string,
|
||||
extraMetaTags: ChangesetTag[],
|
||||
openChangeset: UIEventSource<number>
|
||||
openChangeset: UIEventSource<number>,
|
||||
): Promise<void> {
|
||||
if (
|
||||
!extraMetaTags.some((tag) => tag.key === "comment") ||
|
||||
|
|
@ -179,13 +180,13 @@ export class ChangesetHandler {
|
|||
try {
|
||||
const rewritings = await this.UploadChange(
|
||||
csId,
|
||||
generateChangeXML(csId, this._remappings)
|
||||
generateChangeXML(csId, this._remappings),
|
||||
)
|
||||
|
||||
const rewrittenTags = this.RewriteTagsOf(
|
||||
extraMetaTags,
|
||||
rewritings,
|
||||
oldChangesetMeta
|
||||
oldChangesetMeta,
|
||||
)
|
||||
await this.UpdateTags(csId, rewrittenTags)
|
||||
return // We are done!
|
||||
|
|
@ -196,7 +197,7 @@ export class ChangesetHandler {
|
|||
} catch (e) {
|
||||
this._reportError(
|
||||
e,
|
||||
"While getting metadata from a changeset " + openChangeset.data
|
||||
"While getting metadata from a changeset " + openChangeset.data,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +225,7 @@ export class ChangesetHandler {
|
|||
console.warn(
|
||||
"Could not open/upload changeset due to ",
|
||||
e,
|
||||
"trying again with a another fresh changeset "
|
||||
"trying again with a another fresh changeset ",
|
||||
)
|
||||
openChangeset.setData(undefined)
|
||||
|
||||
|
|
@ -250,7 +251,7 @@ export class ChangesetHandler {
|
|||
uid: number // User ID
|
||||
changes_count: number
|
||||
tags: any
|
||||
}
|
||||
},
|
||||
): ChangesetTag[] {
|
||||
// Note: extraMetaTags is where all the tags are collected into
|
||||
|
||||
|
|
@ -387,7 +388,7 @@ export class ChangesetHandler {
|
|||
tag.key !== undefined &&
|
||||
tag.value !== undefined &&
|
||||
tag.key !== "" &&
|
||||
tag.value !== ""
|
||||
tag.value !== "",
|
||||
)
|
||||
const metadata = tags.map((kv) => `<tag k="${kv.key}" v="${escapeHtml(kv.value)}"/>`)
|
||||
const content = [`<osm><changeset>`, metadata, `</changeset></osm>`].join("")
|
||||
|
|
@ -398,10 +399,16 @@ export class ChangesetHandler {
|
|||
const usedGps = this.changes.state["currentUserLocation"]?.features?.data?.length > 0
|
||||
const hasMorePrivacy = !!this.changes.state?.featureSwitches?.featureSwitchMorePrivacy?.data
|
||||
const setSourceAsSurvey = !hasMorePrivacy && usedGps
|
||||
let shell = ""
|
||||
let host = `${window.location.origin}${window.location.pathname}`
|
||||
if (AndroidPolyfill.inAndroid.data) {
|
||||
shell = " (Android)"
|
||||
host = "https://mapcomplete.org/" + window.location.pathname
|
||||
}
|
||||
return [
|
||||
["created_by", `MapComplete ${Constants.vNumber}`],
|
||||
["created_by", `MapComplete ${Constants.vNumber}${shell}`],
|
||||
["locale", Locale.language.data],
|
||||
["host", `${window.location.origin}${window.location.pathname}`], // Note: deferred changes might give a different hostpath then the theme with which the changes were made
|
||||
["host", host], // Note: deferred changes might give a different hostpath then the theme with which the changes were made
|
||||
["source", setSourceAsSurvey ? "survey" : undefined],
|
||||
["imagery", this.changes.state["backgroundLayer"]?.data?.id],
|
||||
].map(([key, value]) => ({
|
||||
|
|
@ -427,7 +434,7 @@ export class ChangesetHandler {
|
|||
const csId = await this.osmConnection.put(
|
||||
"changeset/create",
|
||||
[`<osm><changeset>`, metadata, `</changeset></osm>`].join(""),
|
||||
{ "Content-Type": "text/xml" }
|
||||
{ "Content-Type": "text/xml" },
|
||||
)
|
||||
return Number(csId)
|
||||
}
|
||||
|
|
@ -437,12 +444,12 @@ export class ChangesetHandler {
|
|||
*/
|
||||
private async UploadChange(
|
||||
changesetId: number,
|
||||
changesetXML: string
|
||||
changesetXML: string,
|
||||
): Promise<Map<string, string>> {
|
||||
const response = await this.osmConnection.post<XMLDocument>(
|
||||
"changeset/" + changesetId + "/upload",
|
||||
changesetXML,
|
||||
{ "Content-Type": "text/xml" }
|
||||
{ "Content-Type": "text/xml" },
|
||||
)
|
||||
const changes = this.parseUploadChangesetResponse(response)
|
||||
console.log("Uploaded changeset ", changesetId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue