removed unused methods
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { message, ptpUser, responseModel } from 'src/models';
|
||||
import Keycloak, { KeycloakInitOptions, KeycloakLoginOptions } from 'keycloak-js';
|
||||
import { message } from 'src/models';
|
||||
import { useNotificationStore } from './notification-store';
|
||||
import { useUserStore } from './user-store';
|
||||
|
||||
@@ -22,33 +21,21 @@ export const useMessageStore = defineStore('messageStore', {
|
||||
async createChatAndSendFirstMessage(receiverId : string, senderId : string, content : string) {
|
||||
const config = { headers: {'Content-Type': 'application/json'} };
|
||||
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);
|
||||
|
||||
return response.data.id;
|
||||
|
||||
}));
|
||||
},
|
||||
|
||||
loadMessagesByChatID(chatID : number) {
|
||||
const notificationStore = useNotificationStore();
|
||||
const userStore = useUserStore();
|
||||
const messagesTemp : message[] = [];
|
||||
|
||||
const initialLoad = !this.loadedMessagesForChats.includes(chatID);
|
||||
|
||||
this.getAllMessagesByChatID(chatID).then((responseBody) => {
|
||||
responseBody.response.forEach((message : message) => {
|
||||
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)){
|
||||
this.messages[chatID] = [];
|
||||
@@ -61,35 +48,17 @@ export const useMessageStore = defineStore('messageStore', {
|
||||
}
|
||||
|
||||
this.messages[chatID].unshift(message);
|
||||
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async getAllMessagesByChatID(chatID : number) {
|
||||
//const timestamp = !this.messages[chatID] ? 0 : this.messages[chatID][0].timestamp;
|
||||
let timestamp = "0";
|
||||
if(this.loadedMessagesForChats.includes(chatID)){
|
||||
timestamp = this.messages[chatID][0].timestamp;
|
||||
}
|
||||
//console.log("Timestamp: "+timestamp);
|
||||
|
||||
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");
|
||||
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user