Created
November 18, 2017 20:47
-
-
Save drFabio/cc2f0db70463967d6d047c472a26eb9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sendMessage () { | |
idleButton() | |
var feedBack = document.getElementById('feedBack') | |
var question = document.getElementById("question").value.trim() | |
if (!question || question.length === 0){ | |
setError('Insira uma pergunta') | |
return | |
} | |
if (question === lastQuestion) { | |
setError('Você já perguntou isso....') | |
return | |
} | |
lastQuestion = question | |
if (!authenticated) { | |
setError('Logue, por favor') | |
return | |
} | |
if (sending) { | |
return | |
} | |
sending = true | |
newMessageRef = databaseRef.push() | |
var displayName = userAuthData.user.displayName | |
var email = userAuthData.user.email | |
if (!email && userAuthData.user.providerData) { | |
userAuthData.user.providerData.some(function (data) { | |
email = data.email | |
return data.email && data.email !== '' | |
}) | |
} | |
newMessageRef.set({question, createdAt, displayName, email}, (err) => { | |
sending = false | |
if (!err) { | |
setSuccessFeedback('Pergunta enviada!') | |
} else { | |
setError('Algo deu errado, tente novamente mais tarde ;)') | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment