v1.6.0/added support, cleanup webhook
This commit is contained in:
@@ -2,18 +2,6 @@ const admin = require('firebase-admin');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { player, roomId, uid, showChanged, userName } = JSON.parse(req.body);
|
||||
// const statusString =
|
||||
// player.status === 'PLAYING'
|
||||
// ? 'started playing from'
|
||||
// : player.status === 'PAUSED'
|
||||
// ? 'paused at'
|
||||
// : player.status === 'NOT_PLAYING'
|
||||
// ? 'stopped at'
|
||||
// : 'is at';
|
||||
// const timeString =
|
||||
// player.time > 3600
|
||||
// ? new Date(player.time * 1000).toISOString().substr(11, 8)
|
||||
// : new Date(player.time * 1000).toISOString().substr(14, 5);
|
||||
if (!roomId) return res.status(204).send({ message: 'Party name not sent.' });
|
||||
const [roomExists, roomData] = await admin
|
||||
.firestore()
|
||||
@@ -32,17 +20,19 @@ module.exports = async (req, res) => {
|
||||
.then((userSnap) => userSnap.exists);
|
||||
if (userExists) {
|
||||
if (showChanged === true && player.showName) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(roomId)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `${userName} changed \n${player.showName ? 'to ' + player.showName : ''}`,
|
||||
time: new Date(),
|
||||
});
|
||||
if (roomData.player.showName !== player.showName) {
|
||||
await admin
|
||||
.firestore()
|
||||
.collection('rooms')
|
||||
.doc(roomId)
|
||||
.collection('messages')
|
||||
.add({
|
||||
uid: '<system>',
|
||||
name: '',
|
||||
text: `${userName} changed \n${player.showName ? 'to ' + player.showName : ''}`,
|
||||
time: new Date(),
|
||||
});
|
||||
}
|
||||
}
|
||||
if (roomData.status !== player.status) {
|
||||
await admin
|
||||
@@ -56,23 +46,6 @@ module.exports = async (req, res) => {
|
||||
console.error(`Failed to update player : \n\t Room: ${roomId} \n\t ${uid}`, err);
|
||||
res.status(500).send({ message: "Uh oh party could't be synced", err });
|
||||
});
|
||||
// await admin
|
||||
// .firestore()
|
||||
// .collection('rooms')
|
||||
// .doc(roomId)
|
||||
// .collection('messages')
|
||||
// .add({
|
||||
// uid: '<system>',
|
||||
// name: '',
|
||||
// text: `${userName} ${statusString} ${timeString}`,
|
||||
// time: new Date(),
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.error(
|
||||
// `Failed to add system update player message : \n\t Room: ${roomId} \n\t ${uid}`,
|
||||
// err
|
||||
// );
|
||||
// });
|
||||
return res.status(200).send({ message: 'Synced party player' });
|
||||
} else {
|
||||
return res.status(208).send({ message: 'Player already up to date' });
|
||||
|
||||
Reference in New Issue
Block a user