* Cleanup related to message area IDs / database -> JSON format and names
This commit is contained in:
parent
35de0a2487
commit
d69d00a14b
|
@ -124,7 +124,7 @@ function getDefaultConfig() {
|
|||
|
||||
messages : {
|
||||
areas : [
|
||||
{ name : "private_mail", desc : "Private Email", groups : [ "users" ] }
|
||||
{ name : 'private_mail', desc : 'Private Email', groups : [ 'users' ] }
|
||||
]
|
||||
},
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ function createUserTables() {
|
|||
|
||||
function createMessageBaseTables() {
|
||||
|
||||
/*
|
||||
dbs.message.run(
|
||||
'CREATE TABLE IF NOT EXISTS message_area (' +
|
||||
' area_id INTEGER PRIMARY KEY,' +
|
||||
|
@ -95,11 +96,12 @@ function createMessageBaseTables() {
|
|||
' group_id INTEGER NOT NULL' + // FK @ user.sqlite::user_group::group_id
|
||||
');'
|
||||
);
|
||||
*/
|
||||
|
||||
dbs.message.run(
|
||||
'CREATE TABLE IF NOT EXISTS message (' +
|
||||
' message_id INTEGER PRIMARY KEY,' +
|
||||
' area_id INTEGER NOT NULL,' +
|
||||
' area_name VARCHAR NOT NULL,' +
|
||||
' message_uuid VARCHAR(36) NOT NULL,' +
|
||||
' reply_to_message_id INTEGER,' +
|
||||
' to_user_name VARCHAR NOT NULL,' +
|
||||
|
@ -109,7 +111,6 @@ function createMessageBaseTables() {
|
|||
' modified_timestamp DATETIME NOT NULL,' +
|
||||
' view_count INTEGER NOT NULL DEFAULT 0,' +
|
||||
' UNIQUE(message_uuid),' +
|
||||
' FOREIGN KEY(area_id) REFERENCES message_area(area_id)' +
|
||||
');'
|
||||
);
|
||||
|
||||
|
@ -165,13 +166,6 @@ function createMessageBaseTables() {
|
|||
}
|
||||
|
||||
function createInitialMessageValues() {
|
||||
//
|
||||
// Area ID 1: Private / Local
|
||||
//
|
||||
dbs.message.run(
|
||||
'INSERT OR IGNORE INTO message_area ' +
|
||||
'VALUES(1, "Local Private Messages");'
|
||||
);
|
||||
}
|
||||
|
||||
function createInitialUserValues() {
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = Message;
|
|||
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.areaName = options.areaName || Message.WellKnownAreaNames.Invalid;
|
||||
this.uuid = uuid.v1();
|
||||
this.replyToMsgId = options.replyToMsgId || 0;
|
||||
this.toUserName = options.toUserName || '';
|
||||
|
@ -73,9 +73,9 @@ function Message(options) {
|
|||
*/
|
||||
}
|
||||
|
||||
Message.WellKnownAreaIds = {
|
||||
Invalid : 0,
|
||||
Private : 1,
|
||||
Message.WellKnownAreaNames = {
|
||||
Invalid : '',
|
||||
Private : 'private_mail'
|
||||
};
|
||||
|
||||
Message.MetaCategories = {
|
||||
|
@ -135,8 +135,8 @@ Message.prototype.persist = function(cb) {
|
|||
},
|
||||
function storeMessage(callback) {
|
||||
msgDb.run(
|
||||
'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.getMessageTimestampString(self.modTimestamp) ],
|
||||
'INSERT INTO message (area_name, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, message, modified_timestamp) ' +
|
||||
'VALUES (?, ?, ?, ?, ?, ?, ?, ?);', [ self.areaName, self.uuid, self.replyToMsgId, self.toUserName, self.fromUserName, self.subject, self.message, self.getMessageTimestampString(self.modTimestamp) ],
|
||||
function msgInsert(err) {
|
||||
if(!err) {
|
||||
self.messageId = this.lastID;
|
||||
|
|
|
@ -54,98 +54,3 @@ function changeMessageArea(client, areaName, cb) {
|
|||
}
|
||||
);
|
||||
}
|
||||
/*
|
||||
function getAvailableMessageAreas(cb) {
|
||||
var areas = []; // { areaId, name, groupIds[] }
|
||||
|
||||
async.series(
|
||||
[
|
||||
function getAreas(callback) {
|
||||
msgDb.all(
|
||||
'SELECT area_id, area_name ' +
|
||||
'FROM message_area;',
|
||||
function areaResults(err, areaRows) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
} else {
|
||||
areaRows.forEach(function entry(ar) {
|
||||
areas.push( {
|
||||
areaId : ar.area_id,
|
||||
name : ar.area_name,
|
||||
});
|
||||
});
|
||||
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
function getAreaGroups(callback) {
|
||||
var query = msgDb.prepare(
|
||||
'SELECT group_id ' +
|
||||
'FROM message_area_group ' +
|
||||
'WHERE area_id=?;');
|
||||
|
||||
async.each(areas, function area(a, next) {
|
||||
query.all( [ a.areaId ], function groupRows(err, groups) {
|
||||
a.groupIds = groups;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function complete(err) {
|
||||
query.finalize(function finalized(err2) {
|
||||
callback(err); // use orig err
|
||||
});
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
cb(err, areas);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function changeCurrentArea(client, areaId, cb) {
|
||||
async.series(
|
||||
[
|
||||
function validateAccess(callback) {
|
||||
// :TODO: validate user has access to areaId -- must belong to group(s) specified
|
||||
callback(null);
|
||||
},
|
||||
function changeArea(callback) {
|
||||
client.user.persistProperty('message_area_id', areaId, function persisted(err) {
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function cacheAreaName(callback) {
|
||||
msgDb.get(
|
||||
'SELECT area_name ' +
|
||||
'FROM message_area ' +
|
||||
'WHERE area_id=? ' +
|
||||
'LIMIT 1;',
|
||||
[ areaId ],
|
||||
function got(err, row) {
|
||||
// note: failures here are non-fatal
|
||||
if(err) {
|
||||
callback(null);
|
||||
} else {
|
||||
client.user.persistProperty('message_area_name', row.area_name, function persisted(err) {
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
if(!err) {
|
||||
client.log.info( { areaId : areaId }, 'Current message area changed');
|
||||
} else {
|
||||
client.log.warn( { areaId : areaId, error : err.message }, 'Could not change message area');
|
||||
}
|
||||
|
||||
cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
*/
|
|
@ -24,6 +24,8 @@ function MessageAreaListModule(options) {
|
|||
|
||||
var self = this;
|
||||
|
||||
this.messageAreas = messageArea.getAvailableMessageAreas();
|
||||
|
||||
if(_.isObject(this.menuConfig.config)) {
|
||||
if(_.isString(this.menuConfig.config.entryFormat)) {
|
||||
this.entryFormat = this.menuConfig.config.entryFormat;
|
||||
|
@ -48,22 +50,6 @@ function MessageAreaListModule(options) {
|
|||
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
var areaId = self.messageAreas[formData.value.area].areaId;
|
||||
|
||||
messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) {
|
||||
if(err) {
|
||||
self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n');
|
||||
|
||||
setTimeout(function timeout() {
|
||||
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||
}, 1000);
|
||||
} else {
|
||||
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -71,24 +57,13 @@ function MessageAreaListModule(options) {
|
|||
}
|
||||
|
||||
require('util').inherits(MessageAreaListModule, MenuModule);
|
||||
|
||||
/*
|
||||
MessageAreaListModule.prototype.enter = function(client) {
|
||||
var self = this;
|
||||
this.messageAreas = messageArea.getAvailableMessageAreas();
|
||||
|
||||
self.messageAreas = messageArea.getAvailableMessageAreas();
|
||||
|
||||
console.log(self.messageAreas)
|
||||
|
||||
MessageAreaListModule.super_.prototype.enter.call(self, client);
|
||||
|
||||
/*
|
||||
|
||||
messageArea.getAvailableMessageAreas(function fetched(err, areas) {
|
||||
self.messageAreas = areas;
|
||||
|
||||
MessageAreaListModule.super_.prototype.enter.call(self, client);
|
||||
});*/
|
||||
MessageAreaListModule.super_.prototype.enter.call(this, client);
|
||||
};
|
||||
*/
|
||||
|
||||
MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
||||
var self = this;
|
||||
|
@ -113,16 +88,6 @@ MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
|||
});
|
||||
},
|
||||
function populateAreaListView(callback) {
|
||||
var areaListView = vc.getView(1);
|
||||
|
||||
/*
|
||||
var areaList = [];
|
||||
self.messageAreas.forEach(function entry(msgArea) {
|
||||
// :TODO: depending on options, filter out private, local user to user, etc. area IDs
|
||||
// :TODO: dep. on options, filter out areas that current user does not have access to
|
||||
areaList.push(strUtil.format(self.entryFormat, msgArea));
|
||||
});*/
|
||||
|
||||
var areaListItems = [];
|
||||
for(var i = 0; i < self.messageAreas.length; ++i) {
|
||||
areaListItems.push(strUtil.format(
|
||||
|
@ -131,12 +96,13 @@ MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
|||
);
|
||||
}
|
||||
|
||||
var areaListView = vc.getView(1);
|
||||
areaListView.setItems(areaListItems);
|
||||
areaListView.redraw();
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
|
||||
cb(null);
|
||||
}
|
||||
);
|
||||
};
|
|
@ -59,12 +59,9 @@ function AreaPostFSEModule(options) {
|
|||
require('util').inherits(AreaPostFSEModule, FullScreenEditorModule);
|
||||
|
||||
AreaPostFSEModule.prototype.enter = function(client) {
|
||||
//
|
||||
// If messageAreaId is passed in extraArgs, use it. Otherwise, look
|
||||
// to the client user for current area ID
|
||||
//
|
||||
if(_.isNumber(client.user.properties.message_area_id)) {
|
||||
this.messageAreaId = client.user.properties.message_area_id;
|
||||
|
||||
if(_.isString(client.user.properties.message_area_name)) {
|
||||
this.messageAreaName = client.user.properties.message_area_name;
|
||||
}
|
||||
|
||||
AreaPostFSEModule.super_.prototype.enter.call(this, client);
|
||||
|
|
Loading…
Reference in New Issue