/msg function to send direct messages

This commit is contained in:
Richard Ramos 2018-11-08 11:24:01 -04:00
parent 4c31d5307c
commit 5caadd4643
2 changed files with 30 additions and 6 deletions

View File

@ -3,6 +3,7 @@ var StatusJS = require('status-js-api');
var ChannelManager = require('./channelManager.js');
const DEFAULT_CHANNEL = "mytest";
const CONTACT_CODE_REGEXP = /^(0x)?[0-9a-f]{130}$/i;
var ui = new UI();
@ -179,6 +180,29 @@ ui.logEntry(`Rejoining Channels....`);
return;
}
if(cmd.split(' ')[0] === '/msg') {
let destination = cmd.substr(5);
if (!(CONTACT_CODE_REGEXP.test(destination) || /^[a-z0-9A-Z\s]{4,}$/.test(destination))) {
ui.logEntry(`Invalid account`.red);
return;
}
// TODO:resolve ens username
const user = Object.values(channels.allUsers.users).find(x => x.username == destination);
if(user){
channels.addChannel(user.username, 'contact', {pubKey: user.pubkey});
channels.switchChannelIndex(channels.channels.length - 1);
} else {
status.getUserName(destination).then(username => {
channels.addChannel(username, 'contact', {pubKey: destination});
channels.switchChannelIndex(channels.channels.length - 1);
});
}
return;
}
const channel = channels.getCurrentChannel();
if(channel.pubKey){
status.sendMessage(channel.pubKey, cmd);

View File

@ -74,9 +74,9 @@ class UI {
this.log = blessed.box({
label: "Logs",
padding: 1,
width: "73%",
width: "68%",
height: "92%",
left: "7%",
left: "12%",
top: "0%",
border: {
type: "line"
@ -152,7 +152,7 @@ class UI {
layoutChannels() {
this.wrapper = blessed.layout({
width: "7%",
width: "12%",
height: "100%",
top: "0%",
left: "0%",
@ -253,10 +253,10 @@ class UI {
layoutState() {
this.consoleStateContainer = blessed.layout({
width: '73%',
width: '68%',
height: '5%',
left: '7%',
top: '90%',
left: '12%',
top: '92%',
layout: "grid"
});