From 0f2b48419d740e270402eb6d675d9d3e4b684a0e Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Tue, 12 Sep 2023 17:52:16 +0200 Subject: [PATCH] first test run with chat module --- gui_vue/src/components/chat.vue | 648 +++++ gui_vue/src/components/chat_conversations.vue | 41 + .../components/chat_conversations_entry.vue | 21 + gui_vue/src/components/chat_messages.vue | 28 + gui_vue/src/components/chat_navbar.vue | 289 +++ gui_vue/src/components/main.vue | 2213 ++++++----------- .../components/main_active_heard_stations.vue | 6 + gui_vue/src/js/chatHandler.js | 162 ++ gui_vue/src/main.ts | 1 + gui_vue/src/store/chatStore.js | 18 + 10 files changed, 1916 insertions(+), 1511 deletions(-) create mode 100644 gui_vue/src/components/chat.vue create mode 100644 gui_vue/src/components/chat_conversations.vue create mode 100644 gui_vue/src/components/chat_conversations_entry.vue create mode 100644 gui_vue/src/components/chat_messages.vue create mode 100644 gui_vue/src/components/chat_navbar.vue create mode 100644 gui_vue/src/js/chatHandler.js create mode 100644 gui_vue/src/store/chatStore.js diff --git a/gui_vue/src/components/chat.vue b/gui_vue/src/components/chat.vue new file mode 100644 index 00000000..d87e8f9f --- /dev/null +++ b/gui_vue/src/components/chat.vue @@ -0,0 +1,648 @@ + + + diff --git a/gui_vue/src/components/chat_conversations.vue b/gui_vue/src/components/chat_conversations.vue new file mode 100644 index 00000000..80f8336f --- /dev/null +++ b/gui_vue/src/components/chat_conversations.vue @@ -0,0 +1,41 @@ + + + diff --git a/gui_vue/src/components/chat_conversations_entry.vue b/gui_vue/src/components/chat_conversations_entry.vue new file mode 100644 index 00000000..596011d3 --- /dev/null +++ b/gui_vue/src/components/chat_conversations_entry.vue @@ -0,0 +1,21 @@ + + + diff --git a/gui_vue/src/components/chat_messages.vue b/gui_vue/src/components/chat_messages.vue new file mode 100644 index 00000000..7d013451 --- /dev/null +++ b/gui_vue/src/components/chat_messages.vue @@ -0,0 +1,28 @@ + + + diff --git a/gui_vue/src/components/chat_navbar.vue b/gui_vue/src/components/chat_navbar.vue new file mode 100644 index 00000000..55d42f14 --- /dev/null +++ b/gui_vue/src/components/chat_navbar.vue @@ -0,0 +1,289 @@ + + + diff --git a/gui_vue/src/components/main.vue b/gui_vue/src/components/main.vue index bd8438e6..84214974 100644 --- a/gui_vue/src/components/main.vue +++ b/gui_vue/src/components/main.vue @@ -27,6 +27,7 @@ import main_active_broadcasts from './main_active_broadcasts.vue' import main_active_heard_stations from './main_active_heard_stations.vue' import main_active_audio_level from './main_active_audio_level.vue' +import chat from './chat.vue' @@ -98,24 +99,12 @@ function changeGuiDesign(design) { //update path to css file document.getElementById("bootstrap_theme").href = escape(theme_path); } - - - - - - - - - diff --git a/gui_vue/src/components/main_active_heard_stations.vue b/gui_vue/src/components/main_active_heard_stations.vue index 832efd8e..4c49c087 100644 --- a/gui_vue/src/components/main_active_heard_stations.vue +++ b/gui_vue/src/components/main_active_heard_stations.vue @@ -39,7 +39,13 @@ return datetime } function getMaidenheadDistance(dxGrid){ +try{ return parseInt(distance(settings.mygrid, dxGrid)); +}catch(e){ +// +} + + } diff --git a/gui_vue/src/js/chatHandler.js b/gui_vue/src/js/chatHandler.js new file mode 100644 index 00000000..ee4f637a --- /dev/null +++ b/gui_vue/src/js/chatHandler.js @@ -0,0 +1,162 @@ +const path = require("path"); +const fs = require("fs"); + +// pinia store setup +import { setActivePinia } from 'pinia'; +import pinia from '../store/index'; +setActivePinia(pinia); + +import { useChatStore } from '../store/chatStore.js'; +const chat = useChatStore(pinia); + + +// ---- MessageDB +try { + var PouchDB = require("pouchdb"); +} catch (err) { + console.log(err); + + /* + This is a fix for raspberryPi where we get an error when loading pouchdb because of + leveldown package isnt running on ARM devices. + pouchdb-browser does not depend on leveldb and seems to be working. + */ + console.log("using pouchdb-browser fallback"); + var PouchDB = require("pouchdb-browser"); +} + + +PouchDB.plugin(require("pouchdb-find")); +//PouchDB.plugin(require('pouchdb-replication')); +PouchDB.plugin(require("pouchdb-upsert")); + + + +// https://stackoverflow.com/a/26227660 +var appDataFolder = + process.env.APPDATA || + (process.platform == "darwin" + ? process.env.HOME + "/Library/Application Support" + : process.env.HOME + "/.config"); +var configFolder = path.join(appDataFolder, "FreeDATA"); + + + + +var chatDB = path.join(configFolder, "chatDB"); +var db = new PouchDB(chatDB); + +/* -------- CREATE DATABASE INDEXES */ +createChatIndex(); + + + + + + + +chat.callsign_list = new Set() + + + + + + +export async function updateAllChat() { + + //Ensure we create an index before running db.find + //We can't rely on the default index existing before we get here...... :'( + await db + .createIndex({ + index: { + fields: [{ dxcallsign: "asc" }, { timestamp: "asc" }], + }, + }) + .then(async function (result) { + // handle result + await db + .find({ + selector: { + $and: [ + { dxcallsign: { $exists: true } }, + { timestamp: { $exists: true } }, + { $or: chat.chat_filter }, + ], + //$or: chat.chat_filter + }, + sort: [{ dxcallsign: "asc" }, { timestamp: "asc" }], + }) + .then(async function (result) { + console.log(result); + for (var item of result.docs) { + console.log(item) + chat.callsign_list.add(item.dxcallsign) + + } + + // handle result async + + + /* + + if (typeof result !== "undefined") { + for (const item of result.docs) { + //await otherwise history will not be in chronological order + await db + .get(item._id, { + attachments: true, + }) + .then(function (item_with_attachments) { + update_chat(item_with_attachments); + }); + } + } + */ + + + }) + .catch(function (err) { + console.log(err); + }); + }) + .catch(function (err) { + console.log(err); + }); + +} + + + + + + +function createChatIndex() { + db.createIndex({ + index: { + fields: [ + "timestamp", + "uuid", + "dxcallsign", + "dxgrid", + "msg", + "checksum", + "type", + "command", + "status", + "percent", + "attempt", + "hmac_signed", + "bytesperminute", + "_attachments", + "new", + ], + }, + }) + .then(function (result) { + // handle result + console.log(result); + }) + .catch(function (err) { + console.log(err); + }); +} diff --git a/gui_vue/src/main.ts b/gui_vue/src/main.ts index f056580a..6e6db99f 100644 --- a/gui_vue/src/main.ts +++ b/gui_vue/src/main.ts @@ -38,3 +38,4 @@ loadSettings() //import './js/settingsHandler.js' import './js/daemon.js' import './js/sock.js' +//import './js/settingsHandler.js' diff --git a/gui_vue/src/store/chatStore.js b/gui_vue/src/store/chatStore.js new file mode 100644 index 00000000..8f7b5817 --- /dev/null +++ b/gui_vue/src/store/chatStore.js @@ -0,0 +1,18 @@ +import { defineStore } from 'pinia' +import { ref, computed } from 'vue'; + +export const useChatStore = defineStore('chatStore', () => { + var chat_filter = ref([ + { type: "newchat" }, + { type: "received" }, + { type: "transmit" }, + { type: "ping-ack" }, + { type: "broadcast_received" }, + { type: "broadcast_transmit" }, + //{ type: "request" }, + //{ type: "response" }, + ]) + + var callsign_list = ref() + return {chat_filter, callsign_list }; +});