/msg function to send direct messages
This commit is contained in:
parent
4c31d5307c
commit
5caadd4643
24
src/index.js
24
src/index.js
|
@ -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);
|
||||||
|
|
12
src/ui.js
12
src/ui.js
|
@ -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"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue