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 {
- +
New Conversation
@@ -29,7 +29,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 { - const uploadTarget = await fetch("upload.php", { + if(this.verifyValidLocation()){ + const uploadTarget = await fetch("upload.php", { method: "POST", body: JSON.stringify({ filename: attachment.file.name }) - }).then(r => r.json()); + }).then(r => r.json()); + + attachment.uploadedURL = uploadTarget.download_url; + + console.log("uploading ", uploadTarget); + const resp = await fetch(uploadTarget.upload_url, { + method: "PUT", + body: await attachment.file.arrayBuffer(), + }); - attachment.uploadedURL = uploadTarget.download_url; + attachment.progress = 100; - console.log("uploading ", uploadTarget); - const resp = await fetch(uploadTarget.upload_url, { - method: "PUT", - body: await attachment.file.arrayBuffer(), - }); + console.log("uploaded: ", resp); + }else{ + //alert('Attachments not supported for new conversations at this time.') + } + + }, + verifyValidLocation(){ + if(this.location ==='Conversation'){ + return true; + } + else if(this.location ==='New-Message'){ + //alert('Attachments not supported for new conversations at this time.'); + } + else{ + alert('Invalid SendBox location.') + } + return false; + }, + attachPendingAttachment(file: File) { + 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); - attachment.progress = 100; + } + else { + alert(`The selected file is too large. We cannot send files bigger than ${MAXFILESIZE / 1000}kB.`); - console.log("uploaded: ", resp); + } }, onPaste(e: ClipboardEvent) { var items = (e.clipboardData || e.originalEvent.clipboardData).items; @@ -201,59 +299,33 @@ export default { for (const item of items) { switch (item.type) { case "image/png": - const filePng = item.getAsFile(); - if (verifyFileSize(filePng)) { - const aPng: PendingAttachment = { - file: filePng, - previewURL: URL.createObjectURL(filePng), - progress: 0, - upload: null, - uploadedURL: null, - }; - aPng.upload = this.uploadAttachment(aPng); - this.pendingAttachments.push(aPng); + if(this.verifyValidLocation()){ + const file = item.getAsFile(); + this.attachPendingAttachment(file); break; } - 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.'); break; } + case "image/jpg": - const file = item.getAsFile(); - 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); + if(this.verifyValidLocation()){ + const file = item.getAsFile(); + this.attachPendingAttachment(file); break; - } - 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.'); break; } case "image/jpeg": - const fileJpeg = item.getAsFile(); - if (verifyFileSize(fileJpeg)) { - console.log(fileJpeg); - const aJpeg: PendingAttachment = { - file: file, - previewURL: URL.createObjectURL(file), - progress: 0, - upload: null, - uploadedURL: null, - }; - aJpeg.upload = this.uploadAttachment(a); - this.pendingAttachments.push(a); + if(this.verifyValidLocation()){ + const file = item.getAsFile(); + this.attachPendingAttachment(file); break; - } - 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.'); break; } case "text/plain": @@ -279,8 +351,10 @@ export default {
- - + + @@ -357,7 +431,7 @@ export default { .attachment-preview { display: flex; justify-content: left; - background-color: #eee; + background-color: #aaa; } .attachment-preview-wrapper { diff --git a/frontend/components/conversation/Conversation.vue b/frontend/components/conversation/Conversation.vue index 045d1de..faffbb8 100644 --- a/frontend/components/conversation/Conversation.vue +++ b/frontend/components/conversation/Conversation.vue @@ -316,7 +316,7 @@ export default { v-for="(message, index) in this.state.conversations[conversationKey]" />
 
- +
{{ state.connectivityStatus }} - Sending as {{ ownNumber }}
diff --git a/frontend/lib/SIP.ts b/frontend/lib/SIP.ts index f726ed7..a654568 100644 --- a/frontend/lib/SIP.ts +++ b/frontend/lib/SIP.ts @@ -96,6 +96,7 @@ function RunSIPConnection(username: string, password: string, server: string, ow onMessage: async (message: Message) => { //console.log("[MESSAGE]", message); //console.log(`own number: ${ownNumber}`) + //I believe this is where we need to target to add auto updatign threadlist let direction = 'incoming'; let originalTo = message.request.getHeader("X-Original-To"); diff --git a/webtexting-worker.js b/webtexting-worker.js index 79c25ba..9595618 100644 --- a/webtexting-worker.js +++ b/webtexting-worker.js @@ -18,13 +18,11 @@ self.addEventListener('push', function (event) { const payload = event.data.json(); channel.postMessage(payload); - console.log(payload); + var tab = clientList.some(function (client) { let u = new URL(client.url); - console.log(u) return u.searchParams.get('extension_uuid') == payload.to && u.searchParams.get('number') == payload.from; }); - console.log(tab) if(tab) { console.log("tab with conversation exists"); @@ -33,7 +31,6 @@ self.addEventListener('push', function (event) { return; } } - return self.registration.showNotification(payload.display_name, {body: payload.body}); }) ); @@ -58,4 +55,4 @@ self.addEventListener('notificationclick', function (event) { } }) ); -}); +}); \ No newline at end of file