Merge pull request #1 from status-im/direct-messages

/msg function to send direct messages
This commit is contained in:
Iuri Matias 2018-11-08 11:32:03 -05:00 committed by GitHub
commit a34ed2a3fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'); var ChannelManager = require('./channelManager.js');
const DEFAULT_CHANNEL = "mytest"; const DEFAULT_CHANNEL = "mytest";
const CONTACT_CODE_REGEXP = /^(0x)?[0-9a-f]{130}$/i;
var ui = new UI(); var ui = new UI();
@ -179,6 +180,29 @@ ui.logEntry(`Rejoining Channels....`);
return; 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(); const channel = channels.getCurrentChannel();
if(channel.pubKey){ if(channel.pubKey){
status.sendMessage(channel.pubKey, cmd); status.sendMessage(channel.pubKey, cmd);

View File

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