diff --git a/src/app/domain/geolocation/tracking/index.js b/src/app/domain/geolocation/tracking/index.js index 9191cc698..c845f4ca5 100644 --- a/src/app/domain/geolocation/tracking/index.js +++ b/src/app/domain/geolocation/tracking/index.js @@ -25,12 +25,12 @@ import { WALKING_ACTIVITY, LOW_CONFIDENCE_THRESHOLD } from '/app/domain/geolocation/tracking/consts' +import { getOrCreateId } from '/app/domain/geolocation/tracking/user' export { Log, getAllLogs, sendLogFile } from '/app/domain/geolocation/helpers' export { getOrCreateId, updateId } from '/app/domain/geolocation/tracking/user' export { uploadData } from '/app/domain/geolocation/tracking/upload' export { GeolocationTrackingHeadlessTask } from '/app/domain/geolocation/tracking/headless' export { storeFetchServiceWebHook } from '/app/domain/geolocation/tracking/storage' -import { getOrCreateId } from '/app/domain/geolocation/tracking/user' export { clearAllCozyGPSMemoryData, @@ -228,6 +228,8 @@ export const startOpenPathUploadAndPipeline = async ({ }) => { try { const user = await getOrCreateId() + Log(`User: ${JSON.stringify(user)}`) + // Upload data to openpath server const uploadedCount = await uploadData(user, { untilTs, force }) if (uploadedCount >= 0) { diff --git a/src/app/domain/geolocation/tracking/tracking.js b/src/app/domain/geolocation/tracking/tracking.js index 94da49c5c..fc968e32b 100644 --- a/src/app/domain/geolocation/tracking/tracking.js +++ b/src/app/domain/geolocation/tracking/tracking.js @@ -1,5 +1,5 @@ import { uploadUserCache } from '/app/domain/geolocation/tracking/upload' -import { getOrCreateUser } from '/app/domain/geolocation/tracking/user' +import { createOpenPathUserIfMissing } from '/app/domain/geolocation/tracking/user' import { getTs, Log, parseISOString } from '/app/domain/geolocation/helpers' import { getActivities, @@ -57,7 +57,7 @@ export const uploadTrackingData = async ( user, { force = false } = {} ) => { - await getOrCreateUser(user) + await createOpenPathUserIfMissing(user) if (!locations || locations.length === 0) { Log('No new locations') @@ -483,7 +483,9 @@ export const getFilteredActivities = async ({ beforeTs, locations }) => { if (isMovingStillActivity(loc) || isUnknownActivity(loc)) { // Avoid unknown or "moving" still activities location.activity.type = inferMotionActivity(loc) - Log('Changed ' + loc.activity.type + ' to: ' + location.activity.type) + if (loc.activity.type !== location.activity.type) { + Log('Changed ' + loc.activity.type + ' to: ' + location.activity.type) + } } return translateEventToEMissionMotionActivity(location) }) diff --git a/src/app/domain/geolocation/tracking/user.js b/src/app/domain/geolocation/tracking/user.js index b5ec8e182..02920f233 100644 --- a/src/app/domain/geolocation/tracking/user.js +++ b/src/app/domain/geolocation/tracking/user.js @@ -26,6 +26,9 @@ export const getOrCreateId = async () => { } export const createUser = async user => { + Log( + `Request openpath server to create new user with id ${JSON.stringify(user)}` + ) let response = await fetch(SERVER_URL + '/profile/create', { method: 'POST', headers: { @@ -38,11 +41,16 @@ export const createUser = async user => { throw new Error('FAILED_EMISSION_USER_CREATION') // Could be no Internet, offline server or unknown issue. Won't trigger if user already exists. } else { const jsonTokenResponse = await response.json() - Log('Success creating user ' + user + ', UUID: ' + jsonTokenResponse.uuid) + Log( + 'Success creating user ' + + JSON.stringify(user) + + ', UUID: ' + + jsonTokenResponse.uuid + ) } } -export const getOrCreateUser = async user => { +export const createOpenPathUserIfMissing = async user => { let response try { const respFetch = await fetch(SERVER_URL + '/profile/get', { @@ -53,15 +61,19 @@ export const getOrCreateUser = async user => { body: JSON.stringify({ user: user }) }) if (respFetch.status === 403) { + Log("No openpath user found, let's create one.") return createUser(user) } response = await respFetch.json() const uuid = response?.user_id?.['$uuid'] if (!uuid) { + Log("No openpath uuid found, let's create the user.") await createUser(user) } return uuid } catch (err) { + // If the user actually exist, the creation will return the existing user + Log(`Error when trying to get openpath user, let's create one`) return createUser(user) } }