mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first success with storing messages
This commit is contained in:
parent
3d5cd58e9b
commit
d8e392ddba
8 changed files with 221 additions and 31 deletions
|
@ -13,14 +13,36 @@ const settings = useSettingsStore(pinia);
|
||||||
import { useStateStore } from '../store/stateStore.js';
|
import { useStateStore } from '../store/stateStore.js';
|
||||||
const state = useStateStore(pinia);
|
const state = useStateStore(pinia);
|
||||||
|
|
||||||
|
import { useChatStore } from '../store/chatStore.js';
|
||||||
|
const chat = useChatStore(pinia);
|
||||||
|
|
||||||
|
|
||||||
import chat_navbar from './chat_navbar.vue'
|
import chat_navbar from './chat_navbar.vue'
|
||||||
import chat_conversations from './chat_conversations.vue'
|
import chat_conversations from './chat_conversations.vue'
|
||||||
import chat_messages from './chat_messages.vue'
|
import chat_messages from './chat_messages.vue'
|
||||||
|
|
||||||
import {updateAllChat} from '../js/chatHandler'
|
import {updateAllChat, newMessage} from '../js/chatHandler'
|
||||||
|
|
||||||
updateAllChat()
|
updateAllChat()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function transmitNewMessage(){
|
||||||
|
console.log(chat.inputText)
|
||||||
|
console.log(chat.selectedCallsign)
|
||||||
|
|
||||||
|
newMessage(chat.selectedCallsign, chat.inputText)
|
||||||
|
|
||||||
|
// finally do a cleanup
|
||||||
|
chat.inputText = ''
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -67,10 +89,7 @@ updateAllChat()
|
||||||
style="height: calc(100% - 200px)"
|
style="height: calc(100% - 200px)"
|
||||||
>
|
>
|
||||||
<chat_messages/>
|
<chat_messages/>
|
||||||
<!--<div class="tab-content" id="nav-tabContent-Chat"></div>-->
|
|
||||||
<!--<div class="container position-absolute bottom-0">-->
|
|
||||||
</div>
|
</div>
|
||||||
<!-- </div>-->
|
|
||||||
<div class="container-fluid mt-2 p-0">
|
<div class="container-fluid mt-2 p-0">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -104,18 +123,22 @@ updateAllChat()
|
||||||
rows="1"
|
rows="1"
|
||||||
id="chatModuleMessage"
|
id="chatModuleMessage"
|
||||||
placeholder="Message - Send with [Enter]"
|
placeholder="Message - Send with [Enter]"
|
||||||
|
v-model="chat.inputText"
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|
||||||
<div class="input-group-text me-3">
|
<div class="input-group-text">
|
||||||
<i
|
<i
|
||||||
class="bi bi-paperclip"
|
class="bi bi-paperclip"
|
||||||
style="font-size: 1rem"
|
style="font-size: 1rem"
|
||||||
id="selectFilesButton"
|
id="selectFilesButton"
|
||||||
></i>
|
></i>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-secondary d-none invisible"
|
class="btn btn-sm btn-secondary me-2"
|
||||||
id="sendMessage"
|
id="sendMessage"
|
||||||
|
@click="transmitNewMessage()"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<i
|
<i
|
||||||
|
@ -123,7 +146,7 @@ updateAllChat()
|
||||||
style="font-size: 1.2rem"
|
style="font-size: 1.2rem"
|
||||||
></i>
|
></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,12 +23,23 @@ function deleteChat(callsign){
|
||||||
|
|
||||||
|
|
||||||
import chat_conversations_entry from './chat_conversations_entry.vue'
|
import chat_conversations_entry from './chat_conversations_entry.vue'
|
||||||
|
|
||||||
|
function chatSelected(callsign){
|
||||||
|
chat.selectedCallsign = callsign
|
||||||
|
|
||||||
|
// scroll message container to bottom
|
||||||
|
var messageBody = document.getElementById("message-container");
|
||||||
|
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<div class="list-group" id="chat-list-tab" role="chat-tablist">
|
<div class="list-group" id="chat-list-tab" role="chat-tablist">
|
||||||
<template v-for="(item, key) in chat.callsign_list" :key="item.dxcallsign">
|
<template v-for="(item, key) in chat.callsign_list" :key="item.dxcallsign">
|
||||||
<a class="list-group-item list-group-item-action" :class="{ active: key==0 }" :id="`list-chat-list-${item}`" data-bs-toggle="list" :href="`#list-${item}-messages`" role="tab" aria-controls="list-{{item}}-messages">
|
<a class="list-group-item list-group-item-action" :class="{ active: key==0 }" :id="`list-chat-list-${item}`" data-bs-toggle="list" :href="`#list-${item}-messages`" role="tab" aria-controls="list-{{item}}-messages" @click="chatSelected(item)">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9">{{item}}</div>
|
<div class="col-9">{{item}}</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
|
|
|
@ -21,11 +21,18 @@ const settings = useSettingsStore(pinia);
|
||||||
import { useStateStore } from '../store/stateStore.js';
|
import { useStateStore } from '../store/stateStore.js';
|
||||||
const state = useStateStore(pinia);
|
const state = useStateStore(pinia);
|
||||||
|
|
||||||
|
import { useChatStore } from '../store/chatStore.js';
|
||||||
|
const chat = useChatStore(pinia);
|
||||||
|
|
||||||
|
|
||||||
|
function chatSelected(){
|
||||||
|
chat.selectedCallsign =
|
||||||
|
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<a class="list-group-item list-group-item-action active" id="list-home-list" data-bs-toggle="list" href="#list-home" role="tab" aria-controls="list-home">Home</a>
|
<a class="list-group-item list-group-item-action active" id="list-home-list" data-bs-toggle="list" href="#list-home" role="tab" aria-controls="list-home" @click="chatSelected()">Home</a>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -36,7 +36,6 @@ return datetime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
|
const { v4: uuidv4 } = require("uuid");
|
||||||
|
|
||||||
|
|
||||||
// pinia store setup
|
// pinia store setup
|
||||||
import { setActivePinia } from 'pinia';
|
import { setActivePinia } from 'pinia';
|
||||||
import pinia from '../store/index';
|
import pinia from '../store/index';
|
||||||
|
@ -9,6 +12,15 @@ setActivePinia(pinia);
|
||||||
import { useChatStore } from '../store/chatStore.js';
|
import { useChatStore } from '../store/chatStore.js';
|
||||||
const chat = useChatStore(pinia);
|
const chat = useChatStore(pinia);
|
||||||
|
|
||||||
|
import { sendMessage } from './sock.js';
|
||||||
|
|
||||||
|
const FD = require("./src/js/freedata.js");
|
||||||
|
|
||||||
|
// split character
|
||||||
|
const split_char = "0;1;";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ---- MessageDB
|
// ---- MessageDB
|
||||||
try {
|
try {
|
||||||
|
@ -54,11 +66,85 @@ createChatIndex();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chat.callsign_list = new Set()
|
chat.callsign_list = new Set()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function newMessage(dxcallsign, chatmessage){
|
||||||
|
var mode = ''
|
||||||
|
var frames = ''
|
||||||
|
var data = ''
|
||||||
|
var file = ''
|
||||||
|
var file_checksum = crc32(file).toString(16).toUpperCase();
|
||||||
|
var checksum = ''
|
||||||
|
var message_type = 'transmit'
|
||||||
|
var command = ''
|
||||||
|
var filetype = "plain/text"
|
||||||
|
var filename = ''
|
||||||
|
var timestamp = Math.floor(Date.now() / 1000)
|
||||||
|
var uuid = uuidv4();
|
||||||
|
let uuidlast = uuid.lastIndexOf("-");
|
||||||
|
console.log(uuidlast)
|
||||||
|
uuidlast += 1;
|
||||||
|
if (uuidlast > 0) {
|
||||||
|
uuid = uuid.substring(uuidlast);
|
||||||
|
}
|
||||||
|
// slice uuid for reducing overhead
|
||||||
|
uuid = uuid.slice(-4);
|
||||||
|
|
||||||
|
|
||||||
|
var data_with_attachment =
|
||||||
|
timestamp +
|
||||||
|
split_char +
|
||||||
|
chatmessage +
|
||||||
|
split_char +
|
||||||
|
filename +
|
||||||
|
split_char +
|
||||||
|
filetype +
|
||||||
|
split_char +
|
||||||
|
file;
|
||||||
|
var tnc_command = "msg";
|
||||||
|
|
||||||
|
sendMessage(
|
||||||
|
dxcallsign,
|
||||||
|
data_with_attachment,
|
||||||
|
checksum,
|
||||||
|
uuid,
|
||||||
|
tnc_command
|
||||||
|
)
|
||||||
|
|
||||||
|
let newChatObj = new Object();
|
||||||
|
|
||||||
|
newChatObj.command = "msg"
|
||||||
|
newChatObj.hmac_signed = false
|
||||||
|
newChatObj.percent = 0
|
||||||
|
newChatObj.bytesperminute
|
||||||
|
newChatObj.is_new = false
|
||||||
|
newChatObj._id = uuid
|
||||||
|
newChatObj.timestamp = timestamp
|
||||||
|
newChatObj.dxcallsign = dxcallsign
|
||||||
|
newChatObj.dxgrid = "null"
|
||||||
|
newChatObj.msg = chatmessage
|
||||||
|
newChatObj.checksum = file_checksum
|
||||||
|
newChatObj.type = message_type
|
||||||
|
newChatObj.status = "transmit"
|
||||||
|
newChatObj.attempt = 1
|
||||||
|
newChatObj.uuid = uuid
|
||||||
|
newChatObj._attachments = {
|
||||||
|
[filename]: {
|
||||||
|
content_type: filetype,
|
||||||
|
data: FD.btoa_FD(file),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
addObjToDatabase(newChatObj)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sortChatList(){
|
function sortChatList(){
|
||||||
|
|
||||||
// Create an empty object to store the reordered data dynamically
|
// Create an empty object to store the reordered data dynamically
|
||||||
|
@ -113,7 +199,6 @@ export async function updateAllChat() {
|
||||||
chat.sorted_chat_list = sortChatList()
|
chat.sorted_chat_list = sortChatList()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
if (typeof result !== "undefined") {
|
if (typeof result !== "undefined") {
|
||||||
for (const item of result.docs) {
|
for (const item of result.docs) {
|
||||||
//await otherwise history will not be in chronological order
|
//await otherwise history will not be in chronological order
|
||||||
|
@ -140,6 +225,41 @@ export async function updateAllChat() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addObjToDatabase(newobj){
|
||||||
|
console.log(newobj)
|
||||||
|
/*
|
||||||
|
db.upsert(newobj._id, function (doc) {
|
||||||
|
if (!doc._id) {
|
||||||
|
console.log("upsert")
|
||||||
|
console.log(doc)
|
||||||
|
doc = newobj
|
||||||
|
} else {
|
||||||
|
console.log("new...")
|
||||||
|
*/
|
||||||
|
db.post(newobj)
|
||||||
|
.then(function (response) {
|
||||||
|
// handle response
|
||||||
|
console.log("new database entry");
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
chat.unsorted_chat_list.push(newobj)
|
||||||
|
chat.sorted_chat_list = sortChatList()
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// upsert footer ...
|
||||||
|
|
||||||
|
}
|
||||||
|
return doc;
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function createChatIndex() {
|
function createChatIndex() {
|
||||||
db.createIndex({
|
db.createIndex({
|
||||||
|
@ -159,7 +279,7 @@ function createChatIndex() {
|
||||||
"hmac_signed",
|
"hmac_signed",
|
||||||
"bytesperminute",
|
"bytesperminute",
|
||||||
"_attachments",
|
"_attachments",
|
||||||
"new",
|
"is_new",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -215,3 +335,37 @@ db.find({
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// CRC CHECKSUMS
|
||||||
|
// https://stackoverflow.com/a/50579690
|
||||||
|
// crc32 calculation
|
||||||
|
//console.log(crc32('abc'));
|
||||||
|
//var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
|
||||||
|
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
|
||||||
|
|
||||||
|
var makeCRCTable = function () {
|
||||||
|
var c;
|
||||||
|
var crcTable = [];
|
||||||
|
for (var n = 0; n < 256; n++) {
|
||||||
|
c = n;
|
||||||
|
for (var k = 0; k < 8; k++) {
|
||||||
|
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
||||||
|
}
|
||||||
|
crcTable[n] = c;
|
||||||
|
}
|
||||||
|
return crcTable;
|
||||||
|
};
|
||||||
|
|
||||||
|
var crc32 = function (str) {
|
||||||
|
var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
|
||||||
|
var crc = 0 ^ -1;
|
||||||
|
|
||||||
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xff];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (crc ^ -1) >>> 0;
|
||||||
|
};
|
|
@ -1,15 +1,5 @@
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { ipcRenderer } = require("electron");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save config and update config setting globally
|
|
||||||
* @param {string} config - config data
|
|
||||||
* @param {string} configPath
|
|
||||||
*/
|
|
||||||
exports.saveConfig = function (config, configPath) {
|
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
||||||
ipcRenderer.send("set-config-global", config);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binary to ASCII replacement
|
* Binary to ASCII replacement
|
||||||
|
|
|
@ -115,7 +115,7 @@ function writeTncCommand(command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.readyState == "closed") {
|
if (client.readyState == "closed") {
|
||||||
console.log("CLOSED!");
|
console.log("TNC SOCKET CONNECTION CLOSED!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.readyState == "opening") {
|
if (client.readyState == "opening") {
|
||||||
|
@ -683,11 +683,8 @@ function sendFile(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send Message
|
// Send Message
|
||||||
//exports.sendMessage = function (
|
export function sendMessage(
|
||||||
function sendMessage(
|
|
||||||
dxcallsign,
|
dxcallsign,
|
||||||
mode,
|
|
||||||
frames,
|
|
||||||
data,
|
data,
|
||||||
checksum,
|
checksum,
|
||||||
uuid,
|
uuid,
|
||||||
|
@ -704,6 +701,12 @@ function sendMessage(
|
||||||
split_char +
|
split_char +
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: REMOVE mode and frames from TNC!
|
||||||
|
var mode = 255
|
||||||
|
var frames = 5
|
||||||
|
|
||||||
|
|
||||||
command =
|
command =
|
||||||
'{"type" : "arq", "command" : "send_raw", "uuid" : "' +
|
'{"type" : "arq", "command" : "send_raw", "uuid" : "' +
|
||||||
uuid +
|
uuid +
|
||||||
|
@ -717,7 +720,6 @@ function sendMessage(
|
||||||
data +
|
data +
|
||||||
'", "attempts": "10"}]}';
|
'", "attempts": "10"}]}';
|
||||||
console.log(command);
|
console.log(command);
|
||||||
console.log("-------------------------------------");
|
|
||||||
writeTncCommand(command);
|
writeTncCommand(command);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -950,6 +952,7 @@ export function set_rf_level(rf_level){
|
||||||
// crc32 calculation
|
// crc32 calculation
|
||||||
//console.log(crc32('abc'));
|
//console.log(crc32('abc'));
|
||||||
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
|
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
|
||||||
|
|
||||||
var crc32 = function (r) {
|
var crc32 = function (r) {
|
||||||
for (var a, o = [], c = 0; c < 256; c++) {
|
for (var a, o = [], c = 0; c < 256; c++) {
|
||||||
a = c;
|
a = c;
|
||||||
|
|
|
@ -14,11 +14,14 @@ export const useChatStore = defineStore('chatStore', () => {
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
var selectedCallsign = ref()
|
||||||
|
var inputText = ref()
|
||||||
|
|
||||||
|
|
||||||
var callsign_list = ref()
|
var callsign_list = ref()
|
||||||
var sorted_chat_list = ref()
|
var sorted_chat_list = ref()
|
||||||
var unsorted_chat_list = ref([])
|
var unsorted_chat_list = ref([])
|
||||||
|
|
||||||
|
|
||||||
return {chat_filter, callsign_list, sorted_chat_list, unsorted_chat_list };
|
return {selectedCallsign, inputText, chat_filter, callsign_list, sorted_chat_list, unsorted_chat_list };
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue