diff --git a/CHANGELOG.md b/CHANGELOG.md index e841c2b..7a1d7ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Pre-releases +## v0.2.0 + +- Add direct message support with `@KC3LZO` ([#2](https://github.com/brannondorsey/chattervox/issues/2)) +- Remove `test/Messenger.test.js` + ## v0.1.0 - Add ssid support. diff --git a/package.json b/package.json index ce1ee43..690fd34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chattervox", - "version": "0.1.0", + "version": "0.2.0", "description": "An AX.25 packet radio chat protocol with support for digital signatures and binary compression. Like IRC over radio waves 📡〰.", "main": "build/main.js", "bin": { diff --git a/src/Messenger.ts b/src/Messenger.ts index 04c2f68..43159c9 100644 --- a/src/Messenger.ts +++ b/src/Messenger.ts @@ -112,8 +112,8 @@ export class Messenger extends EventEmitter { } const event: MessageEvent = { - to: packet.to, - from: packet.from, + to: { callsign: packet.to.callsign.trim(), ssid: packet.to.ssid }, + from: { callsign: packet.from.callsign.trim(), ssid: packet.from.ssid }, message: packet.message, verification } diff --git a/src/subcommands/chat.ts b/src/subcommands/chat.ts index b71d591..9d78c18 100644 --- a/src/subcommands/chat.ts +++ b/src/subcommands/chat.ts @@ -19,7 +19,11 @@ export async function main(args: any, conf: Config, ks: Keystore): Promise { - ui.printReceivedMessage(message, conf.callsign) + if (message.to.callsign === 'CQ' || + (message.to.callsign === conf.callsign && + message.to.ssid === conf.ssid)) { + ui.printReceivedMessage(message, conf.callsign) + } }) try { diff --git a/src/ui/chat.ts b/src/ui/chat.ts index 0f6fd79..a8156ca 100644 --- a/src/ui/chat.ts +++ b/src/ui/chat.ts @@ -1,7 +1,7 @@ import { terminal as term } from 'terminal-kit' import { Messenger, MessageEvent, Verification } from '../Messenger'; -import { stationToCallsignSSID } from '../utils' +import { stationToCallsignSSID, isCallsign, isCallsignSSID } from '../utils' term.on('key', (name: string , matches: string[], data: any): void => { if ( matches.includes('CTRL_C') || matches.includes('CTRL_D')) { @@ -66,9 +66,16 @@ export async function printReceivedMessage(message: MessageEvent, callsign: stri export async function inputLoop(callsign: string, messenger: Messenger, sign: boolean): Promise { while (true) { const text = (await prompt(callsign)).trim() - // TODO dynamic to addresses, not just CQ. "TOCALL: message" should only - // be sent appear to specific user. - if (text !== '') await messenger.send('CQ', text, sign) + if (text !== '') { + let to = 'CQ' + if (text.startsWith('@')) { + const space = text.indexOf(' ') + const callsign = space === -1 ? text.slice(1) : text.slice(1, space) + if (isCallsign(callsign) || isCallsignSSID(callsign)) + to = callsign.toUpperCase() + } + await messenger.send(to, text, sign) + } term.eraseLine() const pos: { x: number, y: number } = await term.getCursorLocation() term.moveTo(0, pos.y) diff --git a/test/Messenger.test.js b/test/Messenger.test.js deleted file mode 100644 index 230e87e..0000000 --- a/test/Messenger.test.js +++ /dev/null @@ -1,55 +0,0 @@ -const { Messenger, Verification } = require('../build/Messenger.js') -const { Config, load } = require('../build/config.js') - -async function main() { - - const conf = load() - const messenger = new Messenger(conf) - - messenger.on('open', (err) => { - if (err) { - console.log('Error opening tnc connection') - } else { - console.log('Messenger\'s tnc is open') - } - }) - - messenger.on('close', () => { - console.log('Messenger\'s tnc is now closed') - setTimeout(async () => { - await messenger.openTNC() - await messenger.send('CQ', 'This is a second message that was sent after the tnc was first closed.') - }, 10 * 1000) - }) - - messenger.on('tnc-error', (err) => { - console.log('Messenger\'s TNC experienced an error:') - console.error(err) - }) - - messenger.on('message', (to, from, message, verification) => { - console.log('message received!') - console.log(`to: ${to}`) - console.log(`from: ${from}`) - console.log(`message: ${message}`) - console.log(`verified: ${verification == Verification.Valid}`) - }) - - messenger.openTNC() - .then( - () => sendMessage(messenger), - () => { console.log('Error opening TNC connection message') } - ) - -} - -async function sendMessage(messenger) { - - await messenger.send('CQ', 'This message is a zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz test baby!', true) - // messenger.closeTNC() - // await messenger.send('CQ', 'This message is a zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz test baby!') - - setTimeout(()=>{}, 100000) -} - -main().catch(console.error) \ No newline at end of file