Add image URL editor for AcitvityPub user config

This commit is contained in:
Bryan Ashby 2023-02-12 17:48:34 -07:00
parent df55c3fa6d
commit 194a5b012e
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
5 changed files with 107 additions and 15 deletions

View File

@ -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. // :TODO: move this to the right area, rename, etc.

View File

@ -25,21 +25,26 @@ const MciViewIds = {
manuallyApproveFollowersToggle: 2, manuallyApproveFollowersToggle: 2,
hideSocialGraphToggle: 3, hideSocialGraphToggle: 3,
showRealNameToggle: 4, showRealNameToggle: 4,
image: 5, imageUrl: 5,
icon: 6, iconUrl: 6,
manageImagesButton: 7, manageImagesButton: 7,
saveOrCancel: 8, saveOrCancel: 8,
customRangeStart: 10, customRangeStart: 10,
}, },
images: {
imageUrl: 1,
iconUrl: 2,
saveOrCancel: 3,
},
}; };
const EnabledViewGroup = [ const EnabledViewGroup = [
MciViewIds.main.manuallyApproveFollowersToggle, MciViewIds.main.manuallyApproveFollowersToggle,
MciViewIds.main.hideSocialGraphToggle, MciViewIds.main.hideSocialGraphToggle,
MciViewIds.main.showRealNameToggle, MciViewIds.main.showRealNameToggle,
MciViewIds.main.image, MciViewIds.main.imageUrl,
MciViewIds.main.icon, MciViewIds.main.iconUrl,
MciViewIds.main.manageImagesButton, MciViewIds.main.manageImagesButton,
]; ];
@ -52,7 +57,7 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule {
}); });
this.menuMethods = { this.menuMethods = {
submit: (formData, extraArgs, cb) => { mainSubmit: (formData, extraArgs, cb) => {
switch (formData.submitId) { switch (formData.submitId) {
case MciViewIds.main.manageImagesButton: case MciViewIds.main.manageImagesButton:
return this._manageImagesButton(cb); 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) { _manageImagesButton(cb) {
return cb(null); this.viewControllers.main.setFocus(false);
return this._displayImagesPage(true, cb);
} }
_save(values, 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) { _displayMainPage(clearScreen, cb) {
async.series( async.series(
[ [
@ -140,7 +178,9 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule {
callback => { callback => {
return this.validateMCIByViewIds( return this.validateMCIByViewIds(
'main', 'main',
Object.values(MciViewIds.main), Object.values(MciViewIds.main).filter(
i => i !== MciViewIds.main.customRangeStart
),
callback callback
); );
}, },
@ -155,8 +195,8 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule {
MciViewIds.main.hideSocialGraphToggle MciViewIds.main.hideSocialGraphToggle
); );
const showRealNameToggleView = v(MciViewIds.main.showRealNameToggle); const showRealNameToggleView = v(MciViewIds.main.showRealNameToggle);
const imageView = v(MciViewIds.main.image); const imageView = v(MciViewIds.main.imageUrl);
const iconView = v(MciViewIds.main.icon); const iconView = v(MciViewIds.main.iconUrl);
const apSettings = ActivityPubSettings.fromUser(this.client.user); const apSettings = ActivityPubSettings.fromUser(this.client.user);
enabledToggleView.setFromBoolean(apSettings.enabled); 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() { _toggleEnabledViewGroup() {
const enabledToggleView = this.getView('main', MciViewIds.main.enabledToggle); const enabledToggleView = this.getView('main', MciViewIds.main.enabledToggle);
EnabledViewGroup.forEach(id => { EnabledViewGroup.forEach(id => {

View File

@ -3,9 +3,7 @@
// ENiGMA½ // ENiGMA½
const MenuModule = require('./menu_module.js').MenuModule; const MenuModule = require('./menu_module.js').MenuModule;
const ViewController = require('./view_controller.js').ViewController;
const ansi = require('./ansi_term.js'); const ansi = require('./ansi_term.js');
const theme = require('./theme.js');
const FileEntry = require('./file_entry.js'); const FileEntry = require('./file_entry.js');
const stringFormat = require('./string_format.js'); const stringFormat = require('./string_format.js');
const FileArea = require('./file_base_area.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') { if (name === 'details') {
try { try {
this.detailsInfoArea = { this.detailsInfoArea = {

View File

@ -81,6 +81,8 @@ module.exports = class MenuStack {
prev(cb) { prev(cb) {
const menuResult = this.top().instance.getMenuResult(); const menuResult = this.top().instance.getMenuResult();
const currentModuleInfo = this.top();
// :TODO: leave() should really take a cb... // :TODO: leave() should really take a cb...
this.pop().instance.leave(); // leave & remove current this.pop().instance.leave(); // leave & remove current
@ -91,6 +93,7 @@ module.exports = class MenuStack {
extraArgs: previousModuleInfo.extraArgs, extraArgs: previousModuleInfo.extraArgs,
savedState: previousModuleInfo.savedState, savedState: previousModuleInfo.savedState,
lastMenuResult: menuResult, lastMenuResult: menuResult,
currentModuleInfo,
}; };
return this.goto(previousModuleInfo.name, opts, cb); return this.goto(previousModuleInfo.name, opts, cb);
@ -102,14 +105,13 @@ module.exports = class MenuStack {
} }
goto(name, options, cb) { goto(name, options, cb) {
const currentModuleInfo = this.top();
if (!cb && _.isFunction(options)) { if (!cb && _.isFunction(options)) {
cb = options; cb = options;
options = {}; options = {};
} }
options = options || {}; options = options || {};
const currentModuleInfo = options.currentModuleInfo || this.top();
const self = this; const self = this;
if (currentModuleInfo && name === currentModuleInfo.name) { if (currentModuleInfo && name === currentModuleInfo.name) {