Add image URL editor for AcitvityPub user config
This commit is contained in:
parent
df55c3fa6d
commit
194a5b012e
Binary file not shown.
|
@ -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.
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue