removed unused methods

This commit is contained in:
joschuatonn
2024-06-20 07:29:25 +02:00
parent 85b6da4387
commit 6b558e6d48

View File

@@ -1,7 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { message, ptpUser, responseModel } from 'src/models'; import { message } from 'src/models';
import Keycloak, { KeycloakInitOptions, KeycloakLoginOptions } from 'keycloak-js';
import { useNotificationStore } from './notification-store'; import { useNotificationStore } from './notification-store';
import { useUserStore } from './user-store'; import { useUserStore } from './user-store';
@@ -22,33 +21,21 @@ export const useMessageStore = defineStore('messageStore', {
async createChatAndSendFirstMessage(receiverId : string, senderId : string, content : string) { async createChatAndSendFirstMessage(receiverId : string, senderId : string, content : string) {
const config = { headers: {'Content-Type': 'application/json'} }; const config = { headers: {'Content-Type': 'application/json'} };
return (await api.post("/messages/dm/"+senderId+"/"+receiverId, content, config).then((response) => { return (await api.post("/messages/dm/"+senderId+"/"+receiverId, content, config).then((response) => {
console.info("LET ME IN");
console.info(response.data);
console.info(response.data.id);
this.loadMessagesByChatID(response.data.id); this.loadMessagesByChatID(response.data.id);
return response.data.id; return response.data.id;
})); }));
}, },
loadMessagesByChatID(chatID : number) { loadMessagesByChatID(chatID : number) {
const notificationStore = useNotificationStore(); const notificationStore = useNotificationStore();
const userStore = useUserStore(); const userStore = useUserStore();
const messagesTemp : message[] = [];
const initialLoad = !this.loadedMessagesForChats.includes(chatID); const initialLoad = !this.loadedMessagesForChats.includes(chatID);
this.getAllMessagesByChatID(chatID).then((responseBody) => { this.getAllMessagesByChatID(chatID).then((responseBody) => {
responseBody.response.forEach((message : message) => { responseBody.response.forEach((message : message) => {
message.content = message.content.substring(1, message.content.length-1); message.content = message.content.substring(1, message.content.length-1);
if (isUrl(message.content)) {
if (isTenorGifUrl(message.content)) {
message.gif = true;
} else {
message.link = true;
}
}
if(!this.loadedMessagesForChats.includes(chatID)){ if(!this.loadedMessagesForChats.includes(chatID)){
this.messages[chatID] = []; this.messages[chatID] = [];
@@ -61,35 +48,17 @@ export const useMessageStore = defineStore('messageStore', {
} }
this.messages[chatID].unshift(message); this.messages[chatID].unshift(message);
}); });
}); });
}, },
async getAllMessagesByChatID(chatID : number) { async getAllMessagesByChatID(chatID : number) {
//const timestamp = !this.messages[chatID] ? 0 : this.messages[chatID][0].timestamp;
let timestamp = "0"; let timestamp = "0";
if(this.loadedMessagesForChats.includes(chatID)){ if(this.loadedMessagesForChats.includes(chatID)){
timestamp = this.messages[chatID][0].timestamp; timestamp = this.messages[chatID][0].timestamp;
} }
//console.log("Timestamp: "+timestamp);
return (await api.get("/messages/"+chatID+"/"+timestamp)).data; return (await api.get("/messages/"+chatID+"/"+timestamp)).data;
}, },
}, },
}); });
function isUrl(url : string) {
try {
new URL(url);
return true;
} catch (err) {
return false;
}
}
function isTenorGifUrl(url : string) {
return url.startsWith("https://media.tenor.com/") && url.endsWith(".gif");
}