mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 02:08:47 +00:00
commit
b769ab930a
@ -565,7 +565,7 @@ exports.unverifyUser = (req, res) => {
|
|||||||
|
|
||||||
// Returns all the DMs that the user is currently participating in
|
// Returns all the DMs that the user is currently participating in
|
||||||
exports.getDirectMessages = (req, res) => {
|
exports.getDirectMessages = (req, res) => {
|
||||||
/* Return value
|
/* Return value
|
||||||
* data: [DMs]
|
* data: [DMs]
|
||||||
* dm : {
|
* dm : {
|
||||||
* dmId: str
|
* dmId: str
|
||||||
@ -681,20 +681,16 @@ exports.getDirectMessages = (req, res) => {
|
|||||||
|
|
||||||
// Get all the data from the users to get the data on whether they have DMs enabled or not
|
// Get all the data from the users to get the data on whether they have DMs enabled or not
|
||||||
let userPromises = [];
|
let userPromises = [];
|
||||||
dmRecipients.forEach((recipient) => {
|
dmRecipients.forEach(recipient => {
|
||||||
userPromises.push(
|
userPromises.push(db.doc(`/users/${recipient}`).get());
|
||||||
db.doc(`/users/${recipient}`)
|
});
|
||||||
.get()
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
// Wait for all DM document promises to resolve before returning data
|
// Wait for all DM document promises to resolve before returning data
|
||||||
Promise.all(dmPromises)
|
Promise.all(dmPromises)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return Promise.all(userPromises)
|
return Promise.all(userPromises);
|
||||||
})
|
})
|
||||||
.then((userData) => {
|
.then(userData => {
|
||||||
// Sort the DMs so that the ones with the newest messages are at the top
|
// Sort the DMs so that the ones with the newest messages are at the top
|
||||||
dmsData.sort((a, b) => {
|
dmsData.sort((a, b) => {
|
||||||
if (
|
if (
|
||||||
@ -721,15 +717,21 @@ exports.getDirectMessages = (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dmsData.forEach((dm) => {
|
dmsData.forEach(dm => {
|
||||||
dm.hasDirectMessagesEnabled = userData.find((user) => {
|
dm.hasDirectMessagesEnabled =
|
||||||
|
userData
|
||||||
|
.find(user => {
|
||||||
if (dm.recipient === user.data().handle) {
|
if (dm.recipient === user.data().handle) {
|
||||||
return true
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false;
|
||||||
}}).data().dmEnabled === false ? false : true
|
}
|
||||||
})
|
})
|
||||||
return res.status(200).json({data: dmsData})
|
.data().dmEnabled === false
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
|
});
|
||||||
|
return res.status(200).json({ data: dmsData });
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
@ -864,7 +866,10 @@ oneWayCheck = (userA, userB) => {
|
|||||||
if (dmRecipient === userB) {
|
if (dmRecipient === userB) {
|
||||||
console.log(`You already have a DM with ${userB}`);
|
console.log(`You already have a DM with ${userB}`);
|
||||||
// reject(new Error(`You already have a DM with ${userB}`));
|
// reject(new Error(`You already have a DM with ${userB}`));
|
||||||
reject({code: 400, message: `You already have a DM with that user`});
|
reject({
|
||||||
|
code: 400,
|
||||||
|
message: `You already have a DM with that user`
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -984,21 +989,30 @@ exports.sendDirectMessage = (req, res) => {
|
|||||||
|
|
||||||
db.doc(`/users/${recipient}`)
|
db.doc(`/users/${recipient}`)
|
||||||
.get()
|
.get()
|
||||||
.then((recipDoc) => {
|
.then(recipDoc => {
|
||||||
// Return if the other user has DM's disabled
|
// Return if the other user has DM's disabled
|
||||||
if (recipDoc.data().dmEnabled === false && recipDoc.data().dmEnabled !== null && recipDoc.data().dmEnabled !== undefined) {
|
if (
|
||||||
return res.status(400).json({error: "This user has DMs disabled"});
|
recipDoc.data().dmEnabled === false &&
|
||||||
|
recipDoc.data().dmEnabled !== null &&
|
||||||
|
recipDoc.data().dmEnabled !== undefined
|
||||||
|
) {
|
||||||
|
return res.status(400).json({ error: "This user has DMs disabled" });
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
db.doc(`/users/${creator}`).get()
|
db.doc(`/users/${creator}`)
|
||||||
.then((userDoc) => {
|
.get()
|
||||||
|
.then(userDoc => {
|
||||||
let dmList = userDoc.data().dms;
|
let dmList = userDoc.data().dms;
|
||||||
|
|
||||||
// Return if the creator doesn't have any DMs.
|
// Return if the creator doesn't have any DMs.
|
||||||
// This means they have not created a DM's channel yet
|
// This means they have not created a DM's channel yet
|
||||||
if (dmList === null || dmList === undefined) {
|
if (dmList === null || dmList === undefined) {
|
||||||
return res.status(400).json({error: `There is no DM channel between ${creator} and ${recipient}. Use /api/dms/new.`})
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({
|
||||||
|
error: `There is no DM channel between ${creator} and ${recipient}. Use /api/dms/new.`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let dmRefPromises = [];
|
let dmRefPromises = [];
|
||||||
@ -1181,7 +1195,7 @@ exports.addSubscription = (req, res) => {
|
|||||||
const struct = {
|
const struct = {
|
||||||
handle: req.body.following,
|
handle: req.body.following,
|
||||||
topics: ["Admin"]
|
topics: ["Admin"]
|
||||||
}
|
};
|
||||||
new_following
|
new_following
|
||||||
? new_following.push(struct)
|
? new_following.push(struct)
|
||||||
: (new_following = req.body.following);
|
: (new_following = req.body.following);
|
||||||
@ -1357,7 +1371,7 @@ exports.removeSub = (req, res) => {
|
|||||||
new_following = doc.data().following;
|
new_following = doc.data().following;
|
||||||
// remove username from array
|
// remove username from array
|
||||||
new_following.forEach(function(follower, index) {
|
new_following.forEach(function(follower, index) {
|
||||||
if (follower === `${req.body.unfollow}`) {
|
if (follower.handle === `${req.body.unfollow}`) {
|
||||||
new_following.splice(index, 1);
|
new_following.splice(index, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -93,7 +93,8 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
console.log("removed sub");
|
console.log("removed sub");
|
||||||
this.setState({
|
this.setState({
|
||||||
following: false
|
following: false,
|
||||||
|
myTopics: []
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
@ -201,10 +202,9 @@ class user extends Component {
|
|||||||
} else {
|
} else {
|
||||||
alertPromise = new Promise((resolve, reject) => {
|
alertPromise = new Promise((resolve, reject) => {
|
||||||
resolve();
|
resolve();
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Promise.all([otherUserPromise, userPromise, posts, alertPromise])
|
Promise.all([otherUserPromise, userPromise, posts, alertPromise])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({ loading: false });
|
this.setState({ loading: false });
|
||||||
@ -254,18 +254,20 @@ class user extends Component {
|
|||||||
this.state.myTopics.includes(topic) ? (
|
this.state.myTopics.includes(topic) ? (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={topic}
|
||||||
key={{ topic }.topic.id} // BUG: this value is undefined
|
key={{ topic }.id}
|
||||||
onDelete
|
onDelete
|
||||||
deleteIcon={<DoneIcon />}
|
deleteIcon={<DoneIcon />}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : this.state.following ? (
|
||||||
<MyChip
|
<MyChip
|
||||||
label={topic}
|
label={topic}
|
||||||
key={{ topic }.topic.id} // BUG: this value is undefined
|
key={{ topic }.id}
|
||||||
color="secondary"
|
color="secondary"
|
||||||
clickable
|
clickable
|
||||||
onClick={key => this.handleAdd(topic)}
|
onClick={key => this.handleAdd(topic)}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<MyChip label={topic} key={{ topic }.id} color="secondary" />
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<p></p>
|
<p></p>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user