From c75fd8e77701605e97ce070a3546ee39c7df138b Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:14:46 -0500 Subject: [PATCH 01/13] Rename file to avoid confusion --- .../{getConnectedUsers.ts => getMultipleConnectedUsers.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/src/actions/{getConnectedUsers.ts => getMultipleConnectedUsers.ts} (100%) diff --git a/server/src/actions/getConnectedUsers.ts b/server/src/actions/getMultipleConnectedUsers.ts similarity index 100% rename from server/src/actions/getConnectedUsers.ts rename to server/src/actions/getMultipleConnectedUsers.ts From ee6df1d445056fc80857bc773a0e77c98eaaccfc Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:17:01 -0500 Subject: [PATCH 02/13] Add function to get display name --- server/src/actions/getSingleConnectedUser.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 server/src/actions/getSingleConnectedUser.ts diff --git a/server/src/actions/getSingleConnectedUser.ts b/server/src/actions/getSingleConnectedUser.ts new file mode 100644 index 000000000..d9bda18fd --- /dev/null +++ b/server/src/actions/getSingleConnectedUser.ts @@ -0,0 +1,11 @@ +import { connectedUsersCollection } from '../utilities/firebaseInit' + +export const getConnectedUserDisplayName = async (socketID: string) => { + try { + return connectedUsersCollection.doc(socketID).displayName; + } catch (error) { + console.error(error); + return null; + } +} + From 70f05ff43aa93c1dea36793158940f05a14b1471 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:19:55 -0500 Subject: [PATCH 03/13] Add function to update display name --- server/src/actions/updateConnectedUser.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/actions/updateConnectedUser.ts b/server/src/actions/updateConnectedUser.ts index 59bfe7c54..c05421f12 100644 --- a/server/src/actions/updateConnectedUser.ts +++ b/server/src/actions/updateConnectedUser.ts @@ -26,3 +26,13 @@ export const updateUserLocation = async (socketID: string, lat: number, lon: num return false } } + +export const updateUserDisplayName = async (socketID: string, displayName: string) => { + try { + await connectedUsersCollection.doc(socketID).update({ displayName: displayName }) + return true + } catch (error) { + console.error(error.message) + return false + } +} From e4de3316e8242da93deb7d4b1cd2b85a91558bd8 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:21:46 -0500 Subject: [PATCH 04/13] Add socket hooks to activate based on display name related actions --- server/src/index.ts | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index c2e4932b2..456873324 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -4,10 +4,11 @@ import 'geofire-common' import { Message } from './types/Message'; import { createMessage } from './actions/createMessage' import { createUser } from './actions/createConnectedUser' -import { toggleUserConnectionStatus, updateUserLocation } from './actions/updateConnectedUser' +import { toggleUserConnectionStatus, updateUserLocation, updateUserDisplayName } from './actions/updateConnectedUser' import { deleteConnectedUserByUID } from './actions/deleteConnectedUser' +import { getConnectedUserDisplayName } from './actions/getSingleConnectedUser' import {geohashForLocation} from 'geofire-common'; -import { findNearbyUsers } from './actions/getConnectedUsers' +import { findNearbyUsers } from './actions/getMultipleConnectedUsers' import { ConnectedUser } from './types/User'; import { getAuth } from 'firebase-admin/auth'; @@ -132,8 +133,33 @@ io.on('connection', async (socket: any) => { console.error("[WS] Error calling updateLocation:", error.message) } }) + socket.on('updateDisplayName', async (newDisplayName, ack) => { + try { + const success = await updateUserDisplayName(socket.id, newDisplayName) + if (success) { + console.log(`[WS] Updated display name of user <${socket.id}> to <${newDisplayName}> successfully.`) + if (ack) ack("display name updated") + } else { + throw new Error("updateDisplayName() failed.") + } + } catch (error) { + console.error("[WS] Error calling updateDisplayName:", error.message) + } + }) + socket.on('retrieveDisplayName', async (ack) => { + try { + const success = await getConnectedUserDisplayName(socket.id) + if (success) { + console.log(`[WS] Retrieved display name of user <${socket.id}> successfully.`) + if (ack) ack("display name retrieved") + } else { + throw new Error("retrieveDisplayName() failed.") + } + } catch (error) { + console.error("[WS] Error calling retrieveDisplayName:", error.message) + } + }) }) - socketServer.listen(socket_port, () => { console.log(`[WS] Listening for new connections on port ${socket_port}.`) }) From 9bef6d4355b207f8cf980ac383ef1aee04d2b00e Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Sat, 2 Mar 2024 16:26:47 -0500 Subject: [PATCH 05/13] Update dependencies in lockfile --- client/package-lock.json | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/client/package-lock.json b/client/package-lock.json index 853ac67d0..eb11d1b71 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -30,9 +30,11 @@ "react": "18.2.0", "react-native": "0.72.6", "react-native-dotenv": "^3.4.9", + "react-native-feather": "^1.1.2", "react-native-fs": "^2.20.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", + "react-native-svg": "13.9.0", "react-native-uuid": "^2.0.1", "react-native-web": "~0.19.6", "socket.io-client": "^4.7.4" @@ -17609,6 +17611,15 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/react-native-feather": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/react-native-feather/-/react-native-feather-1.1.2.tgz", + "integrity": "sha512-qBc0+XegKkX4JV6ykgScasguEV3RdlbYp9IrCMnbozngOgJ7vi76pyRpb+dnZ1AZVkYsbYnpdA9JXeP7EJbMCA==", + "peerDependencies": { + "react-native": ">=0.46", + "react-native-svg": ">=5.3" + } + }, "node_modules/react-native-fs": { "version": "2.20.0", "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.20.0.tgz", @@ -17666,6 +17677,85 @@ "react-native": "*" } }, + "node_modules/react-native-svg": { + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/react-native-svg/-/react-native-svg-13.9.0.tgz", + "integrity": "sha512-Ey18POH0dA0ob/QiwCBVrxIiwflhYuw0P0hBlOHeY4J5cdbs8ngdKHeWC/Kt9+ryP6fNoEQ1PUgPYw2Bs/rp5Q==", + "dependencies": { + "css-select": "^5.1.0", + "css-tree": "^1.1.3" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + } + }, + "node_modules/react-native-svg/node_modules/css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "dependencies": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/react-native-svg/node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/react-native-svg/node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/react-native-svg/node_modules/domutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz", + "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/react-native-svg/node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/react-native-uuid": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/react-native-uuid/-/react-native-uuid-2.0.1.tgz", From ca9bbe23fa21c3e306b53e9761d1ddbb7693f2f2 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:03:49 -0400 Subject: [PATCH 06/13] Move all functions related to getting user info into one file --- ...MultipleConnectedUsers.ts => getConnectedUsers.ts} | 10 ++++++++++ server/src/actions/getSingleConnectedUser.ts | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) rename server/src/actions/{getMultipleConnectedUsers.ts => getConnectedUsers.ts} (90%) delete mode 100644 server/src/actions/getSingleConnectedUser.ts diff --git a/server/src/actions/getMultipleConnectedUsers.ts b/server/src/actions/getConnectedUsers.ts similarity index 90% rename from server/src/actions/getMultipleConnectedUsers.ts rename to server/src/actions/getConnectedUsers.ts index c61657006..a98cf4d24 100644 --- a/server/src/actions/getMultipleConnectedUsers.ts +++ b/server/src/actions/getConnectedUsers.ts @@ -1,6 +1,16 @@ import { distanceBetween, geohashForLocation, geohashQueryBounds } from 'geofire-common' import { connectedUsersCollection } from '../utilities/firebaseInit' +export const getConnectedUserDisplayName = async (socketID: string) => { + try { + return connectedUsersCollection.doc(socketID).displayName; + } catch (error) { + console.error(error); + return null; + } +} + + export const findNearbyUsers = async (centerLat: number, centerLon: number, radius: number) => { // Return an array of nearby userIds (which are also socket ids) given a center latitude and longitude. // Latitude and longitude values use degrees with the same bounds as GeoPoints. Radius values use meters. diff --git a/server/src/actions/getSingleConnectedUser.ts b/server/src/actions/getSingleConnectedUser.ts deleted file mode 100644 index d9bda18fd..000000000 --- a/server/src/actions/getSingleConnectedUser.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { connectedUsersCollection } from '../utilities/firebaseInit' - -export const getConnectedUserDisplayName = async (socketID: string) => { - try { - return connectedUsersCollection.doc(socketID).displayName; - } catch (error) { - console.error(error); - return null; - } -} - From cf586832d2281001e5aab4ce19be5e3b4acb9fd3 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:05:24 -0400 Subject: [PATCH 07/13] Make some socket calls REST API calls to avoid overloading traffic --- server/src/index.ts | 59 ++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index be5522997..9451833d8 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,14 +1,13 @@ -import express from 'express' -import 'dotenv/config' -import 'geofire-common' +import express from 'express'; +import 'dotenv/config'; +import 'geofire-common'; import { Message } from './types/Message'; -import { createMessage } from './actions/createMessage' -import { createUser } from './actions/createConnectedUser' -import { toggleUserConnectionStatus, updateUserLocation, updateUserDisplayName } from './actions/updateConnectedUser' -import { deleteConnectedUserByUID } from './actions/deleteConnectedUser' -import { getConnectedUserDisplayName } from './actions/getSingleConnectedUser' +import { createMessage } from './actions/createMessage'; +import { createUser } from './actions/createConnectedUser'; +import { toggleUserConnectionStatus, updateUserLocation, updateUserDisplayName } from './actions/updateConnectedUser'; +import { deleteConnectedUserByUID } from './actions/deleteConnectedUser'; +import { findNearbyUsers, getConnectedUserDisplayName } from './actions/getConnectedUsers'; import {geohashForLocation} from 'geofire-common'; -import { findNearbyUsers } from './actions/getMultipleConnectedUsers' import { ConnectedUser } from './types/User'; import { getAuth } from 'firebase-admin/auth'; @@ -142,32 +141,6 @@ io.on("connection", async (socket: any) => { console.error("[WS] Error calling updateLocation:", error.message); } }) - socket.on('updateDisplayName', async (newDisplayName, ack) => { - try { - const success = await updateUserDisplayName(socket.id, newDisplayName) - if (success) { - console.log(`[WS] Updated display name of user <${socket.id}> to <${newDisplayName}> successfully.`) - if (ack) ack("display name updated") - } else { - throw new Error("updateDisplayName() failed.") - } - } catch (error) { - console.error("[WS] Error calling updateDisplayName:", error.message) - } - }) - socket.on('retrieveDisplayName', async (ack) => { - try { - const success = await getConnectedUserDisplayName(socket.id) - if (success) { - console.log(`[WS] Retrieved display name of user <${socket.id}> successfully.`) - if (ack) ack("display name retrieved") - } else { - throw new Error("retrieveDisplayName() failed.") - } - } catch (error) { - console.error("[WS] Error calling retrieveDisplayName:", error.message) - } - }) }) socketServer.listen(socket_port, () => { console.log(`[WS] Listening for new connections on port ${socket_port}.`); @@ -193,6 +166,13 @@ app.get("/users", async (req, res) => { const userIds = await findNearbyUsers(lat, lon, radius); console.log(userIds); res.json(userIds); + } else if (req.query.userId) { + query = "?userId"; + const userId = req.query.userId; + if (typeof userId != "string") throw Error(" [userId] is not a string."); + + const success = await getConnectedUserDisplayName(userId); + if (!success) throw Error("getConnectedUserDisplayName() failed."); } } catch (error) { console.error( @@ -253,6 +233,15 @@ app.put("/users", async (req, res) => { const success = await updateUserLocation(userId, lat, lon); if (!success) throw Error(" toggleUserConnectionStatus() failed."); + } else if (req.query.userId && req.query.displayName) { + query = "?userId&displayName"; + const userId = req.query.userId; + if (typeof userId != "string") throw Error(" [userId] is not a string."); + const displayName = req.query.displayName; + if (typeof displayName != "string") throw Error(" [displayName] is not a string."); + + const success = await updateUserDisplayName(userId, displayName); + if (!success) throw Error("updateDisplayName() failed."); } console.log(`[EXP] Request returned successfully.`); res.json(`Operation was handled successfully.`); From 9b68d3e79fb53733e179abdbbf0f75061938fc85 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:49:58 -0400 Subject: [PATCH 08/13] Send JSON response on success --- server/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 9451833d8..bf6916f21 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -164,14 +164,16 @@ app.get("/users", async (req, res) => { const radius = Number(req.query.radius); const userIds = await findNearbyUsers(lat, lon, radius); - console.log(userIds); res.json(userIds); } else if (req.query.userId) { query = "?userId"; const userId = req.query.userId; if (typeof userId != "string") throw Error(" [userId] is not a string."); - + const success = await getConnectedUserDisplayName(userId); + if (success) { + res.json(success); + } if (!success) throw Error("getConnectedUserDisplayName() failed."); } } catch (error) { From 17ae0691277ee8369a220dec9bd3e7f1d6472999 Mon Sep 17 00:00:00 2001 From: Aadit Kamat <30969577+aaditkamat@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:50:56 -0400 Subject: [PATCH 09/13] Fix error fetching connected user info --- server/src/actions/getConnectedUsers.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/actions/getConnectedUsers.ts b/server/src/actions/getConnectedUsers.ts index a98cf4d24..3e038e979 100644 --- a/server/src/actions/getConnectedUsers.ts +++ b/server/src/actions/getConnectedUsers.ts @@ -3,7 +3,10 @@ import { connectedUsersCollection } from '../utilities/firebaseInit' export const getConnectedUserDisplayName = async (socketID: string) => { try { - return connectedUsersCollection.doc(socketID).displayName; + const snap = await connectedUsersCollection.doc(socketID).get(); + return { + "displayName": snap.data().displayName + } } catch (error) { console.error(error); return null; From 49678a5ed2d568e6a4094d77bd4688d85406279b Mon Sep 17 00:00:00 2001 From: h1divp <71522316+h1divp@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:24:33 -0400 Subject: [PATCH 10/13] Re-added mailgun import --- server/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/index.ts b/server/src/index.ts index bf6916f21..990894767 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -10,7 +10,7 @@ import { findNearbyUsers, getConnectedUserDisplayName } from './actions/getConne import {geohashForLocation} from 'geofire-common'; import { ConnectedUser } from './types/User'; import { getAuth } from 'firebase-admin/auth'; - +import Mailgun from "mailgun.js"; const { createServer } = require("http"); const { Server } = require("socket.io"); From ca66f6f7b45b05f866ff4c6ecc0d4c33e044a7ef Mon Sep 17 00:00:00 2001 From: h1divp <71522316+h1divp@users.noreply.github.com> Date: Tue, 19 Mar 2024 20:38:31 -0400 Subject: [PATCH 11/13] variable name updates and other minor fixes --- server/src/actions/getConnectedUsers.ts | 9 ++++----- server/src/index.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/actions/getConnectedUsers.ts b/server/src/actions/getConnectedUsers.ts index 3e038e979..a94db543f 100644 --- a/server/src/actions/getConnectedUsers.ts +++ b/server/src/actions/getConnectedUsers.ts @@ -3,17 +3,16 @@ import { connectedUsersCollection } from '../utilities/firebaseInit' export const getConnectedUserDisplayName = async (socketID: string) => { try { - const snap = await connectedUsersCollection.doc(socketID).get(); + const user = await connectedUsersCollection.doc(socketID).get(); return { - "displayName": snap.data().displayName + "displayName": user.data().displayName } } catch (error) { - console.error(error); - return null; + console.error("getConnectedUserDisplayName() failed:", error.message); + return false; } } - export const findNearbyUsers = async (centerLat: number, centerLon: number, radius: number) => { // Return an array of nearby userIds (which are also socket ids) given a center latitude and longitude. // Latitude and longitude values use degrees with the same bounds as GeoPoints. Radius values use meters. diff --git a/server/src/index.ts b/server/src/index.ts index 990894767..1a445f65a 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -170,11 +170,13 @@ app.get("/users", async (req, res) => { const userId = req.query.userId; if (typeof userId != "string") throw Error(" [userId] is not a string."); - const success = await getConnectedUserDisplayName(userId); - if (success) { - res.json(success); + const displayName = await getConnectedUserDisplayName(userId); + if (displayName) { + res.json(displayName); + } else { + // getConnectedUserDisplayName() will return false is an error is thrown, and print it to console. + throw Error("getConnectedUserDisplayName() failed."); } - if (!success) throw Error("getConnectedUserDisplayName() failed."); } } catch (error) { console.error( From aa9fef5c923c7ce630fae0ca0678b12c6bf243c1 Mon Sep 17 00:00:00 2001 From: h1divp <71522316+h1divp@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:06:49 -0400 Subject: [PATCH 12/13] Changed getConnectedUserDisplayName() to getConnectedUser(), and return all ConnectedUser document information. Updated /users?userId GET endpoint to match this change. --- server/src/actions/getConnectedUsers.ts | 8 +++----- server/src/index.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/src/actions/getConnectedUsers.ts b/server/src/actions/getConnectedUsers.ts index a94db543f..30724cc52 100644 --- a/server/src/actions/getConnectedUsers.ts +++ b/server/src/actions/getConnectedUsers.ts @@ -1,14 +1,12 @@ import { distanceBetween, geohashForLocation, geohashQueryBounds } from 'geofire-common' import { connectedUsersCollection } from '../utilities/firebaseInit' -export const getConnectedUserDisplayName = async (socketID: string) => { +export const getConnectedUser = async (socketID: string) => { try { const user = await connectedUsersCollection.doc(socketID).get(); - return { - "displayName": user.data().displayName - } + return user.data(); } catch (error) { - console.error("getConnectedUserDisplayName() failed:", error.message); + console.error("getConnectedUser failed:", error.message); return false; } } diff --git a/server/src/index.ts b/server/src/index.ts index 1a445f65a..a22dbc2e0 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -6,7 +6,7 @@ import { createMessage } from './actions/createMessage'; import { createUser } from './actions/createConnectedUser'; import { toggleUserConnectionStatus, updateUserLocation, updateUserDisplayName } from './actions/updateConnectedUser'; import { deleteConnectedUserByUID } from './actions/deleteConnectedUser'; -import { findNearbyUsers, getConnectedUserDisplayName } from './actions/getConnectedUsers'; +import { findNearbyUsers, getConnectedUser } from './actions/getConnectedUsers'; import {geohashForLocation} from 'geofire-common'; import { ConnectedUser } from './types/User'; import { getAuth } from 'firebase-admin/auth'; @@ -165,17 +165,18 @@ app.get("/users", async (req, res) => { const userIds = await findNearbyUsers(lat, lon, radius); res.json(userIds); + } else if (req.query.userId) { query = "?userId"; const userId = req.query.userId; if (typeof userId != "string") throw Error(" [userId] is not a string."); - const displayName = await getConnectedUserDisplayName(userId); - if (displayName) { - res.json(displayName); + const user = await getConnectedUser(userId); + if (user) { + res.json(user); } else { // getConnectedUserDisplayName() will return false is an error is thrown, and print it to console. - throw Error("getConnectedUserDisplayName() failed."); + throw Error("getConnectedUser() failed."); } } } catch (error) { @@ -226,6 +227,7 @@ app.put("/users", async (req, res) => { const success = await toggleUserConnectionStatus(userId); if (!success) throw Error(" toggleUserConnectionStatus() failed."); + } else if (req.query.userId && req.query.lat && req.query.lon) { query = "?userId&lat&lon"; const userId = req.query.userId; @@ -237,6 +239,7 @@ app.put("/users", async (req, res) => { const success = await updateUserLocation(userId, lat, lon); if (!success) throw Error(" toggleUserConnectionStatus() failed."); + } else if (req.query.userId && req.query.displayName) { query = "?userId&displayName"; const userId = req.query.userId; @@ -249,6 +252,7 @@ app.put("/users", async (req, res) => { } console.log(`[EXP] Request returned successfully.`); res.json(`Operation was handled successfully.`); + } catch (error) { console.error( `[EXP] Error returning request :\n`, From 9868ed4b2ab805f225d7223d3a53a2253fdeeb44 Mon Sep 17 00:00:00 2001 From: h1divp <71522316+h1divp@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:45:02 -0400 Subject: [PATCH 13/13] Minor comment change --- server/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/index.ts b/server/src/index.ts index a22dbc2e0..202a50f8b 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -251,7 +251,7 @@ app.put("/users", async (req, res) => { if (!success) throw Error("updateDisplayName() failed."); } console.log(`[EXP] Request returned successfully.`); - res.json(`Operation was handled successfully.`); + res.json(`Operation was handled successfully.`); } catch (error) { console.error(