From 194a5b012e428233846db726be83f041e3bbb91d Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 12 Feb 2023 17:48:34 -0700 Subject: [PATCH] Add image URL editor for AcitvityPub user config --- .../activitypub_user_config_images.ans | Bin 0 -> 2151 bytes art/themes/luciano_blocktronics/theme.hjson | 15 +++ core/activitypub/user_config.js | 95 ++++++++++++++++-- core/file_area_list.js | 4 +- core/menu_stack.js | 8 +- 5 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 art/themes/luciano_blocktronics/activitypub_user_config_images.ans diff --git a/art/themes/luciano_blocktronics/activitypub_user_config_images.ans b/art/themes/luciano_blocktronics/activitypub_user_config_images.ans new file mode 100644 index 0000000000000000000000000000000000000000..b61239faa7d2ffd2abfcf6ca4f42e8026a5d6d74 GIT binary patch literal 2151 zcmds2!D_-l5Y=7^enF|1xd`noCPks1q67&vQfd^6r!+<>brYxx?YAb7FKOv?b~iR_ z0wJ}R?!ovbGw;pp&TQHXjkTb?=nf2x#Q^wM8yGtKe7lg3i221d^ z;K7sUzpP)QeTZey30{9^U!HQ>Y8W7&Wg@RpgR9!;296gHcVwyf!tst>S?y^dXs zVV%&j7+EBz&eBfOYLi(;tJ)PAye4S=#aZT|8e1P1tH_S2&zp}FDkr}$sG~csV~{|9 zaMNQP$t&)!gsYU7CNZrfO`!HCPZWS0NXHqe?=Gk2Y-DL#K9NFXhEe#=qW!k;?ZK#P dx}oV^{o}mRXg2Q~7Y$lx_RxX(*yJet{Q^i{urvSw literal 0 HcmV?d00001 diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index 45237c24..934ef6f7 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -467,6 +467,21 @@ } } } + 1: { + mci: { + ML1: { + height: 4 + width: 70 + } + ML2: { + height: 4 + width: 70 + } + TM3: { + focusTextStyle: first lower + } + } + } } // :TODO: move this to the right area, rename, etc. diff --git a/core/activitypub/user_config.js b/core/activitypub/user_config.js index 220d7f55..09d1386b 100644 --- a/core/activitypub/user_config.js +++ b/core/activitypub/user_config.js @@ -25,21 +25,26 @@ const MciViewIds = { manuallyApproveFollowersToggle: 2, hideSocialGraphToggle: 3, showRealNameToggle: 4, - image: 5, - icon: 6, + imageUrl: 5, + iconUrl: 6, manageImagesButton: 7, saveOrCancel: 8, customRangeStart: 10, }, + images: { + imageUrl: 1, + iconUrl: 2, + saveOrCancel: 3, + }, }; const EnabledViewGroup = [ MciViewIds.main.manuallyApproveFollowersToggle, MciViewIds.main.hideSocialGraphToggle, MciViewIds.main.showRealNameToggle, - MciViewIds.main.image, - MciViewIds.main.icon, + MciViewIds.main.imageUrl, + MciViewIds.main.iconUrl, MciViewIds.main.manageImagesButton, ]; @@ -52,7 +57,7 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { }); this.menuMethods = { - submit: (formData, extraArgs, cb) => { + mainSubmit: (formData, extraArgs, cb) => { switch (formData.submitId) { case MciViewIds.main.manageImagesButton: return this._manageImagesButton(cb); @@ -70,6 +75,13 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { ); } }, + imagesSubmit: (formData, extraArgs, cb) => { + const save = get(formData, 'value.imagesSaveOrCancel') === 0; + return save ? this._saveImages(formData.value, cb) : this._backToMain(cb); + }, + backToMain: (formData, extraArgs, cb) => { + return this._backToMain(cb); + }, }; } @@ -89,8 +101,14 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { ); } + _backToMain(cb) { + this.viewControllers.images.setFocus(false); + return this._displayMainPage(true, cb); + } + _manageImagesButton(cb) { - return cb(null); + this.viewControllers.main.setFocus(false); + return this._displayImagesPage(true, cb); } _save(values, cb) { @@ -126,6 +144,26 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { }); } + _saveImages(values, cb) { + const apSettings = ActivityPubSettings.fromUser(this.client.user); + apSettings.image = values.imageUrl.trim(); + apSettings.icon = values.iconUrl.trim(); + + apSettings.persistToUserProperties(this.client.user, err => { + if (err) { + if (err) { + const user = this.client.user; + this.client.log.warn( + { error: err.message, user: user.username }, + `Failed saving ActivityPub settings for user "${user.username}"` + ); + } + } + + return this._backToMain(cb); + }); + } + _displayMainPage(clearScreen, cb) { async.series( [ @@ -140,7 +178,9 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { callback => { return this.validateMCIByViewIds( 'main', - Object.values(MciViewIds.main), + Object.values(MciViewIds.main).filter( + i => i !== MciViewIds.main.customRangeStart + ), callback ); }, @@ -155,8 +195,8 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { MciViewIds.main.hideSocialGraphToggle ); const showRealNameToggleView = v(MciViewIds.main.showRealNameToggle); - const imageView = v(MciViewIds.main.image); - const iconView = v(MciViewIds.main.icon); + const imageView = v(MciViewIds.main.imageUrl); + const iconView = v(MciViewIds.main.iconUrl); const apSettings = ActivityPubSettings.fromUser(this.client.user); enabledToggleView.setFromBoolean(apSettings.enabled); @@ -189,6 +229,43 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule { ); } + _displayImagesPage(clearScreen, cb) { + async.series( + [ + callback => { + return this.displayArtAndPrepViewController( + 'images', + FormIds.images, + { clearScreen }, + callback + ); + }, + callback => { + return this.validateMCIByViewIds( + 'images', + Object.values(MciViewIds.images), + callback + ); + }, + callback => { + const v = id => this.getView('images', id); + + const imageView = v(MciViewIds.images.imageUrl); + const iconView = v(MciViewIds.images.iconUrl); + + const apSettings = ActivityPubSettings.fromUser(this.client.user); + imageView.setText(apSettings.image); + iconView.setText(apSettings.icon); + + return callback(null); + }, + ], + err => { + return cb(err); + } + ); + } + _toggleEnabledViewGroup() { const enabledToggleView = this.getView('main', MciViewIds.main.enabledToggle); EnabledViewGroup.forEach(id => { diff --git a/core/file_area_list.js b/core/file_area_list.js index 9a778468..13e7eed6 100644 --- a/core/file_area_list.js +++ b/core/file_area_list.js @@ -3,9 +3,7 @@ // ENiGMA½ const MenuModule = require('./menu_module.js').MenuModule; -const ViewController = require('./view_controller.js').ViewController; const ansi = require('./ansi_term.js'); -const theme = require('./theme.js'); const FileEntry = require('./file_entry.js'); const stringFormat = require('./string_format.js'); const FileArea = require('./file_base_area.js'); @@ -344,7 +342,7 @@ exports.getModule = class FileAreaList extends MenuModule { ); } - displayArtDataPrepCallback(name, artData, viewController) { + displayArtDataPrepCallback(name, artData) { if (name === 'details') { try { this.detailsInfoArea = { diff --git a/core/menu_stack.js b/core/menu_stack.js index 961fdc7e..8ab4a4e8 100644 --- a/core/menu_stack.js +++ b/core/menu_stack.js @@ -81,6 +81,8 @@ module.exports = class MenuStack { prev(cb) { const menuResult = this.top().instance.getMenuResult(); + const currentModuleInfo = this.top(); + // :TODO: leave() should really take a cb... this.pop().instance.leave(); // leave & remove current @@ -91,6 +93,7 @@ module.exports = class MenuStack { extraArgs: previousModuleInfo.extraArgs, savedState: previousModuleInfo.savedState, lastMenuResult: menuResult, + currentModuleInfo, }; return this.goto(previousModuleInfo.name, opts, cb); @@ -102,14 +105,13 @@ module.exports = class MenuStack { } goto(name, options, cb) { - const currentModuleInfo = this.top(); - if (!cb && _.isFunction(options)) { cb = options; options = {}; } - options = options || {}; + + const currentModuleInfo = options.currentModuleInfo || this.top(); const self = this; if (currentModuleInfo && name === currentModuleInfo.name) {