diff --git a/src/Logic/Osm/OsmConnection.ts b/src/Logic/Osm/OsmConnection.ts
index 4c6d028de5..b97bc4473b 100644
--- a/src/Logic/Osm/OsmConnection.ts
+++ b/src/Logic/Osm/OsmConnection.ts
@@ -91,9 +91,11 @@ export class OsmConnection {
ud.name = "Fake user"
ud.totalMessages = 42
ud.languages = ["en"]
+ this.loadingStatus.setData("logged-in")
}
const self = this
this.UpdateCapabilities()
+
this.isLoggedIn = this.userDetails.map(
(user) =>
user.loggedIn &&
@@ -112,10 +114,7 @@ export class OsmConnection {
this.updateAuthObject()
- this.preferencesHandler = new OsmPreferences(
- this.auth,
- this
- )
+ this.preferencesHandler = new OsmPreferences(this.auth, this, this.fakeUser)
if (options.oauth_token?.data !== undefined) {
console.log(options.oauth_token.data)
@@ -554,13 +553,12 @@ export class OsmConnection {
}
private UpdateCapabilities(): void {
- const self = this
if (this.fakeUser) {
return
}
this.FetchCapabilities().then(({ api, gpx }) => {
- self.apiIsOnline.setData(api)
- self.gpxServiceIsOnline.setData(gpx)
+ this.apiIsOnline.setData(api)
+ this.gpxServiceIsOnline.setData(gpx)
})
}
diff --git a/src/Logic/Osm/OsmPreferences.ts b/src/Logic/Osm/OsmPreferences.ts
index 1035dec823..597dd61eaf 100644
--- a/src/Logic/Osm/OsmPreferences.ts
+++ b/src/Logic/Osm/OsmPreferences.ts
@@ -2,6 +2,9 @@ import { UIEventSource } from "../UIEventSource"
import UserDetails, { OsmConnection } from "./OsmConnection"
import { Utils } from "../../Utils"
import { LocalStorageSource } from "../Web/LocalStorageSource"
+// @ts-ignore
+import { osmAuth } from "osm-auth"
+import OSMAuthInstance = OSMAuth.OSMAuthInstance
export class OsmPreferences {
/**
@@ -17,16 +20,17 @@ export class OsmPreferences {
* @private
*/
private readonly preferenceSources = new Map>()
- private auth: any
+ private readonly auth: OSMAuthInstance
private userDetails: UIEventSource
private longPreferences = {}
+ private readonly _fakeUser: boolean
- constructor(auth, osmConnection: OsmConnection) {
+ constructor(auth: OSMAuthInstance, osmConnection: OsmConnection, fakeUser: boolean = false) {
this.auth = auth
+ this._fakeUser = fakeUser
this.userDetails = osmConnection.userDetails
- const self = this
osmConnection.OnLoggedIn(() => {
- self.UpdatePreferences(true)
+ this.UpdatePreferences(true)
return true
})
}
@@ -212,8 +216,21 @@ export class OsmPreferences {
})
}
+ removeAllWithPrefix(prefix: string) {
+ for (const key in this.preferences.data) {
+ if (key.startsWith(prefix)) {
+ this.GetPreference(key, "", { prefix: "" }).setData(undefined)
+ console.log("Clearing preference", key)
+ }
+ }
+ this.preferences.ping()
+ }
+
private UpdatePreferences(forceUpdate?: boolean) {
const self = this
+ if (this._fakeUser) {
+ return
+ }
this.auth.xhr(
{
method: "GET",
@@ -272,13 +289,15 @@ export class OsmPreferences {
}
const self = this
console.debug("Updating preference", k, " to ", Utils.EllipsesAfter(v, 15))
-
+ if (this._fakeUser) {
+ return
+ }
if (v === undefined || v === "") {
this.auth.xhr(
{
method: "DELETE",
path: "/api/0.6/user/preferences/" + encodeURIComponent(k),
- options: { header: { "Content-Type": "text/plain" } },
+ headers: { "Content-Type": "text/plain" },
},
function (error) {
if (error) {
@@ -297,7 +316,7 @@ export class OsmPreferences {
{
method: "PUT",
path: "/api/0.6/user/preferences/" + encodeURIComponent(k),
- options: { header: { "Content-Type": "text/plain" } },
+ headers: { "Content-Type": "text/plain" },
content: v,
},
function (error) {
@@ -311,14 +330,4 @@ export class OsmPreferences {
}
)
}
-
- removeAllWithPrefix(prefix: string) {
- for (const key in this.preferences.data) {
- if (key.startsWith(prefix)) {
- this.GetPreference(key, "", { prefix: "" }).setData(undefined)
- console.log("Clearing preference", key)
- }
- }
- this.preferences.ping()
- }
}
diff --git a/src/UI/ThemeViewGUI.svelte b/src/UI/ThemeViewGUI.svelte
index 69dc3a8b34..2305e0d31f 100644
--- a/src/UI/ThemeViewGUI.svelte
+++ b/src/UI/ThemeViewGUI.svelte
@@ -257,6 +257,9 @@
Testmode
+
+ Faking a user (Testmode)
+