mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-15 18:08:46 +00:00
Check for DMs enabled or disabled
This commit is contained in:
parent
a2ed627f2b
commit
19d78596b5
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user