2021-11-19 16:30:17 +00:00
|
|
|
const path = require('path')
|
|
|
|
const {
|
|
|
|
ipcRenderer
|
|
|
|
} = require('electron')
|
2022-03-24 19:49:13 +00:00
|
|
|
const {
|
|
|
|
v4: uuidv4
|
|
|
|
} = require('uuid');
|
2022-03-14 19:21:15 +00:00
|
|
|
const utf8 = require('utf8');
|
2022-04-06 08:15:14 +00:00
|
|
|
const blobUtil = require('blob-util')
|
2021-11-19 16:30:17 +00:00
|
|
|
// 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 configPath = path.join(configFolder, 'config.json')
|
|
|
|
const config = require(configPath);
|
2022-03-10 20:29:30 +00:00
|
|
|
// set date format
|
|
|
|
const dateFormat = new Intl.DateTimeFormat('en-GB', {
|
|
|
|
timeStyle: 'long',
|
|
|
|
dateStyle: 'full'
|
|
|
|
});
|
2022-03-24 19:49:13 +00:00
|
|
|
// set date format information
|
|
|
|
const dateFormatShort = new Intl.DateTimeFormat('en-GB', {
|
|
|
|
year: 'numeric',
|
|
|
|
month: 'numeric',
|
|
|
|
day: 'numeric',
|
|
|
|
hour: 'numeric',
|
|
|
|
minute: 'numeric',
|
|
|
|
second: 'numeric',
|
|
|
|
hour12: false,
|
|
|
|
});
|
2022-04-02 16:40:12 +00:00
|
|
|
|
|
|
|
const dateFormatHours = new Intl.DateTimeFormat('en-GB', {
|
|
|
|
hour: 'numeric',
|
|
|
|
minute: 'numeric',
|
|
|
|
hour12: false,
|
|
|
|
});
|
2022-03-10 20:29:30 +00:00
|
|
|
// split character
|
|
|
|
const split_char = '\0;'
|
2022-03-24 19:49:13 +00:00
|
|
|
// global for our selected file we want to transmit
|
2022-03-29 20:24:35 +00:00
|
|
|
// ----------------- some chat globals
|
2022-03-24 19:49:13 +00:00
|
|
|
var filetype = '';
|
|
|
|
var file = '';
|
|
|
|
var filename = '';
|
2022-03-29 20:24:35 +00:00
|
|
|
var callsign_counter = 0;
|
|
|
|
var selected_callsign = '';
|
|
|
|
// -----------------------------------
|
2022-04-03 13:26:24 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
var chatDB = path.join(configFolder, 'chatDB')
|
|
|
|
// ---- MessageDB
|
2022-06-15 12:34:17 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2022-03-14 19:21:15 +00:00
|
|
|
PouchDB.plugin(require('pouchdb-find'));
|
2022-03-10 20:29:30 +00:00
|
|
|
var db = new PouchDB(chatDB);
|
|
|
|
var dxcallsigns = new Set();
|
2022-03-14 19:21:15 +00:00
|
|
|
db.createIndex({
|
2022-03-24 19:49:13 +00:00
|
|
|
index: {
|
2022-04-07 09:19:29 +00:00
|
|
|
fields: ['timestamp', 'uuid', 'dxcallsign', 'dxgrid', 'msg', 'checksum', 'type', 'command', 'status', 'percent', 'bytesperminute', '_attachments']
|
2022-03-24 19:49:13 +00:00
|
|
|
}
|
|
|
|
}).then(function(result) {
|
|
|
|
// handle result
|
|
|
|
console.log(result)
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
2022-03-10 20:29:30 +00:00
|
|
|
});
|
2022-03-14 19:21:15 +00:00
|
|
|
db.find({
|
2022-03-24 19:49:13 +00:00
|
|
|
selector: {
|
|
|
|
timestamp: {
|
|
|
|
$exists: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sort: [{
|
|
|
|
'timestamp': 'asc'
|
|
|
|
}]
|
|
|
|
}).then(function(result) {
|
|
|
|
// handle result
|
|
|
|
if (typeof(result) !== 'undefined') {
|
|
|
|
result.docs.forEach(function(item) {
|
2022-06-07 09:31:59 +00:00
|
|
|
//console.log(item)
|
2022-03-24 19:49:13 +00:00
|
|
|
update_chat(item);
|
|
|
|
});
|
2022-03-14 19:21:15 +00:00
|
|
|
}
|
2022-03-24 19:49:13 +00:00
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
2022-03-14 19:21:15 +00:00
|
|
|
});
|
2021-11-19 16:30:17 +00:00
|
|
|
// WINDOW LISTENER
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
2022-04-03 13:26:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// theme selector
|
|
|
|
if(config.theme != 'default'){
|
|
|
|
var theme_path = "../node_modules/bootswatch/dist/"+ config.theme +"/bootstrap.min.css";
|
|
|
|
document.getElementById("bootstrap_theme").href = theme_path;
|
|
|
|
} else {
|
|
|
|
var theme_path = "../node_modules/bootstrap/dist/css/bootstrap.min.css";
|
|
|
|
document.getElementById("bootstrap_theme").href = theme_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
document.querySelector('emoji-picker').addEventListener("emoji-click", (event) => {
|
|
|
|
document.getElementById('chatModuleMessage').setRangeText(event.detail.emoji.unicode)
|
|
|
|
console.log(event.detail);
|
|
|
|
})
|
|
|
|
document.getElementById("emojipickerbutton").addEventListener("click", () => {
|
|
|
|
var element = document.getElementById("emojipickercontainer")
|
|
|
|
console.log(element.style.display);
|
|
|
|
if (element.style.display === "none") {
|
|
|
|
element.style.display = "block";
|
|
|
|
} else {
|
|
|
|
element.style.display = "none";
|
|
|
|
}
|
|
|
|
})
|
2022-03-29 20:24:35 +00:00
|
|
|
document.getElementById("delete_selected_chat").addEventListener("click", () => {
|
|
|
|
db.find({
|
|
|
|
selector: {
|
|
|
|
dxcallsign: selected_callsign
|
|
|
|
}
|
|
|
|
}).then(function(result) {
|
|
|
|
// handle result
|
|
|
|
if (typeof(result) !== 'undefined') {
|
|
|
|
result.docs.forEach(function(item) {
|
|
|
|
console.log(item)
|
|
|
|
db.get(item._id).then(function(doc) {
|
2022-06-15 10:21:03 +00:00
|
|
|
db.remove(doc).then(function(doc) {
|
|
|
|
return location.reload();
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
2022-03-29 20:24:35 +00:00
|
|
|
});
|
2022-06-15 10:21:03 +00:00
|
|
|
|
2022-03-29 20:24:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
})
|
2022-03-27 19:04:04 +00:00
|
|
|
document.getElementById("selectFilesButton").addEventListener("click", () => {
|
|
|
|
//document.getElementById('selectFiles').click();
|
2022-03-24 19:49:13 +00:00
|
|
|
ipcRenderer.send('select-file', {
|
|
|
|
title: 'Title',
|
2022-03-29 20:24:35 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
|
|
|
|
document.getElementById("ping").addEventListener("click", () => {
|
|
|
|
ipcRenderer.send('run-tnc-command', {
|
|
|
|
command: 'ping', dxcallsign: selected_callsign
|
|
|
|
});
|
2022-03-24 19:49:13 +00:00
|
|
|
})
|
2022-03-29 20:24:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
document.addEventListener("keyup", function(event) {
|
|
|
|
// Number 13 == Enter
|
2022-04-03 13:26:24 +00:00
|
|
|
if (event.keyCode === 13 && !event.shiftKey) {
|
2022-03-29 20:24:35 +00:00
|
|
|
// Cancel the default action, if needed
|
|
|
|
event.preventDefault();
|
|
|
|
// Trigger the button element with a click
|
|
|
|
document.getElementById("sendMessage").click();
|
|
|
|
}
|
|
|
|
});
|
2022-03-27 19:04:04 +00:00
|
|
|
|
2022-06-15 11:08:26 +00:00
|
|
|
// ADJUST TEXTAREA SIZE
|
|
|
|
document.getElementById("chatModuleMessage").addEventListener("input", () => {
|
|
|
|
var textarea = document.getElementById("chatModuleMessage");
|
|
|
|
var text = textarea.value;
|
|
|
|
var lines = text.split("\n").length
|
|
|
|
if (lines >= 10){
|
|
|
|
lines = 10;
|
|
|
|
}
|
|
|
|
var message_container_height_offset = 90 + (23*lines);
|
|
|
|
var message_container_height = `calc(100% - ${message_container_height_offset}px)`;
|
|
|
|
document.getElementById("message-container").style.height = message_container_height;
|
|
|
|
textarea.rows = lines;
|
|
|
|
|
2022-03-27 19:04:04 +00:00
|
|
|
|
2022-06-15 11:08:26 +00:00
|
|
|
})
|
2022-04-02 12:54:43 +00:00
|
|
|
|
|
|
|
// NEW CHAT
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("createNewChatButton").addEventListener("click", () => {
|
|
|
|
var dxcallsign = document.getElementById('chatModuleNewDxCall').value;
|
|
|
|
var uuid = uuidv4()
|
|
|
|
db.post({
|
|
|
|
|
|
|
|
_id: uuid,
|
|
|
|
timestamp: Math.floor(Date.now() / 1000),
|
|
|
|
dxcallsign: dxcallsign.toUpperCase(),
|
|
|
|
dxgrid: '---',
|
2022-04-02 16:40:12 +00:00
|
|
|
msg: 'null',
|
|
|
|
checksum: 'null',
|
2022-04-02 12:54:43 +00:00
|
|
|
type: 'newchat',
|
2022-04-02 16:40:12 +00:00
|
|
|
status: 'null',
|
2022-04-02 12:54:43 +00:00
|
|
|
uuid: uuid
|
|
|
|
|
|
|
|
}).then(function(response) {
|
|
|
|
// handle response
|
|
|
|
console.log("new database entry");
|
|
|
|
console.log(response);
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2022-06-07 09:31:59 +00:00
|
|
|
update_chat_obj_by_uuid(uuid);
|
|
|
|
|
2022-04-02 12:54:43 +00:00
|
|
|
});
|
|
|
|
|
2021-11-19 16:30:17 +00:00
|
|
|
// SEND MSG
|
|
|
|
document.getElementById("sendMessage").addEventListener("click", () => {
|
2022-03-24 19:49:13 +00:00
|
|
|
document.getElementById('emojipickercontainer').style.display = "none";
|
2022-04-02 12:54:43 +00:00
|
|
|
|
|
|
|
var dxcallsign = selected_callsign.toUpperCase();
|
2022-06-15 11:08:26 +00:00
|
|
|
var textarea = document.getElementById('chatModuleMessage')
|
|
|
|
var chatmessage = textarea.value;
|
|
|
|
|
|
|
|
// reset textarea size
|
|
|
|
var message_container_height_offset = 110;
|
|
|
|
var message_container_height = `calc(100% - ${message_container_height_offset}px)`;
|
|
|
|
document.getElementById("message-container").style.height = message_container_height;
|
|
|
|
textarea.rows = 1
|
|
|
|
|
2022-03-27 19:04:04 +00:00
|
|
|
console.log(file);
|
|
|
|
console.log(filename);
|
2022-03-29 20:24:35 +00:00
|
|
|
console.log(filetype);
|
2022-06-09 12:54:42 +00:00
|
|
|
if (filetype == ''){
|
|
|
|
filetype = 'plain/text'
|
|
|
|
}
|
2022-03-24 19:49:13 +00:00
|
|
|
var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + file;
|
2022-04-06 08:15:14 +00:00
|
|
|
|
2022-04-03 13:26:24 +00:00
|
|
|
|
|
|
|
document.getElementById('selectFilesButton').innerHTML = ``;
|
2022-03-24 19:49:13 +00:00
|
|
|
var uuid = uuidv4();
|
2022-03-27 19:04:04 +00:00
|
|
|
console.log(data_with_attachment)
|
2022-03-24 19:49:13 +00:00
|
|
|
let Data = {
|
|
|
|
command: "send_message",
|
|
|
|
dxcallsign: dxcallsign,
|
|
|
|
mode: 255,
|
|
|
|
frames: 1,
|
|
|
|
data: data_with_attachment,
|
|
|
|
checksum: '123',
|
|
|
|
uuid: uuid
|
|
|
|
};
|
|
|
|
ipcRenderer.send('run-tnc-command', Data);
|
2022-03-10 20:29:30 +00:00
|
|
|
db.post({
|
2022-03-24 19:49:13 +00:00
|
|
|
_id: uuid,
|
|
|
|
timestamp: Math.floor(Date.now() / 1000),
|
|
|
|
dxcallsign: dxcallsign,
|
2022-04-02 16:40:12 +00:00
|
|
|
dxgrid: 'null',
|
2022-03-24 19:49:13 +00:00
|
|
|
msg: chatmessage,
|
2022-04-02 16:40:12 +00:00
|
|
|
checksum: 'null',
|
2022-03-24 19:49:13 +00:00
|
|
|
type: "transmit",
|
|
|
|
status: 'transmit',
|
|
|
|
uuid: uuid,
|
|
|
|
_attachments: {
|
|
|
|
[filename]: {
|
|
|
|
content_type: filetype,
|
2022-03-27 19:04:04 +00:00
|
|
|
data: btoa(file)
|
2022-03-24 19:49:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(function(response) {
|
|
|
|
// handle response
|
|
|
|
console.log("new database entry");
|
|
|
|
console.log(response);
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
update_chat_obj_by_uuid(uuid);
|
|
|
|
|
2022-03-12 14:06:49 +00:00
|
|
|
// scroll to bottom
|
|
|
|
var element = document.getElementById("message-container");
|
2022-03-24 19:49:13 +00:00
|
|
|
element.scrollTo(0, element.scrollHeight);
|
2022-03-12 14:06:49 +00:00
|
|
|
// clear input
|
2022-03-24 19:49:13 +00:00
|
|
|
document.getElementById('chatModuleMessage').value = ''
|
2022-04-06 08:15:14 +00:00
|
|
|
|
2022-06-09 12:54:42 +00:00
|
|
|
// after adding file data to our attachment variable, delete it from global
|
2022-04-06 08:15:14 +00:00
|
|
|
filetype = '';
|
|
|
|
file = '';
|
|
|
|
filename = '';
|
|
|
|
|
|
|
|
|
2021-11-19 16:30:17 +00:00
|
|
|
})
|
2022-03-24 19:49:13 +00:00
|
|
|
// cleanup after transmission
|
|
|
|
filetype = '';
|
|
|
|
file = '';
|
|
|
|
filename = '';
|
|
|
|
});
|
|
|
|
ipcRenderer.on('return-selected-files', (event, arg) => {
|
|
|
|
filetype = arg.mime;
|
2022-06-09 12:54:42 +00:00
|
|
|
console.log(filetype)
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
file = arg.data;
|
|
|
|
filename = arg.filename;
|
2022-03-27 19:04:04 +00:00
|
|
|
document.getElementById('selectFilesButton').innerHTML = `
|
2022-04-03 13:26:24 +00:00
|
|
|
<span class="position-absolute top-0 start-85 translate-middle p-2 bg-danger border border-light rounded-circle">
|
2022-03-24 19:49:13 +00:00
|
|
|
<span class="visually-hidden">New file selected</span>
|
|
|
|
</span>
|
|
|
|
`;
|
2022-03-14 19:21:15 +00:00
|
|
|
});
|
|
|
|
ipcRenderer.on('action-update-transmission-status', (event, arg) => {
|
2022-06-09 12:11:39 +00:00
|
|
|
var data = arg["data"][0]
|
|
|
|
console.log(data.status);
|
|
|
|
db.get(data.uuid, {
|
2022-03-24 19:49:13 +00:00
|
|
|
attachments: true
|
|
|
|
}).then(function(doc) {
|
|
|
|
return db.put({
|
2022-06-09 12:11:39 +00:00
|
|
|
_id: data.uuid,
|
2022-03-24 19:49:13 +00:00
|
|
|
_rev: doc._rev,
|
|
|
|
timestamp: doc.timestamp,
|
|
|
|
dxcallsign: doc.dxcallsign,
|
|
|
|
dxgrid: doc.dxgrid,
|
|
|
|
msg: doc.msg,
|
|
|
|
checksum: doc.checksum,
|
|
|
|
type: "transmit",
|
2022-06-09 12:11:39 +00:00
|
|
|
status: data.status,
|
|
|
|
percent: data.percent,
|
|
|
|
bytesperminute: data.bytesperminute,
|
2022-03-27 19:04:04 +00:00
|
|
|
uuid: doc.uuid,
|
|
|
|
_attachments: doc._attachments
|
2022-03-24 19:49:13 +00:00
|
|
|
});
|
|
|
|
}).then(function(response) {
|
2022-06-09 12:11:39 +00:00
|
|
|
update_chat_obj_by_uuid(data.uuid);
|
2022-06-07 09:31:59 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
2022-06-09 12:11:39 +00:00
|
|
|
console.log(data)
|
2022-03-24 19:49:13 +00:00
|
|
|
});
|
2022-03-10 20:29:30 +00:00
|
|
|
});
|
|
|
|
ipcRenderer.on('action-new-msg-received', (event, arg) => {
|
2022-03-24 19:49:13 +00:00
|
|
|
console.log(arg.data)
|
2022-06-07 09:31:59 +00:00
|
|
|
|
2022-03-14 19:21:15 +00:00
|
|
|
var new_msg = arg.data;
|
2022-03-10 20:29:30 +00:00
|
|
|
new_msg.forEach(function(item) {
|
2022-06-09 12:11:39 +00:00
|
|
|
console.log(item.status)
|
2022-03-10 20:29:30 +00:00
|
|
|
let obj = new Object();
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
//handle ping
|
|
|
|
if (item.ping == 'received') {
|
2022-03-24 19:49:13 +00:00
|
|
|
obj.timestamp = item.timestamp;
|
|
|
|
obj.dxcallsign = item.dxcallsign;
|
|
|
|
obj.dxgrid = item.dxgrid;
|
|
|
|
obj.uuid = item.uuid;
|
|
|
|
obj.command = 'ping';
|
|
|
|
obj.checksum = 'null';
|
|
|
|
obj.msg = 'null';
|
|
|
|
obj.status = item.status;
|
|
|
|
obj.snr = item.snr;
|
2022-06-07 09:31:59 +00:00
|
|
|
obj.type = 'ping';
|
|
|
|
obj.filename = 'null';
|
|
|
|
obj.filetype = 'null';
|
|
|
|
obj.file = 'null';
|
|
|
|
|
|
|
|
add_obj_to_database(obj)
|
|
|
|
update_chat_obj_by_uuid(obj.uuid);
|
2022-03-29 20:24:35 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
// handle beacon
|
2022-06-07 08:08:15 +00:00
|
|
|
} else if (item.beacon == 'received') {
|
2022-03-24 19:49:13 +00:00
|
|
|
obj.timestamp = item.timestamp;
|
|
|
|
obj.dxcallsign = item.dxcallsign;
|
|
|
|
obj.dxgrid = item.dxgrid;
|
|
|
|
obj.uuid = item.uuid;
|
|
|
|
obj.command = 'beacon';
|
|
|
|
obj.checksum = 'null';
|
|
|
|
obj.msg = 'null';
|
|
|
|
obj.status = item.status;
|
|
|
|
obj.snr = item.snr;
|
2022-06-07 08:08:15 +00:00
|
|
|
obj.type = 'beacon';
|
2022-06-07 09:31:59 +00:00
|
|
|
obj.filename = 'null';
|
|
|
|
obj.filetype = 'null';
|
|
|
|
obj.file = 'null';
|
|
|
|
|
|
|
|
add_obj_to_database(obj);
|
|
|
|
update_chat_obj_by_uuid(obj.uuid);
|
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
|
|
|
|
// handle ARQ transmission
|
2022-06-09 12:11:39 +00:00
|
|
|
} else if (item.arq == 'transmission' && item.status == 'received') {
|
2022-03-24 19:49:13 +00:00
|
|
|
var encoded_data = atob(item.data);
|
|
|
|
var splitted_data = encoded_data.split(split_char);
|
|
|
|
obj.timestamp = item.timestamp;
|
|
|
|
obj.dxcallsign = item.dxcallsign;
|
|
|
|
obj.dxgrid = item.dxgrid;
|
|
|
|
obj.command = splitted_data[1];
|
|
|
|
obj.checksum = splitted_data[2];
|
|
|
|
// convert message to unicode from utf8 because of emojis
|
|
|
|
obj.uuid = utf8.decode(splitted_data[3]);
|
|
|
|
obj.msg = utf8.decode(splitted_data[4]);
|
|
|
|
obj.status = 'null';
|
|
|
|
obj.snr = 'null';
|
|
|
|
obj.type = 'received';
|
|
|
|
obj.filename = utf8.decode(splitted_data[5]);
|
|
|
|
obj.filetype = utf8.decode(splitted_data[6]);
|
2022-03-27 19:04:04 +00:00
|
|
|
obj.file = btoa(utf8.decode(splitted_data[7]));
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
add_obj_to_database(obj);
|
|
|
|
update_chat_obj_by_uuid(obj.uuid);
|
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
}
|
|
|
|
});
|
2022-03-29 20:24:35 +00:00
|
|
|
//window.location = window.location;
|
2022-03-10 20:29:30 +00:00
|
|
|
});
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
// Update chat list
|
|
|
|
update_chat = function(obj) {
|
2022-03-24 19:49:13 +00:00
|
|
|
var dxcallsign = obj.dxcallsign;
|
|
|
|
var timestamp = dateFormat.format(obj.timestamp * 1000);
|
|
|
|
var timestampShort = dateFormatShort.format(obj.timestamp * 1000);
|
2022-04-02 16:40:12 +00:00
|
|
|
var timestampHours = dateFormatHours.format(obj.timestamp * 1000);
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
var dxgrid = obj.dxgrid;
|
2022-04-02 16:40:12 +00:00
|
|
|
|
|
|
|
// define shortmessage
|
|
|
|
if (obj.msg == 'null' || obj.msg == 'NULL'){
|
|
|
|
var shortmsg = obj.type;
|
|
|
|
} else {
|
|
|
|
var shortmsg = obj.msg;
|
2022-06-09 19:31:12 +00:00
|
|
|
var maxlength = 30;
|
2022-04-02 16:40:12 +00:00
|
|
|
var shortmsg = shortmsg.length > maxlength ? shortmsg.substring(0, maxlength - 3) + "..." : shortmsg;
|
2022-04-08 09:35:13 +00:00
|
|
|
|
2022-04-02 16:40:12 +00:00
|
|
|
}
|
2022-03-29 20:24:35 +00:00
|
|
|
try {
|
2022-06-07 09:31:59 +00:00
|
|
|
//console.log(Object.keys(obj._attachments)[0].length)
|
2022-03-29 20:24:35 +00:00
|
|
|
if (typeof(obj._attachments) !== 'undefined' && Object.keys(obj._attachments)[0].length > 0) {
|
|
|
|
//var filename = obj._attachments;
|
|
|
|
var filename = Object.keys(obj._attachments)[0]
|
|
|
|
var filetype = filename.split('.')[1]
|
|
|
|
var filesize = obj._attachments[filename]["length"] + " Bytes";
|
2022-04-10 09:37:09 +00:00
|
|
|
|
2022-03-29 20:24:35 +00:00
|
|
|
var fileheader = `
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="card-header border-0 bg-transparent text-end p-0 mb-0 hover-overlay">
|
2022-03-24 19:49:13 +00:00
|
|
|
<p class="text-right mb-0 p-1 text-black" style="text-align: right; font-size : 1rem">
|
2022-04-10 09:37:09 +00:00
|
|
|
<span class="p-1" style="text-align: right; font-size : 0.8rem">${filename}</span>
|
|
|
|
<span class="p-1" style="text-align: right; font-size : 0.8rem">${filesize}</span>
|
|
|
|
<i class="bi bi-filetype-${filetype}" style="font-size: 2rem;"></i>
|
2022-03-24 19:49:13 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2022-04-10 09:37:09 +00:00
|
|
|
<hr class="m-0 p-0">
|
|
|
|
`;
|
|
|
|
|
|
|
|
var controlarea_transmit = `
|
|
|
|
<div class="ms-auto" id="msg-${obj._id}-control-area">
|
|
|
|
<button class="btn bg-transparent p-1 m-1"><i class="bi bi-arrow-repeat" id="retransmit-msg-${obj._id}" style="font-size: 1.2rem; color: grey;"></i></button>
|
|
|
|
<button class="btn bg-transparent p-1 m-1"><i class="bi bi-download" id="save-file-msg-${obj._id}" style="font-size: 1.2rem; color: grey;"></i></button>
|
|
|
|
</div>
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
`;
|
2022-04-10 09:37:09 +00:00
|
|
|
|
|
|
|
var controlarea_receive = `
|
|
|
|
|
|
|
|
<div class="me-auto" id="msg-${obj._id}-control-area">
|
|
|
|
<button class="btn bg-transparent p-1 m-1"><i class="bi bi-download" id="save-file-msg-${obj._id}" style="font-size: 1.2rem; color: grey;"></i></button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
2022-03-29 20:24:35 +00:00
|
|
|
} else {
|
2022-04-06 08:15:14 +00:00
|
|
|
var filename = '';
|
|
|
|
var fileheader = '';
|
2022-06-09 12:54:42 +00:00
|
|
|
var filetype = 'text/plain';
|
2022-04-10 09:37:09 +00:00
|
|
|
var controlarea_transmit = `
|
|
|
|
<div class="ms-auto" id="msg-${obj._id}-control-area">
|
|
|
|
<button class="btn bg-transparent p-1 m-1"><i class="bi bi-arrow-repeat" id="retransmit-msg-${obj._id}" style="font-size: 1.2rem; color: grey;"></i></button>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
var controlarea_receive = '';
|
2022-03-29 20:24:35 +00:00
|
|
|
}
|
2022-05-20 09:12:22 +00:00
|
|
|
} catch (err) {
|
2022-03-27 19:04:04 +00:00
|
|
|
console.log("error with database parsing...")
|
2022-05-20 09:12:22 +00:00
|
|
|
console.log(err)
|
2022-03-27 19:04:04 +00:00
|
|
|
}
|
2022-03-10 20:29:30 +00:00
|
|
|
// CALLSIGN LIST
|
2022-03-24 19:49:13 +00:00
|
|
|
if (!(document.getElementById('chat-' + dxcallsign + '-list'))) {
|
2022-03-29 15:42:54 +00:00
|
|
|
// increment callsign counter
|
|
|
|
callsign_counter++;
|
2022-03-29 20:24:35 +00:00
|
|
|
if (callsign_counter == 1) {
|
2022-03-29 15:42:54 +00:00
|
|
|
var callsign_selected = 'active show'
|
2022-04-02 12:54:43 +00:00
|
|
|
//document.getElementById('chatModuleDxCall').value = dxcallsign;
|
2022-03-29 20:24:35 +00:00
|
|
|
selected_callsign = dxcallsign;
|
2022-03-29 15:42:54 +00:00
|
|
|
}
|
2022-04-08 09:35:13 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
var new_callsign = `
|
2022-03-29 15:42:54 +00:00
|
|
|
<a class="list-group-item list-group-item-action rounded-4 rounded-top rounded-bottom border-1 mb-2 ${callsign_selected}" id="chat-${dxcallsign}-list" data-bs-toggle="list" href="#chat-${dxcallsign}" role="tab" aria-controls="chat-${dxcallsign}">
|
2022-04-02 12:54:43 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
<div class="d-flex w-100 justify-content-between">
|
2022-04-02 12:54:43 +00:00
|
|
|
<div class="rounded-circle p-0">
|
|
|
|
<i class="bi bi-person-circle p-1" style="font-size:2rem;"></i>
|
|
|
|
</div>
|
2022-04-02 16:40:12 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
<h5 class="mb-1">${dxcallsign}</h5>
|
2022-04-02 16:40:12 +00:00
|
|
|
<span class="badge bg-secondary text-white p-1 h-100" id="chat-${dxcallsign}-list-dxgrid"><small>${dxgrid}</small></span>
|
|
|
|
<span style="font-size:0.8rem;" id="chat-${dxcallsign}-list-time">${timestampHours}</span>
|
|
|
|
<span class="position-absolute m-2 bottom-0 end-0" style="font-size:0.8rem;" id="chat-${dxcallsign}-list-shortmsg">${shortmsg}</span>
|
2022-03-10 20:29:30 +00:00
|
|
|
</div>
|
2022-04-02 16:40:12 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
</a>
|
2021-11-19 17:49:36 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
`;
|
|
|
|
document.getElementById('list-tab').insertAdjacentHTML("beforeend", new_callsign);
|
|
|
|
var message_area = `
|
2022-03-29 15:42:54 +00:00
|
|
|
<div class="tab-pane fade ${callsign_selected}" id="chat-${dxcallsign}" role="tabpanel" aria-labelledby="chat-${dxcallsign}-list"></div>
|
2022-03-10 20:29:30 +00:00
|
|
|
`;
|
2022-03-24 19:49:13 +00:00
|
|
|
document.getElementById('nav-tabContent').insertAdjacentHTML("beforeend", message_area);
|
2022-03-10 20:29:30 +00:00
|
|
|
// create eventlistener for listening on clicking on a callsign
|
|
|
|
document.getElementById('chat-' + dxcallsign + '-list').addEventListener('click', function() {
|
2022-04-02 12:54:43 +00:00
|
|
|
//document.getElementById('chatModuleDxCall').value = dxcallsign;
|
2022-03-29 20:24:35 +00:00
|
|
|
selected_callsign = dxcallsign;
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-12 14:06:49 +00:00
|
|
|
// scroll to bottom
|
|
|
|
var element = document.getElementById("message-container");
|
2022-06-07 09:31:59 +00:00
|
|
|
//console.log(element.scrollHeight)
|
2022-03-24 19:49:13 +00:00
|
|
|
element.scrollTo(0, element.scrollHeight);
|
2022-04-07 09:19:29 +00:00
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
});
|
2022-04-02 16:40:12 +00:00
|
|
|
|
|
|
|
// if callsign entry already exists - update
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// gridsquare - update only on receive
|
|
|
|
if (obj.type !== 'transmit'){
|
|
|
|
document.getElementById('chat-' + dxcallsign +'-list-dxgrid').innerHTML = dxgrid;
|
|
|
|
}
|
|
|
|
// time
|
|
|
|
document.getElementById('chat-' + dxcallsign +'-list-time').innerHTML = timestampHours;
|
|
|
|
// short message
|
|
|
|
document.getElementById('chat-' + dxcallsign +'-list-shortmsg').innerHTML = shortmsg;
|
|
|
|
|
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
}
|
|
|
|
// APPEND MESSAGES TO CALLSIGN
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
if (!(document.getElementById('msg-' + obj._id))) {
|
|
|
|
if (obj.type == 'ping') {
|
|
|
|
var new_message = `
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="m-auto mt-1 p-0 w-50 rounded bg-secondary bg-gradient" id="msg-${obj._id}">
|
|
|
|
<p class="text-small text-white mb-0 text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-arrow-left-right"></i>snr: ${obj.snr} - ${timestamp} </p>
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
if (obj.type == 'beacon') {
|
|
|
|
var new_message = `
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="p-0 rounded m-auto mt-1 w-50 bg-info bg-gradient" id="msg-${obj._id}">
|
|
|
|
<p class="text-small text-white text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-broadcast"></i>snr: ${obj.snr} - ${timestamp} </p>
|
2022-03-24 19:49:13 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2022-04-02 12:54:43 +00:00
|
|
|
|
|
|
|
if (obj.type == 'newchat') {
|
|
|
|
var new_message = `
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="p-0 rounded m-auto mt-1 w-50 bg-light bg-gradient" id="msg-${obj._id}">
|
2022-04-10 17:20:58 +00:00
|
|
|
<p class="text-small text-dark text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-file-earmark-plus"></i> new chat opened - ${timestamp} </p>
|
2022-04-02 12:54:43 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-03 13:26:24 +00:00
|
|
|
// CHECK FOR NEW LINE AND REPLACE WITH <br>
|
2022-04-06 08:15:14 +00:00
|
|
|
var message_html = obj.msg.replaceAll(/\n/g, "<br>");
|
2022-04-02 12:54:43 +00:00
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
if (obj.type == 'received') {
|
2022-03-10 20:29:30 +00:00
|
|
|
var new_message = `
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="d-flex align-items-center" style="margin-left: auto;"> <!-- max-width: 75%; -->
|
|
|
|
|
|
|
|
<div class="mt-3 rounded-3 mb-0" style="max-width: 75%;" id="msg-${obj._id}">
|
2022-03-24 19:49:13 +00:00
|
|
|
<!--<p class="font-monospace text-small mb-0 text-muted text-break">${timestamp}</p>-->
|
2022-03-12 14:06:49 +00:00
|
|
|
<div class="card border-light bg-light" id="msg-${obj._id}">
|
2022-03-24 19:49:13 +00:00
|
|
|
${fileheader}
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
<div class="card-body p-0">
|
2022-04-03 13:26:24 +00:00
|
|
|
<p class="card-text p-2 mb-0 text-break text-wrap">${message_html}</p>
|
2022-03-24 19:49:13 +00:00
|
|
|
<p class="text-right mb-0 p-1 text-white" style="text-align: left; font-size : 0.9rem">
|
|
|
|
<span class="badge bg-light text-muted">${timestamp}</span>
|
|
|
|
|
|
|
|
</p>
|
2022-03-12 14:06:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-10 09:37:09 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${controlarea_receive}
|
|
|
|
|
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
if (obj.type == 'transmit') {
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-06-07 09:31:59 +00:00
|
|
|
//console.log('msg-' + obj._id + '-status')
|
|
|
|
|
|
|
|
if (obj.status == 'failed'){
|
|
|
|
var progressbar_bg = 'bg-danger';
|
|
|
|
} else {
|
|
|
|
var progressbar_bg = 'bg-primary';
|
|
|
|
}
|
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
var new_message = `
|
2022-04-10 09:37:09 +00:00
|
|
|
|
|
|
|
<div class="d-flex align-items-center"> <!-- max-width: 75%; w-75 -->
|
|
|
|
|
|
|
|
${controlarea_transmit}
|
|
|
|
|
|
|
|
<div class="rounded-3 mt-2 mb-0" style="max-width: 75%;" > <!-- w-100 style="margin-left: auto;"-->
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
<!--<p class="font-monospace text-right mb-0 text-muted" style="text-align: right;">${timestamp}</p>-->
|
2022-04-10 09:37:09 +00:00
|
|
|
<div class="card border-primary bg-primary" id="msg-${obj._id}">
|
2022-03-24 19:49:13 +00:00
|
|
|
${fileheader}
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
<div class="card-body p-0 text-right bg-primary">
|
2022-04-10 09:37:09 +00:00
|
|
|
<p class="card-text p-1 mb-0 text-white text-break text-wrap">${message_html}</p>
|
2022-03-24 19:49:13 +00:00
|
|
|
<p class="text-right mb-0 p-1 text-white" style="text-align: right; font-size : 0.9rem">
|
2022-04-07 09:19:29 +00:00
|
|
|
<span class="text-light" style="font-size: 0.7rem;">${timestamp} - </span>
|
2022-04-10 09:37:09 +00:00
|
|
|
|
2022-04-07 09:19:29 +00:00
|
|
|
<span class="text-white" id="msg-${obj._id}-status" style="font-size:0.8rem;">${get_icon_for_state(obj.status)}</span>
|
2022-03-24 19:49:13 +00:00
|
|
|
|
2022-04-10 09:37:09 +00:00
|
|
|
<!--<button type="button" id="retransmit-msg-${obj._id}" class="btn btn-sm btn-light p-0" style="height:20px;width:30px"><i class="bi bi-arrow-repeat" style="font-size: 0.9rem; color: black;"></i></button>-->
|
2022-03-24 19:49:13 +00:00
|
|
|
|
|
|
|
</p>
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-05-01 08:55:56 +00:00
|
|
|
<div class="progress p-0 m-0 rounded-0 rounded-bottom bg-secondary" style="height: 10px;">
|
|
|
|
<div class="progress-bar progress-bar-striped ${progressbar_bg} p-0 m-0 rounded-0" id="msg-${obj._id}-progress" role="progressbar" style="width: ${obj.percent}%;" aria-valuenow="${obj.percent}" aria-valuemin="0" aria-valuemax="100">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p class="justify-content-center d-flex position-absolute m-0 p-0 w-100 text-white" style="font-size: xx-small" id="msg-${obj._id}-progress-information">
|
|
|
|
${obj.percent} % - ${obj.bytesperminute} Bpm
|
|
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-07 09:19:29 +00:00
|
|
|
</div>
|
2022-03-12 14:06:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-24 19:49:13 +00:00
|
|
|
|
2022-03-10 20:29:30 +00:00
|
|
|
</div>
|
2022-04-10 09:37:09 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
// CHECK CHECK CHECK --> This could be done better
|
|
|
|
var id = "chat-" + obj.dxcallsign
|
|
|
|
document.getElementById(id).insertAdjacentHTML("beforeend", new_message);
|
2022-04-02 12:54:43 +00:00
|
|
|
|
2022-06-09 19:42:20 +00:00
|
|
|
//var element = document.getElementById("message-container");
|
2022-06-07 09:31:59 +00:00
|
|
|
//console.log(element.scrollHeight)
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-06-09 12:11:39 +00:00
|
|
|
/* UPDATE EXISTING ELEMENTS */
|
2022-03-24 19:49:13 +00:00
|
|
|
} else if (document.getElementById('msg-' + obj._id)) {
|
2022-04-06 08:15:14 +00:00
|
|
|
console.log("element already exists......")
|
2022-04-07 09:19:29 +00:00
|
|
|
console.log(obj)
|
|
|
|
|
2022-06-09 12:11:39 +00:00
|
|
|
console.log(document.getElementById('msg-' + obj._id + '-progress').getAttribute("aria-valuenow"))
|
2022-04-07 09:19:29 +00:00
|
|
|
|
|
|
|
document.getElementById('msg-' + obj._id + '-status').innerHTML = get_icon_for_state(obj.status);
|
2022-04-08 09:35:13 +00:00
|
|
|
|
2022-04-07 09:19:29 +00:00
|
|
|
document.getElementById('msg-' + obj._id + '-progress').setAttribute("aria-valuenow", obj.percent);
|
|
|
|
document.getElementById('msg-' + obj._id + '-progress').setAttribute("style", "width:" + obj.percent + "%;");
|
2022-05-01 08:55:56 +00:00
|
|
|
document.getElementById('msg-' + obj._id + '-progress-information').innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm";
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-04-07 09:19:29 +00:00
|
|
|
if (obj.percent >= 100){
|
2022-06-09 12:11:39 +00:00
|
|
|
//document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped");
|
2022-04-07 09:19:29 +00:00
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-animated");
|
2022-04-08 09:35:13 +00:00
|
|
|
document.getElementById('msg-' + obj._id + '-progress').innerHTML = '';
|
2022-04-07 09:19:29 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.add("progress-bar-striped");
|
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.add("progress-bar-animated");
|
|
|
|
}
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-05-01 08:55:56 +00:00
|
|
|
if (obj.status == 'failed'){
|
2022-06-09 12:54:42 +00:00
|
|
|
//document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped");
|
2022-05-01 08:55:56 +00:00
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-animated");
|
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.remove("bg-primary");
|
|
|
|
document.getElementById('msg-' + obj._id + '-progress').classList.add("bg-danger");
|
|
|
|
}
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-04-06 08:15:14 +00:00
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
//document.getElementById(id).className = message_class;
|
|
|
|
}
|
2022-04-10 09:37:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
// CREATE SAVE TO FOLDER EVENT LISTENER
|
2022-04-02 12:54:43 +00:00
|
|
|
if (document.getElementById('save-file-msg-' + obj._id) && !document.getElementById('save-file-msg-' + obj._id).hasAttribute('listenerOnClick')) {
|
|
|
|
|
|
|
|
// set Attribute to determine if we already created an EventListener for this element
|
|
|
|
document.getElementById('save-file-msg-' + obj._id).setAttribute('listenerOnClick', 'true');
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
document.getElementById('save-file-msg-' + obj._id).addEventListener("click", () => {
|
2022-03-27 19:04:04 +00:00
|
|
|
saveFileToFolder(obj._id)
|
|
|
|
});
|
2022-04-10 09:37:09 +00:00
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
}
|
|
|
|
// CREATE RESEND MSG EVENT LISTENER
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-29 20:24:35 +00:00
|
|
|
// check if element exists and if we already created NOT created an event listener
|
|
|
|
if (document.getElementById('retransmit-msg-' + obj._id) && !document.getElementById('retransmit-msg-' + obj._id).hasAttribute('listenerOnClick')) {
|
|
|
|
|
2022-04-07 09:19:29 +00:00
|
|
|
// set Attribute to determine if we already created an EventListener for this element
|
|
|
|
document.getElementById('retransmit-msg-' + obj._id).setAttribute('listenerOnClick', 'true');
|
2022-03-24 19:49:13 +00:00
|
|
|
document.getElementById('retransmit-msg-' + obj._id).addEventListener("click", () => {
|
2022-04-07 09:19:29 +00:00
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
db.get(obj._id, {
|
|
|
|
attachments: true
|
|
|
|
}).then(function(doc) {
|
|
|
|
// handle doc
|
|
|
|
console.log(doc)
|
2022-04-06 08:15:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-24 19:49:13 +00:00
|
|
|
var filename = Object.keys(obj._attachments)[0]
|
2022-04-06 08:15:14 +00:00
|
|
|
var filetype = filename.content_type
|
|
|
|
|
|
|
|
console.log(filename)
|
|
|
|
console.log(filetype)
|
|
|
|
var file = obj._attachments[filename].data
|
|
|
|
console.log(file)
|
|
|
|
console.log(Object.keys(obj._attachments)[0].data)
|
|
|
|
|
2022-03-27 19:04:04 +00:00
|
|
|
//var file = atob(obj._attachments[filename]["data"])
|
2022-03-29 20:24:35 +00:00
|
|
|
db.getAttachment(obj._id, filename).then(function(data) {
|
2022-04-06 08:15:14 +00:00
|
|
|
|
|
|
|
var file = blobUtil.arrayBufferToBinaryString(data)
|
|
|
|
|
|
|
|
// converting back to blob for debugging
|
|
|
|
// length must be equal of file size
|
|
|
|
var blob = blobUtil.binaryStringToBlob(file);
|
|
|
|
console.log(blob)
|
|
|
|
|
|
|
|
|
2022-03-29 20:24:35 +00:00
|
|
|
var data_with_attachment = doc.msg + split_char + filename + split_char + filetype + split_char + file;
|
|
|
|
let Data = {
|
|
|
|
command: "send_message",
|
|
|
|
dxcallsign: doc.dxcallsign,
|
|
|
|
mode: 255,
|
|
|
|
frames: 1,
|
|
|
|
data: data_with_attachment,
|
|
|
|
checksum: doc.checksum,
|
|
|
|
uuid: doc.uuid
|
|
|
|
};
|
|
|
|
console.log(Data)
|
2022-04-06 08:15:14 +00:00
|
|
|
ipcRenderer.send('run-tnc-command', Data);
|
|
|
|
|
2022-03-27 19:04:04 +00:00
|
|
|
});
|
2022-03-24 19:49:13 +00:00
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
});
|
2022-03-29 20:24:35 +00:00
|
|
|
|
2022-06-15 12:34:17 +00:00
|
|
|
}
|
2022-03-29 20:24:35 +00:00
|
|
|
//window.location = window.location
|
2022-03-24 19:49:13 +00:00
|
|
|
}
|
2022-03-10 20:29:30 +00:00
|
|
|
|
2022-06-07 09:31:59 +00:00
|
|
|
|
2022-03-14 19:21:15 +00:00
|
|
|
|
2022-03-27 19:04:04 +00:00
|
|
|
function saveFileToFolder(id) {
|
2022-03-29 20:24:35 +00:00
|
|
|
db.get(id, {
|
|
|
|
attachments: true
|
|
|
|
}).then(function(obj) {
|
2022-03-24 19:49:13 +00:00
|
|
|
console.log(obj)
|
|
|
|
console.log(Object.keys(obj._attachments)[0].content_type)
|
|
|
|
var filename = Object.keys(obj._attachments)[0]
|
|
|
|
var filetype = filename.content_type
|
2022-03-27 19:04:04 +00:00
|
|
|
var file = filename.data
|
|
|
|
console.log(file)
|
|
|
|
console.log(filename.data)
|
2022-03-29 20:24:35 +00:00
|
|
|
db.getAttachment(id, filename).then(function(data) {
|
|
|
|
// handle result
|
|
|
|
console.log(data.length)
|
|
|
|
//data = new Blob([data.buffer], { type: 'image/png' } /* (1) */)
|
|
|
|
console.log(data)
|
|
|
|
let Data = {
|
|
|
|
file: data,
|
|
|
|
filename: filename,
|
|
|
|
filetype: filetype,
|
|
|
|
}
|
|
|
|
console.log(Data)
|
|
|
|
ipcRenderer.send('save-file-to-folder', Data);
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
return false
|
|
|
|
});
|
2022-03-24 19:49:13 +00:00
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}
|
2022-04-07 09:19:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
// function for setting an ICON to the correspinding state
|
|
|
|
function get_icon_for_state(state) {
|
|
|
|
if (state == 'transmit') {
|
|
|
|
var status_icon = '<i class="bi bi-check" style="font-size:1rem;"></i>';
|
|
|
|
} else if (state == 'transmitting') {
|
2022-06-09 12:11:39 +00:00
|
|
|
//var status_icon = '<i class="bi bi-arrow-left-right" style="font-size:0.8rem;"></i>';
|
|
|
|
var status_icon = `
|
|
|
|
<i class="spinner-border ms-auto" style="width: 0.8rem; height: 0.8rem;" role="status" aria-hidden="true"></i>
|
|
|
|
`;
|
2022-04-07 09:19:29 +00:00
|
|
|
} else if (state == 'failed') {
|
|
|
|
var status_icon = '<i class="bi bi-exclamation-circle" style="font-size:1rem;"></i>';
|
2022-06-09 12:11:39 +00:00
|
|
|
} else if (state == 'transmitted') {
|
2022-04-07 09:19:29 +00:00
|
|
|
var status_icon = '<i class="bi bi-check-all" style="font-size:1rem;"></i>';
|
|
|
|
} else {
|
|
|
|
var status_icon = '<i class="bi bi-question" style="font-size:1rem;"></i>';
|
|
|
|
}
|
|
|
|
return status_icon;
|
2022-06-15 12:34:17 +00:00
|
|
|
}
|
2022-06-07 09:31:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_chat_obj_by_uuid = function(uuid) {
|
|
|
|
db.get(uuid, {
|
|
|
|
attachments: true
|
|
|
|
}).then(function(doc) {
|
|
|
|
update_chat(doc)
|
|
|
|
//return doc
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
add_obj_to_database = function(obj){
|
|
|
|
db.put({
|
|
|
|
_id: obj.uuid,
|
|
|
|
timestamp: obj.timestamp,
|
|
|
|
uuid: obj.uuid,
|
|
|
|
dxcallsign: obj.dxcallsign,
|
|
|
|
dxgrid: obj.dxgrid,
|
|
|
|
msg: obj.msg,
|
|
|
|
checksum: obj.checksum,
|
|
|
|
type: obj.type,
|
|
|
|
command: obj.command,
|
|
|
|
status: obj.status,
|
|
|
|
snr: obj.snr,
|
|
|
|
_attachments: {
|
|
|
|
[obj.filename]: {
|
|
|
|
content_type: obj.filetype,
|
|
|
|
data: obj.file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).then(function(response) {
|
|
|
|
console.log("new database entry");
|
|
|
|
console.log(response);
|
|
|
|
}).catch(function(err) {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}
|