diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index 8f6d01d7..4fc408c6 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -427,6 +427,39 @@ } } + // :TODO: move this to the right area, rename, etc. + mainMenuActivityPubUserConfig: { + 0: { + mci: { + TM1: { + focusTextStyle: upper + } + TM2: { + focusTextStyle: upper + } + TM3: { + focusTextStyle: upper + } + TM4: { + focusTextStyle: upper + } + TL5: { + width: 70 + } + TL6: { + width: 70 + } + BT7: { + width: 20 + focusTextStyle: upper + } + TM8: { + focusTextStyle: upper + } + } + } + } + mainMenuRumorz: { 0: { mci: { diff --git a/core/activitypub/settings.js b/core/activitypub/settings.js index 3c7cdb95..b7f4e2bd 100644 --- a/core/activitypub/settings.js +++ b/core/activitypub/settings.js @@ -13,6 +13,7 @@ module.exports = class ActivityPubSettings { // override default with any op config Object.assign(this, Config().users.activityPub); + // finally override with any explicit values given to us if (obj) { Object.assign(this, obj); } @@ -39,7 +40,15 @@ module.exports = class ActivityPubSettings { return user.persistProperty( UserProps.ActivityPubSettings, JSON.stringify(this), - cb + err => { + if (!err) { + // drop from cache + delete user.activityPubSettings; + } + if (cb) { + return cb(err); + } + } ); } }; diff --git a/core/activitypub/user_config.js b/core/activitypub/user_config.js new file mode 100644 index 00000000..a56f29ed --- /dev/null +++ b/core/activitypub/user_config.js @@ -0,0 +1,161 @@ +const { MenuModule } = require('../menu_module'); +const ActivityPubSettings = require('./settings'); +const { Errors } = require('../enig_error'); + +// deps +const async = require('async'); +const { get, truncate } = require('lodash'); + +exports.moduleInfo = { + name: 'ActivityPub User Config', + desc: 'ActivityPub User Configuration', + author: 'NuSkooler', +}; + +const FormIds = { + main: 0, + images: 1, +}; + +const MciViewIds = { + main: { + enabledToggle: 1, + manuallyApproveFollowersToggle: 2, + hideSocialGraphToggle: 3, + showRealNameToggle: 4, + image: 5, + icon: 6, + manageImagesButton: 7, + saveOrCancel: 8, + }, +}; + +exports.getModule = class ActivityPubUserConfig extends MenuModule { + constructor(options) { + super(options); + + this.config = Object.assign({}, get(options, 'menuConfig.config'), { + extraArgs: options.extraArgs, + }); + + this.menuMethods = { + submit: (formData, extraArgs, cb) => { + switch (formData.submitId) { + case MciViewIds.main.manageImagesButton: + return this._manageImagesButton(cb); + + case MciViewIds.main.saveOrCancel: { + const save = get(formData, 'value.saveOrCancel') === 0; + return save ? this._save(formData.value, cb) : this.prevMenu(cb); + } + + default: + cb( + Errors.UnexpectedState( + `Unexpected submitId: ${formData.submitId}` + ) + ); + } + }, + }; + } + + initSequence() { + async.series( + [ + callback => { + return this.beforeArt(callback); + }, + callback => { + return this._displayMainPage(false, callback); + }, + ], + () => { + this.finishedLoading(); + } + ); + } + + _manageImagesButton(cb) { + return cb(null); + } + + _save(values, cb) { + const reqFields = [ + 'enabled', + 'manuallyApproveFollowers', + 'hideSocialGraph', + 'showRealName', + ]; + if ( + !reqFields.every(p => { + return true === !![values[p]]; + }) + ) { + return cb(Errors.BadFormData('One or more missing form values')); + } + + const apSettings = ActivityPubSettings.fromUser(this.client.user); + apSettings.enabled = values.enabled; + apSettings.manuallyApproveFollowers = values.manuallyApproveFollowers; + apSettings.hideSocialGraph = values.hideSocialGraph; + apSettings.showRealName = values.showRealName; + + return apSettings.persistToUserProperties(this.client.user, cb); + } + + _displayMainPage(clearScreen, cb) { + async.series( + [ + callback => { + return this.displayArtAndPrepViewController( + 'main', + FormIds.main, + { clearScreen }, + callback + ); + }, + callback => { + return this.validateMCIByViewIds( + 'main', + Object.values(MciViewIds.main), + callback + ); + }, + callback => { + const v = id => this.getView('main', id); + + const enabledToggleView = v(MciViewIds.main.enabledToggle); + const manuallyApproveFollowersToggleView = v( + MciViewIds.main.manuallyApproveFollowersToggle + ); + const hideSocialGraphToggleView = v( + MciViewIds.main.hideSocialGraphToggle + ); + const showRealNameToggleView = v(MciViewIds.main.showRealNameToggle); + const imageView = v(MciViewIds.main.image); + const iconView = v(MciViewIds.main.icon); + + const apSettings = ActivityPubSettings.fromUser(this.client.user); + enabledToggleView.setFromBoolean(apSettings.enabled); + manuallyApproveFollowersToggleView.setFromBoolean( + apSettings.manuallyApproveFollowers + ); + hideSocialGraphToggleView.setFromBoolean(apSettings.hideSocialGraph); + showRealNameToggleView.setFromBoolean(apSettings.showRealName); + imageView.setText( + truncate(apSettings.image, { length: imageView.getWidth() }) + ); + iconView.setText( + truncate(apSettings.icon, { length: iconView.getWidth() }) + ); + + return callback(null); + }, + ], + err => { + return cb(err); + } + ); + } +}; diff --git a/core/enig_error.js b/core/enig_error.js index c396cbe4..0423703a 100644 --- a/core/enig_error.js +++ b/core/enig_error.js @@ -57,6 +57,8 @@ exports.Errors = { MissingProperty: (reason, reasonCode) => new EnigError('Missing property', -32014, reason, reasonCode), Expired: (reason, reasonCode) => new EnigError('Expired', -32015, reason, reasonCode), + BadFormData: (reason, reasonCode) => + new EnigError('Bad or missing form data', -32016, reason, reasonCode), }; exports.ErrorReasons = { diff --git a/core/view.js b/core/view.js index f568a09a..fe0c4a88 100644 --- a/core/view.js +++ b/core/view.js @@ -127,6 +127,14 @@ View.prototype.getId = function () { return this.id; }; +View.prototype.getWidth = function () { + return this.dimens.width; +}; + +View.prototype.getHeight = function () { + return this.dimens.height; +}; + View.prototype.setPosition = function (pos) { // // Allow the following forms: [row, col], { row : r, col : c }, or (row, col)