diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 01068cf..218d31a 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -518,6 +518,43 @@ exports.getDirectMessages = (req, res) => { }); } +// Sends a DM from the caller to the requested DM document +exports.sendDirectMessage = (req, res) => { + return res.status(200).json({message: "Not implemented yet"}) +} + +// Creates a DM between the caller and the user in the request +exports.createDirectMessage = (req, res) => { + return res.status(200).json({message: "Not implemented yet"}) +} + +// Checks if the requested user has DMs enable or not +exports.checkDirectMessagesEnabled = (req, res) => { + username = req.body.user; + if (username === null || username === undefined) return res.status(400).json({error: "No user was sent in the request. The request should have a 'user' key."}); + + db.doc(`/users/${username}`) + .get() + .then((doc) => { + if (doc.exists) { + console.log(doc.data()) + if (doc.data().dmEnabled === true || doc.data().dmEnabled === null || doc.data().dmEnabled === undefined) { + // Assume DMs are enabled if they don't have a dmEnabled key + return res.status(200).json({enabled: true}); + } else { + return res.status(200).json({enabled: false}); + } + } else { + console.log(`${username} is not in the database`); + return res.status(400).json({error: `${username} is not in the database`}); + } + }) + .catch((err) => { + console.error(err); + return res.status(500).json({error: err}); + }) +} + exports.getUserHandles = (req, res) => { admin .firestore() diff --git a/functions/index.js b/functions/index.js index eea2c86..ca249d0 100644 --- a/functions/index.js +++ b/functions/index.js @@ -12,6 +12,9 @@ app.use(cors()); const { getAuthenticatedUser, getDirectMessages, + sendDirectMessage, + createDirectMessage, + checkDirectMessagesEnabled, getUserDetails, getProfileInfo, login, @@ -36,7 +39,16 @@ app.post("/login", login); app.delete("/delete", fbAuth, deleteUser); // Returns all direct messages that the user is participating in -app.get("/dm", fbAuth, getDirectMessages); +app.get("/dms", fbAuth, getDirectMessages); + +// Send a message in a DM from one user to another +app.post("/dms/send", fbAuth, sendDirectMessage); + +// Create a new DM between two users +app.post("/dms/new", fbAuth, createDirectMessage); + +// Checks if the user provided has DMs enabled or not +app.get("/dms/enabled", checkDirectMessagesEnabled); app.get("/getUser", fbAuth, getUserDetails); @@ -46,6 +58,7 @@ app.get("/getProfileInfo", fbAuth, getProfileInfo); // Updates the currently logged in user's profile information app.post("/updateProfileInfo", fbAuth, updateProfileInfo); +// Gets all user data for the logged in user app.get("/user", fbAuth, getAuthenticatedUser); // Verifies the user sent to the request