Merge branch '459-activitypub-integration' of github.com:NuSkooler/enigma-bbs into 459-activitypub-integration

This commit is contained in:
Bryan Ashby 2023-02-01 22:01:20 -07:00
commit d286fa2cf4
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
5 changed files with 198 additions and 0 deletions

View File

@ -462,6 +462,35 @@
} }
} }
// :TODO: move this to the right area, rename, etc.
mainMenuActivityPubActorSearch: {
0: {
mci: {
TL1: {
width: 70
}
BT2: {
width: 20
focusTextStyle: upper
}
}
}
1: {
mci: {
TL1: {
width: 70
}
TL2: {
width: 70
}
BT3: {
width: 20
focusTextStyle: upper
}
}
}
}
mainMenuRumorz: { mainMenuRumorz: {
0: { 0: {
mci: { mci: {

View File

@ -0,0 +1,161 @@
const { MenuModule } = require('../menu_module');
const { Errors } = require('../enig_error');
const Actor = require('../activitypub/actor');
// deps
const async = require('async');
const { get, truncate } = require('lodash');
exports.moduleInfo = {
name: 'ActivityPub Actor Search',
desc: 'Menu item to search for an ActivityPub actor',
author: 'CognitiveGears',
};
const FormIds = {
main: 0,
view: 1,
};
const MciViewIds = {
main: {
searchUrl: 1,
searchOrCancel: 2,
},
view: {
userName: 1,
fullName: 2,
},
};
exports.getModule = class ActivityPubActorSearch 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.searchUrl: {
return this._search(formData.value, cb);
}
case MciViewIds.main.searchOrCancel: {
const search = get(formData, 'value.searchOrCancel') === 0;
return search
? this._search(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();
}
);
}
_search(values, cb) {
const searchString = values['searchUrl'].trim();
//TODO: Handle empty searchString
Actor.fromId(searchString, (err, remoteActor) => {
if (err) {
this.client.log.warn(
{ remoteActor: remoteActor, err: err },
'Failure to search for actor'
);
// TODO: Add error to page for failure to find actor
return this._displayMainPage(true, cb);
}
return this._displayListScreen(remoteActor, cb);
});
}
_displayListScreen(remoteActor, cb) {
async.series(
[
callback => {
return this.displayArtAndPrepViewController(
'view',
FormIds.view,
{ clearScreen: true },
callback
);
},
callback => {
return this.validateMCIByViewIds(
'view',
Object.values(MciViewIds.view),
callback
);
},
callback => {
const v = id => this.getView('view', id);
const nameView = v(MciViewIds.view.userName);
nameView.setText(
truncate(remoteActor.preferredUsername, {
length: nameView.getWidth(),
})
);
// TODO: FIXME: fullNameView.getWidth() is 0 - I'm thinking it's getting form 0 for some reason
const fullNameView = v(MciViewIds.view.fullName);
fullNameView.setText(
truncate(remoteActor.name, { length: fullNameView.getWidth() })
);
return callback(null);
},
],
err => {
return cb(err);
}
);
}
_displayMainPage(clearScreen, cb) {
async.series(
[
callback => {
return this.displayArtAndPrepViewController(
'main',
FormIds.main,
{ clearScreen },
callback
);
},
callback => {
return this.validateMCIByViewIds(
'main',
Object.values(MciViewIds.main),
callback
);
},
],
err => {
return cb(err);
}
);
}
};

View File

@ -632,6 +632,14 @@ exports.MenuModule = class MenuModule extends PluginModule {
this.client.term.rawWrite(ansi.resetScreen()); this.client.term.rawWrite(ansi.resetScreen());
} }
if (!_.has(config.art, name)) {
const artKeys = _.keys(config.art);
this.client.log.warn(
{ requestedArtName: name, availableArtKeys: artKeys },
'Art name is not set! Check configuration for typos.'
);
}
theme.displayThemedAsset( theme.displayThemedAsset(
config.art[name], config.art[name],
this.client, this.client,