Files
ptpchat-frontend/src/stores/message-store.ts
joschuatonn c8d5bc5734 Worked on several new features:
- ProfilePictures for users are now pulled from the backend
- added a component for chat settings (WIP)
- added a loading screen when the backend is not available
- reworked the "add chat" feature
- started to implement the general send-message functionality
2024-05-25 13:37:50 +02:00

29 lines
877 B
TypeScript

import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import { message, ptpUser, responseModel } from 'src/models';
import Keycloak, { KeycloakInitOptions, KeycloakLoginOptions } from 'keycloak-js';
export const useMessageStore = defineStore('messageStore', {
state: () => ({
messages: [[]] as [message[]],
}),
actions: {
async sendMessage(chatId : number, senderId : string, content : string) {
await api.post("/messages/"+chatId+"/"+senderId+"/"+content).then((result) => {
this.loadMessagesByChatID(chatId);
});
},
loadMessagesByChatID(chatID : number) {
this.getAllMessagesByChatID(chatID).then((messages) => {
this.messages[chatID] = messages;
});
},
async getAllMessagesByChatID(chatID : number) {
return (await api.get("/messages/chat/"+chatID)).data;
},
},
});