diff --git a/frontend/components/NewMessage.vue b/frontend/components/NewMessage.vue index ccdbb2b..6cc3398 100644 --- a/frontend/components/NewMessage.vue +++ b/frontend/components/NewMessage.vue @@ -19,7 +19,7 @@ export default {
diff --git a/frontend/components/SendBox/SendBox.vue b/frontend/components/SendBox/SendBox.vue index 9cf8b4c..d35e8a9 100644 --- a/frontend/components/SendBox/SendBox.vue +++ b/frontend/components/SendBox/SendBox.vue @@ -57,6 +57,10 @@ export default { type: String, required: true, }, + location:{ + type: String, + required: true + } }, methods: { keypress(e: KeyboardEvent) { @@ -82,95 +86,154 @@ export default { }, async send() { //we need to fail phone numbers that are not 11 digits long - - if((this.remoteNumber && phoneNumbertoPhoneString(this.remoteNumber).length===11) || this.groupUUID) - { - console.log(this.enteredText); - if (this.enteredText.length == 0 && this.pendingAttachments.length == 0) { - this.$refs.textbox.focus(); - return; - } - - while (this.pendingAttachments.length > 0) { - const attachment = this.pendingAttachments.shift(); - await attachment.upload; + if(this.location === 'Conversation'){ + + if((this.remoteNumber && phoneNumbertoPhoneString(this.remoteNumber).length===11) || this.groupUUID) + { + console.log(this.enteredText); + if (this.enteredText.length == 0 && this.pendingAttachments.length == 0) { + this.$refs.textbox.focus(); + return; + } - console.log("sending attachment:", attachment); + while (this.pendingAttachments.length > 0) { + const attachment = this.pendingAttachments.shift(); + await attachment.upload; - const cpim = new CPIM(attachment.uploadedURL, attachment.file.type); - if (this.groupUUID) { - cpim.headers["Group-UUID"] = this.groupUUID; - } - cpim.previewURL = attachment.previewURL; + console.log("sending attachment:", attachment); - let message = this.getMessageData(); - message.cpim = cpim; - console.log('emitting message', message); - emitter.emit('outbound-message', message); - } - - if (this.enteredText.length > 0) { - let message = this.getMessageData(); - if (this.groupUUID) { - const url = await uploadText(this.enteredText); - const cpim = new CPIM(url, 'text/plain'); - cpim.bodyText = this.enteredText; + const cpim = new CPIM(attachment.uploadedURL, attachment.file.type); + if (this.groupUUID) { + cpim.headers["Group-UUID"] = this.groupUUID; + } + cpim.previewURL = attachment.previewURL; - if (this.groupUUID) { - cpim.headers["Group-UUID"] = this.groupUUID; + let message = this.getMessageData(); + message.cpim = cpim; + console.log('emitting message', message); + emitter.emit('outbound-message', message); } - console.log('outgoing cpim', cpim); + if (this.enteredText.length > 0) { + let message = this.getMessageData(); + if (this.groupUUID) { + const url = await uploadText(this.enteredText); + const cpim = new CPIM(url, 'text/plain'); + cpim.bodyText = this.enteredText; + + if (this.groupUUID) { + cpim.headers["Group-UUID"] = this.groupUUID; + } + + console.log('outgoing cpim', cpim); + + message.contentType = "message/cpim"; + message.cpim = cpim; + message.body = cpim.serialize(); + } else { + message.contentType = "text/plain"; + message.body = this.enteredText; + } + console.log('emitting message', message); + emitter.emit('outbound-message', message); - message.contentType = "message/cpim"; - message.cpim = cpim; - message.body = cpim.serialize(); - } else { - message.contentType = "text/plain"; - message.body = this.enteredText; + this.enteredText = ""; + } } - console.log('emitting message', message); - emitter.emit('outbound-message', message); - - this.enteredText = ""; - } - } - else{ - let errorString = "Outbound number is invalid, not enough digits or invalid groupUUID. \n"; - if(this.remoteNumber.toString().length!=11){ - errorString += `Outbound Number: ${this.remoteNumber}`; + else{ + let errorString = "Outbound number is invalid, not enough digits or invalid groupUUID. \n"; + if(this.remoteNumber.toString().length!=11){ + errorString += `Outbound Number: ${this.remoteNumber}`; + } + else{ + errorString+=`GroupUUID: ${this.groupUUID}`; + } + + alert(errorString) + } } else{ - errorString+=`GroupUUID: ${this.groupUUID}`; + this.sendNewMessage(); } - - alert(errorString) - } + }, + async sendNewMessage(){ + if((this.remoteNumber && phoneNumbertoPhoneString(this.remoteNumber).length===11) || this.groupUUID) + { + console.log(this.enteredText); + if (this.enteredText.length == 0 && this.pendingAttachments.length == 0) { + this.$refs.textbox.focus(); + return; + } + for( let attachment of this.pendingAttachments){ + this.removeAttachment(attachment); + } + this.pendingAttachments= []; + + if (this.enteredText.length > 0) { + let message = this.getMessageData(); + if (this.groupUUID) { + const url = await uploadText(this.enteredText); + const cpim = new CPIM(url, 'text/plain'); + cpim.bodyText = this.enteredText; + + if (this.groupUUID) { + cpim.headers["Group-UUID"] = this.groupUUID; + } + + console.log('outgoing cpim', cpim); + + message.contentType = "message/cpim"; + message.cpim = cpim; + message.body = cpim.serialize(); + } else { + message.contentType = "text/plain"; + message.body = this.enteredText; + } + console.log('emitting message', message); + emitter.emit('outbound-message', message); + setTimeout(() => + location.reload(), 500 + ) + this.enteredText = ""; + } + } + else{ + let errorString = "Outbound number is invalid, not enough digits or invalid groupUUID. \n"; + if(this.remoteNumber.toString().length!=11){ + errorString += `Outbound Number: ${this.remoteNumber}`; + } + else{ + errorString+=`GroupUUID: ${this.groupUUID}`; + } + + alert(errorString) + } }, onAttach(e: Event) { - //console.log(e.target.files); - - const target = e.target as HTMLInputElement; - //console.log(target); - for (const file of target.files) { - if (verifyFileSize(file)) { - const a: PendingAttachment = { - file: file, - previewURL: URL.createObjectURL(file), - progress: 0, - upload: null, - uploadedURL: null, - }; - a.upload = this.uploadAttachment(a); - this.pendingAttachments.push(a); - } - else { - alert(`The selected file is too large. We cannot send files bigger than ${MAXFILESIZE / 1000}kB.`); + if(this.verifyValidLocation()){ + const target = e.target as HTMLInputElement; + //console.log(target); + for (const file of target.files) { + if (verifyFileSize(file)) { + const a: PendingAttachment = { + file: file, + previewURL: URL.createObjectURL(file), + progress: 0, + upload: null, + uploadedURL: null, + }; + a.upload = this.uploadAttachment(a); + this.pendingAttachments.push(a); + } + else { + alert(`The selected file is too large. We cannot send files bigger than ${MAXFILESIZE / 1000}kB.`); + } } } - - + else{ + //alert('Attachments not supported for new conversations at this time.') + } }, removeAttachment(attachment: PendingAttachment) { let position = this.pendingAttachments.indexOf(attachment); @@ -178,22 +241,57 @@ export default { this.pendingAttachments.splice(position, 1); }, async uploadAttachment(attachment: PendingAttachment): Promise