Merge pull request #1 from status-im/direct-messages
/msg function to send direct messages
This commit is contained in:
commit
a34ed2a3fd
24
src/index.js
24
src/index.js
|
@ -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);
|
||||
|
|
12
src/ui.js
12
src/ui.js
|
@ -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"
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue