diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 596cffa3..fa9c7ac8 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -11,6 +11,7 @@ var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView; var MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView; var StatusBarView = require('./status_bar_view.js').StatusBarView; var MultiLineEditTextView = require('./multi_line_edit_text_view.js').MultiLineEditTextView; +var getMessageAreaByName = require('./message_area.js').getMessageAreaByName; var Config = require('./config.js').config; var ansi = require('./ansi_term.js'); @@ -29,6 +30,14 @@ function MCIViewFactory(client) { } MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { + + var self = this; + + function getMessageAreaDescription() { + var area = getMessageAreaByName(self.client.user.properties.message_area_name); + return area ? area.desc : ''; + } + try { return { BN : Config.general.boardName, @@ -49,7 +58,7 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { UT : this.client.user.properties.theme_id, MS : moment(this.client.user.properties.account_created).format(this.client.currentTheme.helpers.getDateFormat()), - MA : this.client.user.properties.message_area_desc, + MA : getMessageAreaDescription(), SH : this.client.term.termHeight.toString(), diff --git a/core/message_area.js b/core/message_area.js index 4e1810cd..55a4b904 100644 --- a/core/message_area.js +++ b/core/message_area.js @@ -9,17 +9,32 @@ var _ = require('lodash'); var assert = require('assert'); exports.getAvailableMessageAreas = getAvailableMessageAreas; +exports.getMessageAreaByName = getMessageAreaByName; exports.changeMessageArea = changeMessageArea; function getAvailableMessageAreas() { return Config.messages.areas; } +function getMessageAreaByName(areaName) { + areaName = areaName.toLowerCase(); + + var availAreas = getAvailableMessageAreas(); + var index = _.findIndex(availAreas, function pred(an) { + return an.name == areaName; + }); + + if(index > -1) { + return availAreas[index]; + } +} + function changeMessageArea(client, areaName, cb) { async.waterfall( [ function getArea(callback) { + /* var availAreas = getAvailableMessageAreas(); areaName = areaName.toLowerCase(); // always lookup lowercase @@ -32,13 +47,21 @@ function changeMessageArea(client, areaName, cb) { } else { callback(new Error('Invalid message area')); } + */ + + var area = getMessageAreaByName(areaName); + if(area) { + callback(null, area); + } else { + callback(new Error('Invalid message area')); + } }, function validateAccess(area, callback) { // :TODO: validate user has access to |area| -- must belong to group(s) specified callback(null, area); }, function changeArea(area, callback) { - client.user.persistProperties( { message_area_name : area.name, message_area_desc : area.desc }, function persisted(err) { + client.user.persistProperty('message_area_name', area.name, function persisted(err) { callback(err, area); }); } diff --git a/core/user.js b/core/user.js index 55b5f489..73a092ae 100644 --- a/core/user.js +++ b/core/user.js @@ -197,9 +197,7 @@ User.prototype.create = function(options, cb) { if(1 === self.userId) { self.properties.account_status = User.AccountStatus.active; } - - - + callback(null); } }