2024-03-22 13:54:52 +01:00
|
|
|
/*******************************************************
|
|
|
|
* File: msg.js
|
|
|
|
* Author: Anthony Debucquoy
|
|
|
|
* Scope: Extension messagerie
|
|
|
|
* Description: Messages frontend api consumer
|
|
|
|
*******************************************************/
|
|
|
|
|
2024-03-27 19:52:48 +01:00
|
|
|
import { restGet, restPost, restPatch } from './restConsumer.js'
|
2024-03-23 01:06:32 +01:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
2024-03-25 00:08:44 +01:00
|
|
|
/**
|
|
|
|
* - id
|
|
|
|
* - name
|
|
|
|
* - members
|
|
|
|
*/
|
2024-03-27 19:52:48 +01:00
|
|
|
export const discussionsList = ref({});
|
|
|
|
export const currentDiscussion = ref({});
|
2024-03-23 01:06:32 +01:00
|
|
|
|
2024-03-22 13:54:52 +01:00
|
|
|
|
2024-03-25 00:08:44 +01:00
|
|
|
export async function createDiscussion(name){
|
2024-03-27 19:52:48 +01:00
|
|
|
let disc = await restPost("/discussion", {name: name});
|
|
|
|
discussionsList.value.push(disc);
|
2024-03-25 00:08:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function invite(id, regNo){
|
|
|
|
restPost("/discussion/"+ id+ "/invite", {user: regNo});
|
|
|
|
}
|
2024-03-27 19:52:48 +01:00
|
|
|
|
|
|
|
export async function sendMessage(id, content, responseId){
|
|
|
|
let data = {
|
|
|
|
content: content,
|
|
|
|
response: responseId,
|
|
|
|
}
|
|
|
|
restPost("/discussion/" + id, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateDiscussionName(id, name){
|
|
|
|
restPatch("/discussion/" + id, {name: name}).then(() => fetchDiscussions());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchDiscussions(){
|
|
|
|
discussionsList.value = await restGet("/discussions");
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function fetchDiscussion(id){
|
|
|
|
currentDiscussion.value = await restGet("/discussion/" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
await fetchDiscussions();
|