Skip to content

Commit d673039

Browse files
author
Ian
committed
added a manual interval timer to check for new messages. removed sip connection.
1 parent 2158182 commit d673039

16 files changed

Lines changed: 1641 additions & 1325 deletions

frontend/components/SendBox/SendBox.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default {
120120
=>
121121
*/
122122
async send() {
123+
console.log("[Sendbox.send] Send button hit. Validating and sending message...");
123124
//we need to fail phone numbers that are not 11 digits long
124125
if (this.location === "Conversation") {
125126
const phoneString = this.remoteNumber;
@@ -130,7 +131,7 @@ export default {
130131
phoneString.length === 6)) ||
131132
this.groupUUID
132133
) {
133-
//console.log(this.enteredText);
134+
console.log(this.enteredText);
134135
if (
135136
this.enteredText.length == 0 &&
136137
this.pendingAttachments.length == 0
@@ -158,7 +159,7 @@ export default {
158159
159160
if (this.enteredText.length > 0) {
160161
let message = this.getMessageData();
161-
//console.log(message);
162+
console.log("the message is ", message);
162163
if (this.groupUUID) {
163164
const url = await uploadText(this.enteredText);
164165
const cpim = new CPIM(url, "text/plain");
@@ -491,7 +492,7 @@ export default {
491492
class="btn btn-send"
492493
:disabled="
493494
(pendingAttachments.length == 0 && enteredText.length == 0) ||
494-
!state.connected
495+
state.connected
495496
"
496497
v-on:click="send"
497498
>

frontend/components/WebTextingContainer/WebTextingContainer.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import Conversation from '../conversation/Conversation.vue';
33
import ThreadList from '../ThreadList/ThreadList.vue';
44
import moment from 'moment';
55
import NewMessage from '../NewMessage.vue';
6-
import { RouterView } from 'vue-router';
6+
import { backfillFromTimestamp } from '../../lib/backfillFromTimestamp';
77
import { saveTemplate, saveTemplateQuery, } from '../../lib/saveTemplates';
88
import { useMatchMedia } from '../../lib/matchMedia';
9-
import { emitter, MessageData, ThreadChangePayload, state, ThreadPreviewData, updateMessageStatus, MessageSuccessPayload } from '../../lib/global';
9+
import { emitter, MessageData, ThreadChangePayload, state, ThreadPreviewData, updateMessageStatus, MessageSuccessPayload, updateCurrentSessionStartTime } from '../../lib/global';
1010
import { searchPreviews, loadPreviews } from '../../lib/backfillPreviews';
1111
import { loadTemplates, loadTemplateQuery } from '../../lib/loadTemplates';
1212
import { deleteTemplateQuery, deleteTemplate } from '../../lib/deleteTemplate';
@@ -262,6 +262,16 @@ export default {
262262
//console.log(payload);
263263
updateMessageStatus(payload.key, payload.id, true);
264264
})
265+
266+
emitter.on("last-checked-timestamp", (timestamp: string) => {
267+
updateCurrentSessionStartTime(timestamp);
268+
})
269+
270+
emitter.on('backfill-poll-complete', () => {
271+
//state.currentSessionStartTime = new Date(Date.now()).toISOString();
272+
});
273+
setInterval(() => backfillFromTimestamp(this.extensionUUID, state.currentSessionStartTime, undefined, undefined), 10000)
274+
265275
},
266276
}
267277
</script>

frontend/components/conversation/Conversation.vue

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -186,31 +186,30 @@ export default {
186186
//console.log("conversation fully backfilled, refusing to attempt to backfill more");
187187
return;
188188
} else if (this.topVisible && this.bottomVisible) {
189-
//console.log("top and bottom of conversation visible, attempting to backfill immediately");
189+
console.log("top and bottom of conversation visible, attempting to backfill immediately");
190190
emitter.emit("backfill-requested", this.conversationKey);
191191
return;
192192
}
193-
194-
//console.log('will backfill if top is still visible in 1 second');
195193
setTimeout(() => {
196194
if (this.topVisible) {
197-
//console.log("top still visible backfill");
195+
console.log("top still visible backfill");
198196
emitter.emit("backfill-requested", this.conversationKey);
199197
}
200198
}, 5000);
201199
});
202200
203201
emitter.on("conversation-fully-backfilled", () => {
204-
//console.log("preventing future backfilling attempts, this conversation has been fully backfilled");
205202
this.backfillAvailable = false;
206203
});
207204
emitter.on("new-message-ingested", () =>{
208-
//this.backfillAvailable = true;
205+
console.log("new message ingested, attempting to backfill conversation ", this.conversationKey);
206+
emitter.emit("backfill-requested", this.conversationKey);
207+
this.backfillAvailable = true;
209208
});
210209
emitter.on("document-unhidden", () => {
211-
//console.log("document unhidden, attempting to backfill conversation");
212-
//this.backfillAvailable = true;
213-
//emitter.emit("backfill-requested", this.conversationKey);
210+
console.log("document unhidden, attempting to backfill conversation ", this.conversationKey);
211+
this.backfillAvailable = true;
212+
emitter.emit("backfill-requested", this.conversationKey);
214213
});
215214
216215
emitter.on("thread-changed", (newDisplayName: String) => {
@@ -233,19 +232,15 @@ export default {
233232
}
234233
});
235234
refreshElement.addEventListener("touchend", (touchend:TouchEvent) => {
236-
//console.log("touch end");
237235
let pullToRefresh = document.querySelector(".pull-to-refresh");
238236
239237
if (pullToRefresh && pullToRefresh.classList.contains("visible")) {
240238
pullToRefresh.classList.remove("visible");
241239
location.reload();
242240
}
243241
});
244-
//console.log(this.state.messages);
245-
//console.log("Conversation.vue mounted with props:\nremoteNumber:", this.remoteNumber, "\ngroupUUID:", this.groupUUID, "\ndisplayName:", this.displayName, "\nownNumber:", this.ownNumber);
246242
},
247243
beforeUpdate() {
248-
//console.log("changing active component");
249244
if (this.$route.query.group) {
250245
const groupTag:any = document.getElementsByName("group");
251246
groupTag[0].value = this.$route.query.group;
@@ -255,35 +250,30 @@ export default {
255250
remoteNumber: async function (rN) {
256251
this.messages = [];
257252
this.backfillAvailable = true;
258-
//console.log("remote number changed changing this.messages")
259-
if (this.remoteNumber) {
253+
if (this.$route.query.number || this.remoteNumber) {
260254
if (this.state.conversations[rN]) {
261255
//conversation found
262-
//console.log("conversation found skipping fetch")
263256
this.messages = this.state.conversations[rN];
264257
} else {
265258
this.messages = this.state.conversations[rN];
266259
}
267260
this.conversationKey = rN;
268261
emitter.emit("backfill-requested", rN);
269-
//console.log("changed Rn " + rN);
270262
}
271263
},
272264
groupUUID: function (gUUID) {
273265
this.messages = [];
274266
if (this.$route.query.group) {
275-
//console.log(observedChangeQueryParams)
276267
this.messages = this.state.conversations[this.$route.query.group];
277-
//this.title = this.$route.query.group;
268+
this.conversationKey = this.$route.query.group;
269+
this.backfillAvailable = true;
270+
emitter.emit("backfill-requested", this.$route.query.group);
278271
}
279-
this.conversationKey = this.$route.query.group;
280-
this.backfillAvailable = true;
281-
emitter.emit("backfill-requested", this.$route.query.group);
272+
282273
},
283274
},
284275
methods: {
285276
scrollToBottom() {
286-
//console.log('scrolling conversation to bottom');
287277
const messageContainer = this.$refs.message_container;
288278
messageContainer.scrollTo(0, messageContainer.scrollHeight);
289279
},
@@ -294,31 +284,25 @@ export default {
294284
this.bottomVisible = e.isIntersecting;
295285
if (e.isIntersecting) {
296286
this.atBottom = true;
297-
//console.log(this.atBottom ? "enabling" : "disabling", "scrolling to bottom for new messages");
298287
}
299-
//console.log("bottom is", e.isIntersecting ? "visible" : "hidden");
300288
break;
301289
case this.$refs.top:
302290
this.topVisible = e.isIntersecting;
303291
if (e.isIntersecting && this.backfillAvailable) {
304-
//console.log("isIntersecting and backfillavailable");
292+
console.log("onObserve", this.conversationKey);
305293
emitter.emit("backfill-requested", this.conversationKey);
306294
}
307-
//console.log("top is", e.isIntersecting ? "visible" : "hidden");
308295
break;
309296
default:
310-
//console.log("observed event on unknown target:", e);
311297
}
312298
});
313299
},
314300
onScroll() {
315301
if (this.atBottom != this.bottomVisible) {
316302
this.atBottom = this.bottomVisible;
317-
//console.log(this.atBottom ? "enabling" : "disabling", "scrolling to bottom for new messages");
318303
}
319304
},
320305
toBottom() {
321-
//console.log("new message added to bottom. scrolling?", this.atBottom);
322306
if (this.atBottom) {
323307
const messageContainer = this.$refs.message_container;
324308
if (messageContainer) {

frontend/lib/SIP.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { UserAgentOptions, UserAgent, Registerer, Invitation, Notification, Message, Messager, URI, RegistererState, TransportState, MessagerOptions, MessagerMessageOptions, } from 'sip.js';
1+
import { UserAgentOptions, UserAgent, Registerer, Invitation, Notification, Message, Messager, URI, RegistererState, TransportState, MessagerOptions, MessagerMessageOptions, } from 'sip.js';
22
import { CPIM } from './CPIM';
33
import { sendMessage } from './sendMessage';
4-
import { state, emitter, MessageData, addMessage } from './global';
4+
import { state, emitter, MessageData, addMessage } from './global';
55
import moment from 'moment';
66
import { compileScript } from 'vue/compiler-sfc';
77
import { AlertData } from '@/components/Alerts/Alert.vue';
@@ -14,7 +14,7 @@ const registrationIntervalSeconds = 270;
1414
let backoff = 0;
1515
//stolen from https://www.geeksforgeeks.org/javascript/generate-random-alpha-numeric-string-in-javascript/
1616
function randomBytes() {
17-
return Math.random().toString(36).slice(2);
17+
return Math.random().toString(36).slice(2);
1818
}
1919

2020

@@ -30,18 +30,18 @@ function calculatePlainThreadID(message: Message, direction: string, originalTo:
3030
return 'do not add';
3131
}
3232

33-
function calculateCPIMThreadID(cpim: CPIM, direction: string, originalTo: string, messageFromUser: string) {
34-
if (cpim.headers["Group-UUID"] ) {
33+
export function calculateCPIMThreadID(cpim: CPIM, direction: string, originalTo: string, messageFromUser: string) {
34+
if (cpim.headers["Group-UUID"]) {
3535
return cpim.headers["Group-UUID"];
3636
}
37-
else if (cpim.headers["group-uuid"] ) {
37+
else if (cpim.headers["group-uuid"]) {
3838
return cpim.headers["group-uuid"];
3939
}
40-
else if ((direction =='incoming')) {
40+
else if ((direction == 'incoming')) {
4141
//not group message and inbound so key is whoever sent message
4242
return messageFromUser;
4343
}
44-
else if (direction =='outgoing') {
44+
else if (direction == 'outgoing') {
4545
//not group and outbound so key is whoever we send message to
4646
return originalTo;
4747
}
@@ -67,7 +67,7 @@ function reconnect(userAgent: UserAgent) {
6767
}
6868
}
6969

70-
function RunSIPConnection(username: string, password: string, server: string, ownNumber: string, extension_uuid:string, remote_number?: string, group?: string,) {
70+
function RunSIPConnection(username: string, password: string, server: string, ownNumber: string, extension_uuid: string, remote_number?: string, group?: string,) {
7171
const uaOpts: UserAgentOptions = {
7272
logBuiltinEnabled: false,
7373
logConfiguration: false,
@@ -85,7 +85,7 @@ function RunSIPConnection(username: string, password: string, server: string, ow
8585
onDisconnect: (err?: Error) => {
8686
state.connectivityStatus = "disconnected";
8787
if (err) {
88-
//console.log("[SIP.RunSIPConnection] connectivity error:", err)
88+
console.log("[SIP.RunSIPConnection] connectivity error:", err)
8989
}
9090
},
9191
onMessage: async (message: Message) => {
@@ -95,11 +95,11 @@ function RunSIPConnection(username: string, password: string, server: string, ow
9595
direction = 'outgoing';
9696
}
9797
const messageFromUser = message.request.from.uri.user;
98-
//console.log(message.request.getHeader("Content-Type"));
98+
console.log(message.request.getHeader("Content-Type"));
9999
switch (message.request.getHeader("Content-Type")) {
100100
case "text/plain":
101101
console.log("onMessage")
102-
console.log(message)
102+
console.log(message)
103103
const plainThreadID = calculatePlainThreadID(message, direction, originalTo, messageFromUser);
104104
addMessage(plainThreadID, {
105105
direction: direction,
@@ -133,17 +133,15 @@ function RunSIPConnection(username: string, password: string, server: string, ow
133133
break;
134134

135135
default:
136-
//console.log("[SIP.RunSIPConnection] dropping message with unknown content type ", message.request.getHeader("Content-Type"))
136+
//console.log("[SIP.RunSIPConnection] dropping message with unknown content type ", message.request.getHeader("Content-Type"))
137137
}
138138
}
139139
}
140140
};
141-
//console.log("initializing user agent with options:", uaOpts);
142141
const userAgent = new UserAgent(uaOpts);
143-
144142
userAgent.transport.onDisconnect = (err?: Error) => {
145143
if (err) {
146-
//console.log("connectivity error:", err)
144+
console.log("connectivity error:", err)
147145
}
148146
}
149147

@@ -164,6 +162,7 @@ function RunSIPConnection(username: string, password: string, server: string, ow
164162
break;
165163
case RegistererState.Unregistered:
166164
let registerRequest = await registerer.register();
165+
console.log("re-register response", registerRequest);
167166
break;
168167
}
169168
});
@@ -203,11 +202,11 @@ function RunSIPConnection(username: string, password: string, server: string, ow
203202
window.addEventListener("beforeunload", (e: BeforeUnloadEvent) => {
204203
registerer.unregister();
205204
});
206-
205+
console.log("[SIP.RunSIPConnection] Starting user agent...", userAgent);
207206
userAgent.start();
208207

209208
emitter.on("outbound-message", async (message: MessageData) => {
210-
//console.log("[SIP.outbound-message] Outbound message:", message);
209+
console.log("[SIP.outbound-message] Outbound message:", message);
211210
//message.timestamp = moment();
212211
const m = message;
213212
// if plain/text use to number as key
@@ -223,34 +222,34 @@ function RunSIPConnection(username: string, password: string, server: string, ow
223222
sendMessageQuery.extensionUUID = extension_uuid;
224223
let sendMessageResponse = await sendMessage(sendMessageQuery);
225224
console.log(sendMessageResponse);
226-
if(sendMessageResponse && sendMessageResponse.statusCode && sendMessageResponse.statusCode == 200){
225+
if (sendMessageResponse && sendMessageResponse.statusCode && sendMessageResponse.statusCode == 200) {
227226
sendMessageQuery.id = sendMessageResponse.id;
228227
sendMessageQuery.key = sendMessageResponse.key;
229228
sendMessageQuery.delivered = true;
230229
sendMessageResponse.delivered = true;
231-
//add message to state
230+
//add message to state
232231
//probably just add the status codes here lmao
233-
if(message.cpim && (message.cpim.headers['Group-UUID'] || message.cpim.headers['group-uuid'])){
232+
if (message.cpim && (message.cpim.headers['Group-UUID'] || message.cpim.headers['group-uuid'])) {
234233
const cpimThreadID = calculateCPIMThreadID(message.cpim, message.direction, message.to, message.from);
235234
addMessage(cpimThreadID, sendMessageQuery);
236235
}
237-
else{
236+
else {
238237
addMessage(message.to, sendMessageQuery);
239238
}
240239
emitter.emit('message-success', sendMessageQuery);
241240
}
242-
else{
241+
else {
243242
//console.log('message failed to send');
244-
if(message.cpim && (message.cpim.headers['Group-UUID'] || message.cpim.headers['group-uuid'])){
243+
if (message.cpim && (message.cpim.headers['Group-UUID'] || message.cpim.headers['group-uuid'])) {
245244
const cpimThreadID = calculateCPIMThreadID(message.cpim, message.direction, message.to, message.from);
246245
addMessage(cpimThreadID, sendMessageQuery);
247246
}
248-
else{
247+
else {
249248
addMessage(message.to, sendMessageQuery);
250249
}
251250
emitter.emit('message-failed', sendMessageQuery);
252251
}
253-
252+
254253
});
255254
}
256255

frontend/lib/backfill.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export async function backfillMessages(extensionUUID: string, remoteNumber?: str
122122

123123
export function insertMessageInHistory(key: string, message: MessageData) {
124124
//check for message in history
125+
//console.log("message", message);
125126
if (state.conversations[key]) {
126127
for (let i = 0; i < state.conversations[key].length; i++) {
127128
if (state.conversations[key][i].id == message.id) {

0 commit comments

Comments
 (0)