diff --git a/functions/index.js b/functions/index.js index 4678afd..35ace51 100644 --- a/functions/index.js +++ b/functions/index.js @@ -45,8 +45,10 @@ return (exports.sendPushNotification = functions.firestore .doc(userId) .get() .then(doc => { - const { pushToken } = doc.data() - return admin.messaging().sendToDevice(pushToken, payload) + const { pushToken, notifications } = doc.data() + if (notifications) + return admin.messaging().sendToDevice(pushToken, payload) + else return null }) } })) diff --git a/src/Components/Config/configBody.js b/src/Components/Config/configBody.js index c7b0d54..b8d2aae 100644 --- a/src/Components/Config/configBody.js +++ b/src/Components/Config/configBody.js @@ -1,4 +1,4 @@ -import React from "react" +import React, { Component } from "react" import { View, StyleSheet, @@ -10,108 +10,138 @@ import { Share } from "react-native" import { Icon } from "react-native-elements" +import firebase from "react-native-firebase" -const configBody = props => { - const { navigation } = props - return ( - - - - Conta - - { - navigation.navigate("LanguagesScreen") - }} - > - - Idiomas - - - - +export default class configBody extends Component { + constructor() { + super() + this.state = { + switchState: false + } + this.ref = firebase + .firestore() + .collection("users") + .doc(firebase.auth().currentUser.uid) + } - { - navigation.navigate("EditPerfilScreen") - }} - > - - Perfil - - - - + componentDidMount() { + this.ref.get().then(doc => { + const { notifications } = doc.data() + this.setState({ switchState: notifications }) + }) + } - - - Notificação - - - - + switchHandler = () => { + const { switchState } = this.state + this.ref.update({ notifications: !switchState }) + this.setState(prevState => ({ switchState: !prevState.switchState })) + } - Aplicativo - + render() { + const { navigation } = this.props + const { switchState } = this.state + return ( + + + + Conta + + { + navigation.navigate("LanguagesScreen") + }} + > + + Idiomas + + + + - - - Enviar Feedback - + { + navigation.navigate("EditPerfilScreen") + }} + > + + Perfil + + + + - { - Share.share({ - message: - "Olá, já instalou o Unichat? Se não, é bem fácil. Apenas clique no link a seguir https://github.com/ES2-UFPI/Unichat/releases" - }) - }} - > - - Compartilhar App - + + + Notificação + + + + - - - Avaliar App - + Aplicativo + - { - Linking.openURL( - "https://github.com/ES2-UFPI/Unichat/blob/dev/PRIVACY-POLICY.md" - ) - }} - > - - Política de Privacidade - + + + Enviar Feedback + + + { + Share.share({ + message: + "Olá, já instalou o Unichat? Se não, é bem fácil. Apenas clique no link a seguir https://github.com/ES2-UFPI/Unichat/releases" + }) + }} + > + + Compartilhar App + - - - Sobre + + + Avaliar App + + { + Linking.openURL( + "https://github.com/ES2-UFPI/Unichat/blob/dev/PRIVACY-POLICY.md" + ) + }} + > + + Política de Privacidade + + + + + Sobre + + + + Excluir Conta - - - Excluir Conta - - - - ) + + + ) + } } const styles = StyleSheet.create({ @@ -169,5 +199,3 @@ const styles = StyleSheet.create({ marginRight: 20 } }) - -export default configBody diff --git a/src/Screens/PerfilSettings/perfilsettings.js b/src/Screens/PerfilSettings/perfilsettings.js index e8ce721..0fdd8f7 100644 --- a/src/Screens/PerfilSettings/perfilsettings.js +++ b/src/Screens/PerfilSettings/perfilsettings.js @@ -73,7 +73,8 @@ export default class PerfilSettings extends Component { language_code: code, profile_img_url: profileImageUrl, online: true, - lastSeen: "" + lastSeen: "", + notifications: true }) }) }