Added email setting and improved reactivity

This commit is contained in:
Kevin F 2022-12-15 22:37:54 +00:00
parent eba1dbe435
commit 6d5494a851
2 changed files with 104 additions and 6 deletions

View File

@ -54,6 +54,10 @@
</div> </div>
<div v-else> <div v-else>
<div>
<button v-if="email" @click="setEmail()">Change/Disable Email Relaying</button>
<button v-else @click="setEmail()">Set Email Relaying</button>
</div>
<form class="draft" @submit="sendSMS" @submit.prevent="onSubmit"> <form class="draft" @submit="sendSMS" @submit.prevent="onSubmit">
<label> <label>
Phone Number: Phone Number:
@ -69,9 +73,12 @@
<div v-if="threads.length"> <div v-if="threads.length">
<br> <br>
<span v-for="person in threads"> <span v-for="person in threads">
<button @click="openThread(person)">{{ formatPhone(person) }} - Open Thread</button> <div v-if="person">
<button @click="deleteThread(person)" class="danger">Delete Thread</button> <button @click="openThread(person)">{{ formatPhone(person) }} - Open Thread</button>
<br><br> <button @click="deleteThread(person)" class="danger">Delete Thread</button>
<br><br>
</div>
</span> </span>
<div v-if="showingThreadNum"> <div v-if="showingThreadNum">
<div v-for="message in threadMessages"> <div v-for="message in threadMessages">

97
main.js
View File

@ -18,7 +18,7 @@ let app = createApp({
userIDInput: '', userIDInput: '',
userID: "", userID: "",
showUserID: "", showUserID: "",
backend: 'https://api.sms.voidnet.tech/', backend: 'http://staging.chaoswebs.net/',
availableNumbers: "", availableNumbers: "",
credits: "", credits: "",
threads: [], threads: [],
@ -35,7 +35,8 @@ let app = createApp({
threadMessages: [], threadMessages: [],
lastThreadLineHeader: 0, lastThreadLineHeader: 0,
threadLineHeader: 0, threadLineHeader: 0,
pricingInfo: "" pricingInfo: "",
email: 0,
} }
}, },
methods: { methods: {
@ -111,6 +112,8 @@ let app = createApp({
this.disableSMSSend = false this.disableSMSSend = false
if (resp.status === 200) { if (resp.status === 200) {
this.messageToSend = "" this.messageToSend = ""
this.getThreads()
this.getThreadMessages
} }
else{ else{
resp.text().then(text => { resp.text().then(text => {
@ -125,6 +128,72 @@ let app = createApp({
}) })
return false return false
}, },
async isUsingEmail(){
fetch(this.backend + this.userID + '/usingemail').then(response => {
if (response.ok) {
return response.text()
} else {
throw new Error('Network response was not ok.')
}
}).then(email => {
if (email === "1"){
this.email = 1
}
else{
this.email = 0
}
})
},
setEmail(){
if (! this.onLine){
alert("You are offline, cannot set email")
return
}
let email = prompt("Enter your email address to receive updates about MoneroSMS.\nLeave blank or cancel to disable email relaying.")
if (! this.onLine){
alert("You are offline, cannot set email")
return
}
if (email === null){
email = "none"
}
else{
email = email.trim()
if (email === ""){
email = "none"
}
else{
if (! RegExp('@').test(email)){
alert("Invalid email address")
return
}
}
}
fetch(this.backend + this.userID + '/setemail/' + email, {
method: 'POST'
}).then(resp => {
if (resp.status === 200) {
if (email === "none"){
this.email = 0
alert("Email disabled. You will see new messages in the UI")
}
else{
this.email = 1
alert("Email set to " + email + ". You will not see new messages in this UI.")
}
}
else{
resp.text().then(text => {
alert(text)
console.debug(text)
})
}
}).catch(err => {
alert(err.toString())
console.log(err)
})
},
getThreads(doInterval){ getThreads(doInterval){
let updateThreads = async (data) => { let updateThreads = async (data) => {
if (! this.userID || document.hidden){ if (! this.userID || document.hidden){
@ -133,6 +202,10 @@ let app = createApp({
let response = await fetch(this.backend + this.userID + '/list') let response = await fetch(this.backend + this.userID + '/list')
if (response.ok){ if (response.ok){
let textResp = await response.text() let textResp = await response.text()
if (RegExp('No').test(textResp)){
this.threads.length = 0
return
}
if (! RegExp('You').test(textResp)){ if (! RegExp('You').test(textResp)){
// Only update threads that changed // Only update threads that changed
let newThreads = textResp.split('\n') let newThreads = textResp.split('\n')
@ -189,6 +262,7 @@ let app = createApp({
console.log("Number bought") console.log("Number bought")
this.ownedNumber = numToBuy this.ownedNumber = numToBuy
this.numberPurchaseMessage = "Successfully purchased number" this.numberPurchaseMessage = "Successfully purchased number"
this.getCredits()
} else { } else {
if (res.status === 402){ if (res.status === 402){
console.debug("Not enough credits") console.debug("Not enough credits")
@ -201,6 +275,23 @@ let app = createApp({
}) })
}, },
async userLogin() { async userLogin() {
if (! this.onLine){
alert("You are offline, cannot login")
return
}
if (this.userID.length > 100){
alert("User ID too long")
return
}
if (this.userID.length < 8){
alert("User ID too short")
return
}
if (RegExp(' ').test(this.userID)){
alert("User ID cannot contain spaces")
return
}
this.isUsingEmail()
this.getXMRAddress() this.getXMRAddress()
this.getThreads(false) this.getThreads(false)
this.getCredits() this.getCredits()
@ -224,7 +315,7 @@ let app = createApp({
} }
return null; return null;
}, },
getCredits(){ async getCredits(){
if (! this.userID || document.hidden){return} if (! this.userID || document.hidden){return}
this.getText(this.userID + '/creditbal').then((data) => { this.getText(this.userID + '/creditbal').then((data) => {
this.credits = data this.credits = data