aboutsummaryrefslogtreecommitdiff
path: root/modern/src/store/session.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/store/session.js')
-rw-r--r--modern/src/store/session.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/modern/src/store/session.js b/modern/src/store/session.js
index 74dc29a0..121b47f5 100644
--- a/modern/src/store/session.js
+++ b/modern/src/store/session.js
@@ -7,6 +7,7 @@ const { reducer, actions } = createSlice({
user: null,
socket: null,
positions: {},
+ history: {},
},
reducers: {
updateServer(state, action) {
@@ -19,7 +20,18 @@ const { reducer, actions } = createSlice({
state.socket = action.payload;
},
updatePositions(state, action) {
- action.payload.forEach((position) => state.positions[position.deviceId] = position);
+ const liveRoutes = state.user.attributes.mapLiveRoutes || state.server.attributes.mapLiveRoutes || 'none';
+ const liveRoutesLimit = state.user.attributes['web.liveRouteLength'] || state.user.attributes['web.liveRouteLength'] || 10;
+ action.payload.forEach((position) => {
+ state.positions[position.deviceId] = position;
+ if (liveRoutes !== 'none') {
+ const route = state.history[position.deviceId] || [];
+ const last = route.at(-1);
+ if (!last || (last[0] !== position.longitude && last[1] !== position.latitude)) {
+ state.history[position.deviceId] = [...route.slice(1 - liveRoutesLimit), [position.longitude, position.latitude]];
+ }
+ }
+ });
},
},
});