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 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">
<label>
Phone Number:
@ -69,9 +73,12 @@
<div v-if="threads.length">
<br>
<span v-for="person in threads">
<div v-if="person">
<button @click="openThread(person)">{{ formatPhone(person) }} - Open Thread</button>
<button @click="deleteThread(person)" class="danger">Delete Thread</button>
<br><br>
</div>
</span>
<div v-if="showingThreadNum">
<div v-for="message in threadMessages">

97
main.js
View File

@ -18,7 +18,7 @@ let app = createApp({
userIDInput: '',
userID: "",
showUserID: "",
backend: 'https://api.sms.voidnet.tech/',
backend: 'http://staging.chaoswebs.net/',
availableNumbers: "",
credits: "",
threads: [],
@ -35,7 +35,8 @@ let app = createApp({
threadMessages: [],
lastThreadLineHeader: 0,
threadLineHeader: 0,
pricingInfo: ""
pricingInfo: "",
email: 0,
}
},
methods: {
@ -111,6 +112,8 @@ let app = createApp({
this.disableSMSSend = false
if (resp.status === 200) {
this.messageToSend = ""
this.getThreads()
this.getThreadMessages
}
else{
resp.text().then(text => {
@ -125,6 +128,72 @@ let app = createApp({
})
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){
let updateThreads = async (data) => {
if (! this.userID || document.hidden){
@ -133,6 +202,10 @@ let app = createApp({
let response = await fetch(this.backend + this.userID + '/list')
if (response.ok){
let textResp = await response.text()
if (RegExp('No').test(textResp)){
this.threads.length = 0
return
}
if (! RegExp('You').test(textResp)){
// Only update threads that changed
let newThreads = textResp.split('\n')
@ -189,6 +262,7 @@ let app = createApp({
console.log("Number bought")
this.ownedNumber = numToBuy
this.numberPurchaseMessage = "Successfully purchased number"
this.getCredits()
} else {
if (res.status === 402){
console.debug("Not enough credits")
@ -201,6 +275,23 @@ let app = createApp({
})
},
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.getThreads(false)
this.getCredits()
@ -224,7 +315,7 @@ let app = createApp({
}
return null;
},
getCredits(){
async getCredits(){
if (! this.userID || document.hidden){return}
this.getText(this.userID + '/creditbal').then((data) => {
this.credits = data