* Very early work on FidoNet, Messages, etc.
This commit is contained in:
parent
ab12974430
commit
5907c1d024
|
@ -23,11 +23,12 @@ function initializeDatabases() {
|
||||||
|
|
||||||
dbs.user.serialize(function serialized() {
|
dbs.user.serialize(function serialized() {
|
||||||
createUserTables();
|
createUserTables();
|
||||||
createInitialValues();
|
createInitialUserValues();
|
||||||
});
|
});
|
||||||
|
|
||||||
dbs.message.serialize(function serialized() {
|
dbs.message.serialize(function serialized() {
|
||||||
createMessageBaseTables();
|
createMessageBaseTables();
|
||||||
|
createInitialMessageValues();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +99,7 @@ function createMessageBaseTables() {
|
||||||
' subject,' + // FTS @ message_fts
|
' subject,' + // FTS @ message_fts
|
||||||
' message,' + // FTS @ message_fts
|
' message,' + // FTS @ message_fts
|
||||||
' modified_timestamp DATETIME NOT NULL,' +
|
' modified_timestamp DATETIME NOT NULL,' +
|
||||||
|
' view_count INTEGER NOT NULL DEFAULT 0,' +
|
||||||
' UNIQUE(message_uuid),' +
|
' UNIQUE(message_uuid),' +
|
||||||
' FOREIGN KEY(area_id) REFERENCES message_area(area_id)' +
|
' FOREIGN KEY(area_id) REFERENCES message_area(area_id)' +
|
||||||
');'
|
');'
|
||||||
|
@ -153,7 +155,17 @@ function createMessageBaseTables() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createInitialValues() {
|
function createInitialMessageValues() {
|
||||||
|
//
|
||||||
|
// Area ID 1: Private / Local
|
||||||
|
//
|
||||||
|
dbs.message.run(
|
||||||
|
'INSERT OR IGNORE INTO message_area ' +
|
||||||
|
'VALUES(1, "Local Private Messages");'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createInitialUserValues() {
|
||||||
dbs.user.run(
|
dbs.user.run(
|
||||||
'INSERT OR IGNORE INTO user_group ' +
|
'INSERT OR IGNORE INTO user_group ' +
|
||||||
'VALUES(1, "users");'
|
'VALUES(1, "users");'
|
||||||
|
|
109
core/message.js
109
core/message.js
|
@ -6,24 +6,27 @@ var msgDb = require('./database.js').dbs.message;
|
||||||
var uuid = require('node-uuid');
|
var uuid = require('node-uuid');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
exports.Message = Message;
|
||||||
|
|
||||||
function Message(options) {
|
function Message(options) {
|
||||||
|
|
||||||
|
this.messageId = options.messageId || 0; // always generated @ persist
|
||||||
|
this.areaId = options.areaId || Message.WellKnownAreaIds.Invalid; // 0 = invalid; 1 = private; Everything else is user defined
|
||||||
|
this.uuid = uuid.v1();
|
||||||
|
this.replyToMsgId = options.replyToMsgId || 0;
|
||||||
|
this.toUserName = options.toUserName || '';
|
||||||
|
this.fromUserName = options.fromUserName || '';
|
||||||
|
this.subject = options.subject || '';
|
||||||
|
this.message = options.message || '';
|
||||||
|
this.modTimestamp = options.modTimestamp || ''; // blank = set @ persist
|
||||||
|
this.viewCount = options.viewCount || 0;
|
||||||
|
this.meta = options.meta || {};
|
||||||
|
this.hashTags = options.hashTags || [];
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.fromExisting = function(opts) {
|
|
||||||
self.messageId = opts.messageId;
|
|
||||||
self.areaId = opts.areaId;
|
|
||||||
self.uuid = opts.uuid;
|
|
||||||
self.replyToMsgId = opts.replyToMsgId;
|
|
||||||
self.toUserName = opts.toUserName;
|
|
||||||
self.fromUserName = opts.fromUserName;
|
|
||||||
self.subject = opts.subject;
|
|
||||||
self.message = opts.message;
|
|
||||||
self.modTimestamp = opts.modTimestamp;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.isValid = function() {
|
this.isValid = function() {
|
||||||
// :TODO: validate as much as possible
|
// :TODO: validate as much as possible
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,8 +35,72 @@ function Message(options) {
|
||||||
this.createMessageTimestamp = function() {
|
this.createMessageTimestamp = function() {
|
||||||
return new Date().toISOString();
|
return new Date().toISOString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Object.defineProperty(this, 'messageId', {
|
||||||
|
get : function() {
|
||||||
|
return messageId;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'areaId', {
|
||||||
|
get : function() { return areaId; },
|
||||||
|
set : function(i) {
|
||||||
|
areaId = i;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message.WellKnownAreaIds = {
|
||||||
|
Invalid : 0,
|
||||||
|
Private : 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.MetaNames = {
|
||||||
|
//
|
||||||
|
// FidoNet: http://ftsc.org/docs/fts-0001.016
|
||||||
|
//
|
||||||
|
FidoNetCost : 'fidonet_cost',
|
||||||
|
FidoNetOrigNode : 'fidonet_orig_node',
|
||||||
|
FidoNetDestNode : 'fidonet_dest_node',
|
||||||
|
FidoNetOrigNetwork : 'fidonet_orig_network',
|
||||||
|
FidoNetDestNetwork : 'fidonet_dest_network',
|
||||||
|
FidoNetOrigZone : 'fidonet_orig_zone',
|
||||||
|
FidoNetDestZone : 'fidonet_dest_zone',
|
||||||
|
FidoNetOrigPoint : 'fidonet_orig_point',
|
||||||
|
FidoNetDestPoint : 'fidonet_dest_point',
|
||||||
|
FidoNetAttribute : 'fidonet_attribute',
|
||||||
|
|
||||||
|
FidoNetProgramID : 'fidonet_program_id', // "PID" http://ftsc.org/docs/fsc-0046.005
|
||||||
|
|
||||||
|
FidoNetMsgID : 'fidonet_msg_id', // "MSGID" http://ftsc.org/docs/fsc-0070.002
|
||||||
|
|
||||||
|
FidoNetMessageID : 'fidonet_message_id', // "MESSAGE-ID" http://ftsc.org/docs/fsc-0030.001
|
||||||
|
FidoNetInReplyTo : 'fidonet_in_reply_to', // "IN-REPLY-TO" http://ftsc.org/docs/fsc-0030.001
|
||||||
|
|
||||||
|
FidoNetTearLineBanner : 'fidonet_tear_line_banner', // FTN style tear line http://ftsc.org/docs/fts-0004.001
|
||||||
|
FidoNetOrigin : 'fidonet_origin', // FTN style "* Origin..." http://ftsc.org/docs/fts-0004.001
|
||||||
|
FidoNetSeenBy : 'fidonet_seen_by', // FTN style "SEEN-BY" http://ftsc.org/docs/fts-0004.001
|
||||||
|
FidoNetPath : 'fidonet_path', // FTN style "PATH" http://ftsc.org/docs/fts-0004.001
|
||||||
|
|
||||||
|
LocalToUserID : 'local_to_user_id',
|
||||||
|
LocalFromUserID : 'local_from_user_id',
|
||||||
|
|
||||||
|
// :TODO: Search further:
|
||||||
|
// https://www.npmjs.com/package/fidonet-jam
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.setLocalToUserId = function(userId) {
|
||||||
|
this.meta.LocalToUserID = userId;
|
||||||
|
};
|
||||||
|
|
||||||
|
Message.prototype.setLocalFromUserId = function(userId) {
|
||||||
|
this.meta.LocalFromUserID = userId;
|
||||||
|
};
|
||||||
|
|
||||||
Message.prototype.persist = function(cb) {
|
Message.prototype.persist = function(cb) {
|
||||||
|
|
||||||
if(!this.isValid()) {
|
if(!this.isValid()) {
|
||||||
|
@ -51,9 +118,11 @@ Message.prototype.persist = function(cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function storeMessage(callback) {
|
function storeMessage(callback) {
|
||||||
|
var modTs = self.modTimestamp || self.createMessageTimestamp();
|
||||||
|
|
||||||
msgDb.run(
|
msgDb.run(
|
||||||
'INSERT INTO message (area_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, message, modified_timestamp) ' +
|
'INSERT INTO message (area_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, message, modified_timestamp) ' +
|
||||||
'VALUES (?, ?, ?, ?, ?, ?, ?, ?);', [ self.areaId, self.uuid, self.replyToMsgId, self.toUserName, self.fromUserName, self.subject, self.message, self.createMessageTimestamp() ],
|
'VALUES (?, ?, ?, ?, ?, ?, ?, ?);', [ self.areaId, self.uuid, self.replyToMsgId, self.toUserName, self.fromUserName, self.subject, self.message, modTs ],
|
||||||
function msgInsert(err) {
|
function msgInsert(err) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
self.messageId = this.lastID;
|
self.messageId = this.lastID;
|
||||||
|
@ -73,7 +142,7 @@ Message.prototype.persist = function(cb) {
|
||||||
'VALUES (?, ?, ?);');
|
'VALUES (?, ?, ?);');
|
||||||
|
|
||||||
async.each(Object.keys(self.meta), function meta(metaName, next) {
|
async.each(Object.keys(self.meta), function meta(metaName, next) {
|
||||||
metaStmt.run(self.messageId, metaName, self.meta[metaName], function insRan(err) {
|
metaStmt.run(self.messageId, metaName, self.meta[metaName], function inserted(err) {
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
}, function complete(err) {
|
}, function complete(err) {
|
||||||
|
@ -86,8 +155,16 @@ Message.prototype.persist = function(cb) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function storeHashTags(callback) {
|
||||||
|
// :TODO: hash tag support
|
||||||
|
callback(null);
|
||||||
|
}
|
||||||
|
],
|
||||||
|
function complete(err) {
|
||||||
|
msgDb.run(err ? 'ROLLBACK;' : 'COMMIT;', function transEnd(err) {
|
||||||
|
cb(err, self.messageId);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
24
mods/fse.js
24
mods/fse.js
|
@ -6,6 +6,7 @@ var ViewController = require('../core/view_controller.js').ViewController;
|
||||||
var ansi = require('../core/ansi_term.js');
|
var ansi = require('../core/ansi_term.js');
|
||||||
var theme = require('../core/theme.js');
|
var theme = require('../core/theme.js');
|
||||||
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
||||||
|
var Message = require('../core/message.js').Message;
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
@ -47,6 +48,27 @@ function FullScreenEditorModule(options) {
|
||||||
}[name];
|
}[name];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getMessage = function() {
|
||||||
|
var headerForm = self.viewControllers.header.getFormData();
|
||||||
|
console.log(headerForm)
|
||||||
|
|
||||||
|
var messageOpts = {
|
||||||
|
areaId : Message.WellKnownAreaIds.Private,
|
||||||
|
toUserName : headerForm.to,
|
||||||
|
fromUserName : headerForm.from,
|
||||||
|
subject : headerForm.subject,
|
||||||
|
message : 'This is the message',
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(messageOpts);
|
||||||
|
|
||||||
|
/*var msg = new Message(messageOpts);
|
||||||
|
msg.persist(function persisted(err, msgId) {
|
||||||
|
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
this.redrawFooter = function(options, cb) {
|
this.redrawFooter = function(options, cb) {
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
|
@ -366,7 +388,7 @@ function FullScreenEditorModule(options) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
editModeMenuSave : function(formData, extraArgs) {
|
editModeMenuSave : function(formData, extraArgs) {
|
||||||
|
self.getMessage();
|
||||||
},
|
},
|
||||||
editModeMenuQuote : function(formData, extraArgs) {
|
editModeMenuQuote : function(formData, extraArgs) {
|
||||||
|
|
||||||
|
|
|
@ -514,15 +514,18 @@
|
||||||
// :TODO: from/to may be set by args
|
// :TODO: from/to may be set by args
|
||||||
// :TODO: focus may change dep on view vs edit
|
// :TODO: focus may change dep on view vs edit
|
||||||
"width" : 36,
|
"width" : 36,
|
||||||
"focus" : true
|
"focus" : true,
|
||||||
|
"argName" : "to"
|
||||||
},
|
},
|
||||||
"ET2" : {
|
"ET2" : {
|
||||||
"width" : 36
|
"width" : 36,
|
||||||
|
"argName" : "from"
|
||||||
},
|
},
|
||||||
"ET3" : {
|
"ET3" : {
|
||||||
"width" : 65,
|
"width" : 65,
|
||||||
"maxLength" : 72,
|
"maxLength" : 72,
|
||||||
"submit" : [ "enter" ]
|
"submit" : [ "enter" ],
|
||||||
|
"argName" : "subject"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submit" : {
|
"submit" : {
|
||||||
|
@ -541,7 +544,8 @@
|
||||||
"MT1" : {
|
"MT1" : {
|
||||||
"width" : 79,
|
"width" : 79,
|
||||||
"height" : 17,
|
"height" : 17,
|
||||||
"text" : "" // :TODO: should not be req.
|
"text" : "", // :TODO: should not be req.
|
||||||
|
"argName" : "message"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submit" : {
|
"submit" : {
|
||||||
|
|
Loading…
Reference in New Issue