Skip to content

Commit

Permalink
Add direct messaging. Close #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
brannondorsey committed Sep 20, 2018
1 parent c871206 commit dcde390
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion src/subcommands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export async function main(args: any, conf: Config, ks: Keystore): Promise<numbe
})

messenger.on('message', (message: MessageEvent) => {
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 {
Expand Down
15 changes: 11 additions & 4 deletions src/ui/chat.ts
Original file line number Diff line number Diff line change
@@ -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')) {
Expand Down Expand Up @@ -66,9 +66,16 @@ export async function printReceivedMessage(message: MessageEvent, callsign: stri
export async function inputLoop(callsign: string, messenger: Messenger, sign: boolean): Promise<void> {
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)
Expand Down
55 changes: 0 additions & 55 deletions test/Messenger.test.js

This file was deleted.

0 comments on commit dcde390

Please sign in to comment.