Skip to content

Commit

Permalink
code cleanup / starting documentation progress / removing unused fun…
Browse files Browse the repository at this point in the history
…ctions / attributes
  • Loading branch information
Ian committed Jun 14, 2024
1 parent 70e13ab commit 0c7f5a8
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 79 deletions.
4 changes: 2 additions & 2 deletions frontend/components/PaginatorButton/PaginatorButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default{
},
methods:{
funnyClickFunction(){
paginatorClickFunction(){
const buttonData = document.getElementById('MORE-PREVIEWS');
console.log("Button data: ", buttonData);
emitter.emit("backfill-previews-requested");
Expand All @@ -32,7 +32,7 @@ export default{
<template>
<div class="paginator_container" >

<a id='MORE-PREVIEWS' class="paginator" role="button" v-if="this.morePreviewsAvailable" @click="funnyClickFunction" :data-oldest-message="oldestMessage">
<a id='MORE-PREVIEWS' class="paginator" role="button" v-if="this.morePreviewsAvailable" @click="paginatorClickFunction" :data-oldest-message="oldestMessage">
<span class="paginator-link">Load More</span>
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { RouterView } from 'vue-router';
import {useMatchMedia} from '../../lib/matchMedia';
import { emitter, MessageData, ThreadChangePayload,state} from '../../lib/global';
import {searchPreviews,loadPreviews} from '../../lib/backfillPreviews';
//TODO: changing threads and threadpreviews to Map<String,Object>
// this should change how ThreadList/ThreadPreview and Conversation components interact with the threads and threadPreviews props
//this component kind of functions as a partial state controller for the app
export default {
name: 'WebTextingContainer',
props: {
Expand Down
11 changes: 0 additions & 11 deletions frontend/lib/backfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ export async function backfillMessages(extensionUUID: string, remoteNumber?: str
console.log("skipping duplicate backfill request");
return;
}
if(group){
//console.log(`group = ${group}`);
}
if(remoteNumber){
//console.log(`group = ${remoteNumber}`);
}
fetching = true;
try {
let params: backfillQuery = { extension_uuid: extensionUUID };
Expand All @@ -48,16 +42,12 @@ export async function backfillMessages(extensionUUID: string, remoteNumber?: str
if (group) {
params.group = group;
}
//console.log(`backfilling conversations array, ${state.conversations}`)
//console.log(`backfill key: ${key}`)
//if state.conversations[key] exists we have already backfilled at least once
const stateMessages = state.conversations[key];
if(stateMessages){
if (stateMessages.length > 0 && stateMessages[0].id) {
params.older_than = stateMessages[0].id;
}
//console.log(stateMessages[0])
//console.log(stateMessages[stateMessages.length-1])
}
else{

Expand Down Expand Up @@ -137,5 +127,4 @@ export function insertMessageInHistory(key:string, message: MessageData) {
}
// no existing message matched, append to end
state.conversations[key].push(message);
//console.log("after:", state.conversations[key]);
}
70 changes: 15 additions & 55 deletions frontend/lib/backfillPreviews.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageData, emitter, state , addPreview, QUERY_LIMIT} from './global';
import { emitter , addPreview, QUERY_LIMIT} from './global';


type threadPreviewQuery = {
Expand All @@ -13,6 +13,10 @@ type loadPreviewQuery = {

let fetching = false;

//Grab the data we need to create the thread previews from the database
//INPUTS: extensionUUID = the user's extension we want to build previews for
// queryString = the user's string that they want to search their threads for
//OUTPUT: None (buildPreviews calls addPreviews which constructs the previews map for global state)
export async function searchPreviews(queryString: String, extensionUUID: String) {
emitter.emit("previews-loading");

Expand All @@ -29,15 +33,6 @@ export async function searchPreviews(queryString: String, extensionUUID: String)
const response = await fetch('/app/webtexting/searchpreviews.php?' + new URLSearchParams(params).toString()).then(r => r.json());

temp = response;
// for (let i = 0; i < response.length; i++) {
// let m = response[i];
// //console.log(m)
// //insertPreview();
// }


// fetching = false;
// //console.log('backfill request complete');

// if (response.length == 0) {
// emitter.emit('no-previews-found');
Expand All @@ -53,32 +48,12 @@ export async function searchPreviews(queryString: String, extensionUUID: String)
return buildPreviews( temp);
}
}
//what identifiers and data do we need
//maybe threadpreviewinterface
export function insertPreview() {
//check for Preview in previewList
if(state.conversations[key]){
for (let i = 0; i < state.conversations[key].length; i++) {
if (state.conversations[key][i].id == message.id) {
state.conversations[key][i] = message;
return;
}

if (state.conversations[key][i].timestamp.isAfter(message.timestamp)) {
state.conversations[key].splice(i, 0, message);
return;
}
}
}
//add a new preview if no preview is found
else{
state.conversations[key] = new Array<MessageData>();
}
// no existing message matched, append to end
state.conversations[key].push(message);
}


//Grab the data we need to create the thread previews from the database
//INPUTS: extensionUUID = string representation of the user's extension we want to build previews for
// (optional) older_than = string representation of a timestamp that we want to check if previews are older than (used for loading older previews)
//OUTPUT: None (buildPreviews calls addPreviews which constructs the previews map for global state)
export async function loadPreviews(extensionUUID:string, older_than:string) {
if (fetching) {
console.log("skipping duplicate search request");
Expand All @@ -94,16 +69,10 @@ export async function loadPreviews(extensionUUID:string, older_than:string) {
}
const initialResponse = await fetch('/app/webtexting/loadpreviews.php?' + new URLSearchParams(params).toString()).then(r => r.json());
temp = initialResponse;
//console.log("received", initialResponse.length, "preview from database");
// for (let i = 0; i < response.length; i++) {
// let m = response[i];
// //console.log(m)
// //insertPreview();
// }


fetching = false;
//console.log('backfill request complete');
//console.log('backfillPreviews request complete');

// if (initialResponse.length == 0) {
// emitter.emit('no-previews-found');
Expand All @@ -116,7 +85,6 @@ export async function loadPreviews(extensionUUID:string, older_than:string) {
if(temp.length< QUERY_LIMIT){
emitter.emit("no-more-previews");
}
//console.log(temp);
emitter.emit('backfill-preview-complete',temp);
fetching= false;
console.log(temp)
Expand All @@ -125,37 +93,29 @@ export async function loadPreviews(extensionUUID:string, older_than:string) {

}

//Calls addPreview for each object in a supplied rpeviews array
//INPUTS: previews = untyped array of objects that contain the data needed to construct a valid ThreadPreview component
//OUTPUTS: None (the threadPreviews state object is constructed/updated in addPreview )
export const buildPreviews = function buildPreviews(previews ) {
//console.log( previews)
//let threadPreviewMap = new Map<String, ThreadPreviewInterface>();
if(previews && previews.length){
for(let x = 0; x < previews.length; x++){
//console.log(opts[x])
if(previews[x].groupUUID){
// if(opts[x].groupMembers){
// //php delviers us a string of comma separated values instead of an array the rest of the app expects an array of strings
// console.log(opts[x].groupMembers);
// opts[x].groupMembers = opts[x].groupMembers.split(", ")
// console.log(opts[x].groupMembers);
// }
// console.log(previews[x]);
// threadPreviewMap.set(previews[x].groupUUID, previews[x])
addPreview(previews[x]);
}
else if(previews[x].remoteNumber){
// threadPreviewMap.set(previews[x].remoteNumber, previews[x])
// console.log(previews[x])
addPreview(previews[x]);
}
else{
console.log(("Contact has no identifier. Missing Group UUID and Phone Number"));
console.log(previews[x]);
}
}
}
console.log("emitting PDL");
emitter.emit("previews-done-loading");
//below not for deployment
emitter.emit('inital-load-complete');
//emitter.emit('inital-load-complete');

return ;
}
2 changes: 1 addition & 1 deletion frontend/lib/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type GlobalState = {
page: number,
oldestMessage: Number,
};
const QUERY_LIMIT = 20; //this limits the nubmer of threadpreview results per load request
const QUERY_LIMIT = 20; //this limits the number of threadpreview results per load request

const state = reactive<GlobalState>({
conversations: {},
Expand Down
3 changes: 3 additions & 0 deletions frontend/lib/updateLastSeen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
let updatingLastSeen = false;
//this function is called when a user selects a threadpreview and the conversation component is rendered
//when this function is called it updates the database so that we can keep track of messages recieved since the last time a user accessed that conversations
//this is how we keep track of persistent unreads
export async function updateLastSeen(updateULSObject:updateUserLastSeenOptions){
if(updatingLastSeen){
console.log("skipping duplicate userLastSeen update")
Expand Down
4 changes: 2 additions & 2 deletions frontend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export const initializeWebTextingContainer = function initializeWebTextingContai
app.mount("#TEST_DIV_FOR_TESTING_WEBTEXTING");

RunSIPConnection(opts.username, opts.password, opts.server, opts.ownNumber, opts.remoteNumber, opts.groupUUID);

// any event that needs absolute global scope should be listened for here
emitter.on('backfill-requested', (key:string) => {
console.log(`main.ts backfill key ${key}`)
//key is either a uuid or phone number. uuid length is at least 16
//key is either a uuid or phone number. uuid length is 16
if(key){
if(key.length<15){
console.log(`backfill using remotenumber: ${key}`)
Expand Down
1 change: 0 additions & 1 deletion frontend/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ export const router = createRouter({
}
]
})
export default {}
5 changes: 0 additions & 5 deletions last_seen.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
$parameters["domain_uuid"] = $domain_uuid;
$updated_last_seen = $database->execute($sql, $parameters);
if($updated_last_seen){
//succeeded
echo(json_encode(["Update Success",$updated_last_seen]));
}
else{
//failed
echo(json_encode(["Update Failed",$updated_last_seen]));
}
}
//else
// insert row
else{
$sql = "INSERT INTO webtexting_threads_last_seen (timestamp, extension_uuid, thread_uuid, domain_uuid) VALUES ( NOW(), :extension_uuid, :thread_uuid, :domain_uuid)";
Expand All @@ -52,11 +49,9 @@
$parameters["domain_uuid"] = $domain_uuid;
$insert_last_seen = $database->execute($sql, $parameters);
if($insert_last_seen){
//succeeded
echo(json_encode(["New User_Thread Creation Success",$insert_last_seen]));
}
else{
//failed
echo(json_encode(["New User_Thread Creation Failed",$insert_last_seen]));

}
Expand Down

0 comments on commit 0c7f5a8

Please sign in to comment.