mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
delete messages
This commit is contained in:
parent
69a7705043
commit
1bbfa6f22b
|
@ -43,7 +43,7 @@
|
|||
<i class="bi bi-download"></i>
|
||||
</button>
|
||||
|
||||
<button disabled class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<i class="bi bi-info-circle"></i>
|
||||
</button>
|
||||
|
||||
<button disabled class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||
<button class="btn btn-outline-secondary border-0" @click="deleteMessage">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -11,14 +11,14 @@ const chat = useChatStore(pinia);
|
|||
import { settingsStore as settings, onChange } from "../store/settingsStore.js";
|
||||
import { sendModemTestFrame } from "../js/api";
|
||||
import main_startup_check from "./main_startup_check.vue";
|
||||
import { newMessage } from '../js/messagesHandler.ts'
|
||||
import { newMessage, deleteCallsignFromDB } from '../js/messagesHandler.ts'
|
||||
|
||||
function newChat(){
|
||||
newMessage(chat.newChatCallsign, chat.newChatMessage)
|
||||
}
|
||||
|
||||
function deleteChat() {
|
||||
return
|
||||
deleteCallsignFromDB(chat.selectedCallsign);
|
||||
}
|
||||
|
||||
import {
|
||||
|
|
|
@ -46,6 +46,27 @@ export async function apiPost(endpoint, payload = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function apiDelete(endpoint, payload = {}) {
|
||||
try {
|
||||
const response = await fetch(buildURL(settings.local, endpoint), {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`REST response not ok: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error deleting from REST:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getVersion() {
|
||||
let data = await apiGet("/version").then((res) => {
|
||||
return res;
|
||||
|
@ -55,30 +76,30 @@ export async function getVersion() {
|
|||
}
|
||||
|
||||
export async function getConfig() {
|
||||
return apiGet("/config");
|
||||
return await apiGet("/config");
|
||||
}
|
||||
|
||||
export function setConfig(config) {
|
||||
return apiPost("/config", config);
|
||||
export async function setConfig(config) {
|
||||
return await apiPost("/config", config);
|
||||
}
|
||||
|
||||
export function getAudioDevices() {
|
||||
return apiGet("/devices/audio");
|
||||
export async function getAudioDevices() {
|
||||
return await apiGet("/devices/audio");
|
||||
}
|
||||
|
||||
export function getSerialDevices() {
|
||||
return apiGet("/devices/serial");
|
||||
export async function getSerialDevices() {
|
||||
return await apiGet("/devices/serial");
|
||||
}
|
||||
|
||||
export function setModemBeacon(enabled = false) {
|
||||
return apiPost("/modem/beacon", { enabled: enabled });
|
||||
export async function setModemBeacon(enabled = false) {
|
||||
return await apiPost("/modem/beacon", { enabled: enabled });
|
||||
}
|
||||
|
||||
export function sendModemCQ() {
|
||||
return apiPost("/modem/cqcqcq");
|
||||
export async function sendModemCQ() {
|
||||
return await apiPost("/modem/cqcqcq");
|
||||
}
|
||||
|
||||
export function sendModemPing(dxcall) {
|
||||
export async function sendModemPing(dxcall) {
|
||||
if (
|
||||
validateCallsignWithSSID(dxcall) === false &&
|
||||
validateCallsignWithoutSSID(dxcall) === true
|
||||
|
@ -88,11 +109,11 @@ export function sendModemPing(dxcall) {
|
|||
}
|
||||
dxcall = String(dxcall).toUpperCase().trim();
|
||||
if (validateCallsignWithSSID(dxcall))
|
||||
return apiPost("/modem/ping_ping", { dxcall: dxcall });
|
||||
return await apiPost("/modem/ping_ping", { dxcall: dxcall });
|
||||
}
|
||||
|
||||
export function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
||||
return apiPost("/modem/send_arq_raw", {
|
||||
export async function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
||||
return await apiPost("/modem/send_arq_raw", {
|
||||
mycallsign: mycall,
|
||||
dxcall: dxcall,
|
||||
data: data,
|
||||
|
@ -100,35 +121,35 @@ export function sendModemARQRaw(mycall, dxcall, data, uuid) {
|
|||
});
|
||||
}
|
||||
|
||||
export function stopTransmission() {
|
||||
return apiPost("/modem/stop_transmission");
|
||||
export async function stopTransmission() {
|
||||
return await apiPost("/modem/stop_transmission");
|
||||
}
|
||||
|
||||
export function sendModemTestFrame() {
|
||||
return apiPost("/modem/send_test_frame");
|
||||
export async function sendModemTestFrame() {
|
||||
return await apiPost("/modem/send_test_frame");
|
||||
}
|
||||
|
||||
export function startModem() {
|
||||
return apiPost("/modem/start");
|
||||
export async function startModem() {
|
||||
return await apiPost("/modem/start");
|
||||
}
|
||||
|
||||
export function stopModem() {
|
||||
return apiPost("/modem/stop");
|
||||
export async function stopModem() {
|
||||
return await apiPost("/modem/stop");
|
||||
}
|
||||
|
||||
export function getModemState() {
|
||||
return apiGet("/modem/state");
|
||||
export async function getModemState() {
|
||||
return await apiGet("/modem/state");
|
||||
}
|
||||
|
||||
export function setRadioParameters(frequency, mode, rf_level) {
|
||||
return apiPost("/radio", {
|
||||
export async function setRadioParameters(frequency, mode, rf_level) {
|
||||
return await apiPost("/radio", {
|
||||
radio_frequency: frequency,
|
||||
radio_mode: mode,
|
||||
radio_rf_level: rf_level,
|
||||
});
|
||||
}
|
||||
export function getRadioStatus() {
|
||||
return apiGet("/radio");
|
||||
export async function getRadioStatus() {
|
||||
return await apiGet("/radio");
|
||||
}
|
||||
|
||||
export async function getFreedataMessages(){
|
||||
|
@ -141,4 +162,8 @@ export async function sendFreedataMessage(dxcall, body) {
|
|||
dxcall: dxcall,
|
||||
body: body,
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteFreedataMessage(id) {
|
||||
return await apiDelete(`/freedata/messages/${id}`);
|
||||
}
|
|
@ -6,7 +6,7 @@ setActivePinia(pinia);
|
|||
import { useChatStore } from "../store/chatStore.js";
|
||||
const chatStore = useChatStore(pinia);
|
||||
|
||||
import { sendFreedataMessage } from "./api"
|
||||
import { sendFreedataMessage, deleteFreedataMessage } from "./api"
|
||||
|
||||
interface Message {
|
||||
id: string;
|
||||
|
@ -71,8 +71,15 @@ export function repeatMessageTransmission(id){
|
|||
return
|
||||
}
|
||||
|
||||
export function deleteCallsignFromDB(callsign){
|
||||
for (var message of chatStore.sorted_chat_list[callsign]) {
|
||||
deleteFreedataMessage(message["id"]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function deleteMessageFromDB(id){
|
||||
return
|
||||
deleteFreedataMessage(id);
|
||||
}
|
||||
|
||||
export function requestMessageInfo(id){
|
||||
|
|
|
@ -166,6 +166,7 @@ class DatabaseManager:
|
|||
session.delete(message)
|
||||
session.commit()
|
||||
self.log(f"Deleted: {message_id}")
|
||||
self.event_manager.freedata_message_db_change()
|
||||
return {'status': 'success', 'message': f'Message {message_id} deleted'}
|
||||
else:
|
||||
return {'status': 'failure', 'message': 'Message not found'}
|
||||
|
@ -188,6 +189,7 @@ class DatabaseManager:
|
|||
message.body = update_data['body']
|
||||
session.commit()
|
||||
self.log(f"Updated: {message_id}")
|
||||
self.event_manager.freedata_message_db_change()
|
||||
return {'status': 'success', 'message': f'Message {message_id} updated'}
|
||||
else:
|
||||
return {'status': 'failure', 'message': 'Message not found'}
|
||||
|
|
Loading…
Reference in a new issue