diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-01 18:59:47 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-01 18:59:47 -0700 |
commit | fd83ca07e5544a1d7b4a91e4c5f68a7f5f2189a6 (patch) | |
tree | 9152009542ba79aeeb7af9373e7da41ddc11ca52 /modern/src/common/components | |
parent | 76edb2c97cec70d6c26bc523ac8f64c80fb05c37 (diff) | |
download | trackermap-web-fd83ca07e5544a1d7b4a91e4c5f68a7f5f2189a6.tar.gz trackermap-web-fd83ca07e5544a1d7b4a91e4c5f68a7f5f2189a6.tar.bz2 trackermap-web-fd83ca07e5544a1d7b4a91e4c5f68a7f5f2189a6.zip |
Fix push token duplication
Diffstat (limited to 'modern/src/common/components')
-rw-r--r-- | modern/src/common/components/NativeInterface.js | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/modern/src/common/components/NativeInterface.js b/modern/src/common/components/NativeInterface.js index aee4c042..b36a3d26 100644 --- a/modern/src/common/components/NativeInterface.js +++ b/modern/src/common/components/NativeInterface.js @@ -36,24 +36,26 @@ const NativeInterface = () => { setToken(null); const tokens = user.attributes.notificationTokens?.split(',') || []; - const updatedUser = { - ...user, - attributes: { - ...user.attributes, - notificationTokens: [...tokens.slice(-2), token].join(','), - }, - }; + if (!tokens.includes(token)) { + const updatedUser = { + ...user, + attributes: { + ...user.attributes, + notificationTokens: [...tokens.slice(-2), token].join(','), + }, + }; - const response = await fetch(`/api/users/${user.id}`, { - method: 'PUT', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(updatedUser), - }); + const response = await fetch(`/api/users/${user.id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(updatedUser), + }); - if (response.ok) { - dispatch(sessionActions.updateUser(await response.json())); - } else { - throw Error(await response.text()); + if (response.ok) { + dispatch(sessionActions.updateUser(await response.json())); + } else { + throw Error(await response.text()); + } } } }, [user, token, setToken]); |