From ec70cc8caaaf0072ddc49b1b3e5918c71efbe3f9 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 19 Aug 2015 22:10:18 -0600 Subject: [PATCH] * Progress on FSE / Area Posting * Proof of concept work on user validation in FSE * Term now has pipeWrite() --- core/client_term.js | 23 ++++++-------- core/connect.js | 11 ++++--- core/fse.js | 20 +++++++++++-- core/message.js | 6 +++- mods/art/msg_area_post_header.ans | Bin 582 -> 582 bytes mods/menu.json | 13 ++++++-- mods/msg_area_list.js | 3 +- mods/msg_area_post_fse.js | 48 +++++++++++++++++++++++++++++- 8 files changed, 96 insertions(+), 28 deletions(-) diff --git a/core/client_term.js b/core/client_term.js index 445b5d35..0e67b6e4 100644 --- a/core/client_term.js +++ b/core/client_term.js @@ -2,11 +2,12 @@ 'use strict'; // ENiGMA½ -var Log = require('./logger.js').log; +var Log = require('./logger.js').log; +var enigmaToAnsi = require('./color_codes.js').enigmaToAnsi; -var iconv = require('iconv-lite'); -var assert = require('assert'); -var _ = require('lodash'); +var iconv = require('iconv-lite'); +var assert = require('assert'); +var _ = require('lodash'); iconv.extendNodeEncodings(); @@ -126,16 +127,6 @@ ClientTerminal.prototype.isANSI = function() { return [ 'ansi', 'pc-ansi', 'qansi', 'scoansi' ].indexOf(this.termType) > -1; }; -/* -ClientTerminal.prototype.write = function(s, convertLineFeeds) { - convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds; - if(convertLineFeeds && _.isString(s)) { - s = s.replace(/\n/g, '\r\n'); - } - this.output.write(this.iconv.encode(s, this.outputEncoding)); -}; -*/ - // :TODO: probably need to update these to convert IAC (0xff) -> IACIAC (escape it) ClientTerminal.prototype.write = function(s, convertLineFeeds) { @@ -146,6 +137,10 @@ ClientTerminal.prototype.rawWrite = function(s) { this.output.write(s); }; +ClientTerminal.prototype.pipeWrite = function(s) { + this.write(enigmaToAnsi(s)); +}; + ClientTerminal.prototype.encode = function(s, convertLineFeeds) { convertLineFeeds = _.isUndefined(convertLineFeeds) ? this.convertLF : convertLineFeeds; if(convertLineFeeds && _.isString(s)) { diff --git a/core/connect.js b/core/connect.js index c78b90ee..819919ed 100644 --- a/core/connect.js +++ b/core/connect.js @@ -2,7 +2,6 @@ 'use strict'; var ansi = require('./ansi_term.js'); -var colorCodes = require('./color_codes.js'); var theme = require('./theme.js'); var moduleUtil = require('./module_util.js'); var Config = require('./config.js').config; @@ -75,21 +74,21 @@ function ansiQueryTermSizeIfNeeded(client, cb) { }, 2000); // This causes - client.term.write(ansi.queryScreenSize()); + client.term.rawWrite(ansi.queryScreenSize()); } function prepareTerminal(term) { - term.write(ansi.normal()); - term.write(ansi.disableVT100LineWrapping()); + term.rawWrite(ansi.normal()); + term.rawWrite(ansi.disableVT100LineWrapping()); // :TODO: set xterm stuff -- see x84/others } function displayBanner(term) { // :TODO: add URL(s) to banner - term.write(colorCodes.pipeToAnsi(util.format( + term.pipeWrite(util.format( '|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' + '|00|33Copyright (c) 2014-2015 Bryan Ashby |33|01- |31|01http://l33t.codes/\n' + - '|00', packageJson.version))); + '|00', packageJson.version)); } function connectEntry(client) { diff --git a/core/fse.js b/core/fse.js index 260a71ba..cad93831 100644 --- a/core/fse.js +++ b/core/fse.js @@ -47,8 +47,9 @@ function FullScreenEditorModule(options) { this.messageAreaId = options.extraArgs.messageAreaId || Message.WellKnownAreaIds.Private; } - // netMail/crashMail | echoMail - //this.messageAreaId = 'netMail' === this.editorType ? Message.WellKnownAreaIds.Private : options.messageAreaId; + this.isLocalEmail = function() { + return 'email' === this.editorType && Message.WellKnownAreaIds.Private === this.messageAreaId; + }; this.getFooterName = function(editorMode) { editorMode = editorMode || this.editorMode; @@ -312,7 +313,18 @@ function FullScreenEditorModule(options) { this.mciReadyHandler = function(mciData) { self.createInitialViews(mciData, function viewsCreated(err) { + self.viewControllers.header.on('leave', function headerViewLeave(view) { + if(2 === view.id) { // "to" field + self.validateToUserName(view.getData(), function result(err) { + if(err) { + // :TODO: display a error in a %TL area or such + view.clearText(); + self.viewControllers.headers.switchFocus(2); + } + }); + } + }); }); }; @@ -460,3 +472,7 @@ FullScreenEditorModule.prototype.mciReady = function(mciData) { //this['mciReadyHandler' + _.capitalize(this.editorType)](mciData); }; +FullScreenEditorModule.prototype.validateToUserName = function(un, cb) { + cb(null); // note: to be implemented by sub classes +}; + diff --git a/core/message.js b/core/message.js index ce44071f..41bd3e2f 100644 --- a/core/message.js +++ b/core/message.js @@ -37,7 +37,11 @@ function Message(options) { _.defaultsDeep(this.meta, options.meta); } - this.meta = options.meta || {}; + if(options.meta) { + this.meta = options.meta; + } + +// this.meta = options.meta || {}; this.hashTags = options.hashTags || []; var self = this; diff --git a/mods/art/msg_area_post_header.ans b/mods/art/msg_area_post_header.ans index 7ea3a56f768a74065c0e2433a438fe03b4dd65e1..3959d681b51beba46b7e84c66513b9434aed9209 100644 GIT binary patch delta 16 XcmX@ca*Snz3L~?xqv>XKMtMd6D{llV delta 16 XcmX@ca*Snz3L|rfkI80rMtMd6EA9k5 diff --git a/mods/menu.json b/mods/menu.json index 7efd7501..91323249 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -316,6 +316,7 @@ "messageAreaNewPost" : { "module" : "msg_area_post_fse", "options" : { "cls" : true }, + "fallback" : "messageArea", // :TODO: remove once default fallback is in place "config" : { "art" : { "header" : "msg_area_post_header", @@ -324,11 +325,12 @@ "footerEditMenu" : "demo_fse_netmail_footer_edit_menu.ans", "footerView" : "demo_fse_netmail_footer_view.ans", "help" : "demo_fse_netmail_help.ans" - } + }, + "editorType" : "area" }, "form" : { "0" : { - "ETETTLTL" : { + "ETETTL" : { "mci" : { "TL1" : { "width" : 36, @@ -345,10 +347,15 @@ "maxLength" : 72, "submit" : true }, - "TL4" : { + "MA5" : { "width" : 19, "textOverflow" : "..." } + /*, + "TL4" : { + "width" : 19, + "textOverflow" : "..." + }*/ }, "submit" : { "3" : [ diff --git a/mods/msg_area_list.js b/mods/msg_area_list.js index 1643825f..01ce02a5 100644 --- a/mods/msg_area_list.js +++ b/mods/msg_area_list.js @@ -36,9 +36,10 @@ function MessageAreaListModule(options) { changeArea : function(formData, extraArgs) { if(1 === formData.submitId) { var areaId = self.messageAreas[formData.value.area].areaId; + messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) { if(err) { - self.client.term.write('\nCannot change area: ' + err.message + '\n'); + self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n'); setTimeout(function timeout() { self.client.gotoMenuModule( { name : self.menuConfig.fallback } ); diff --git a/mods/msg_area_post_fse.js b/mods/msg_area_post_fse.js index ee4fc5a4..5ba85b86 100644 --- a/mods/msg_area_post_fse.js +++ b/mods/msg_area_post_fse.js @@ -3,8 +3,10 @@ var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule; var Message = require('../core/message.js').Message; +var user = require('../core/user.js'); var _ = require('lodash'); +var async = require('async'); exports.getModule = AreaPostFSEModule; @@ -24,7 +26,33 @@ function AreaPostFSEModule(options) { this.menuMethods.editModeMenuSave = function(formData, extraArgs) { var msg = self.getMessage(); - console.log(msg); + + async.series( + [ + function prepareMessage(callback) { + if(self.isLocalEmail()) { + msg.setLocalFromUserId(self.client.user.userId); + msg.setLocalToUserId(self.toUserId); + } + + callback(null); + }, + function saveMessage(callback) { + msg.persist(function persisted(err) { + callback(err); + }); + } + ], + function complete(err) { + if(err) { + // :TODO:... sooooo now what? + } else { + console.log(msg); + } + + self.client.gotoMenuModule( { name : self.menuConfig.fallback } ); + } + ); }; } @@ -40,4 +68,22 @@ AreaPostFSEModule.prototype.enter = function(client) { } AreaPostFSEModule.super_.prototype.enter.call(this, client); +}; + +AreaPostFSEModule.prototype.validateToUserName = function(un, cb) { + + console.log('bazinga') + + + var self = this; + + if(!self.isLocalEmail()) { + cb(null); + return; + } + + user.getUserIdAndName(un, function uidAndName(err, userId, userName) { + self.toUserId = userId; + cb(err); + }); }; \ No newline at end of file