New MCI for AP subject, show subj and custom info format on config

This commit is contained in:
Bryan Ashby 2023-02-11 20:27:50 -07:00
parent a09fe4894f
commit df55c3fa6d
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
8 changed files with 98 additions and 2 deletions

View File

@ -430,6 +430,9 @@
// :TODO: move this to the right area, rename, etc.
mainMenuActivityPubUserConfig: {
config: {
mainInfoFormat10: "{subject}"
}
0: {
mci: {
TM1: {
@ -459,6 +462,9 @@
TM8: {
focusTextStyle: first lower
}
TL10: {
width: 40
}
}
}
}

View File

@ -270,7 +270,7 @@ module.exports = class Note extends ActivityPubObject {
}
// If the Note is marked sensitive, prefix the subject
if (this.sensitive) {
if (this.sensitive && message.subject.indexOf('[NSFW]') === -1) {
message.subject = `[NSFW] ${message.subject}`;
}

View File

@ -1,6 +1,8 @@
const { MenuModule } = require('../menu_module');
const ActivityPubSettings = require('./settings');
const { Errors } = require('../enig_error');
const { getServer } = require('../listening_server');
const { userNameToSubject } = require('./util');
// deps
const async = require('async');
@ -27,9 +29,20 @@ const MciViewIds = {
icon: 6,
manageImagesButton: 7,
saveOrCancel: 8,
customRangeStart: 10,
},
};
const EnabledViewGroup = [
MciViewIds.main.manuallyApproveFollowersToggle,
MciViewIds.main.hideSocialGraphToggle,
MciViewIds.main.showRealNameToggle,
MciViewIds.main.image,
MciViewIds.main.icon,
MciViewIds.main.manageImagesButton,
];
exports.getModule = class ActivityPubUserConfig extends MenuModule {
constructor(options) {
super(options);
@ -159,6 +172,14 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule {
truncate(apSettings.icon, { length: iconView.getWidth() })
);
this._toggleEnabledViewGroup();
this._updateCustomViews();
enabledToggleView.on('index update', () => {
this._toggleEnabledViewGroup();
this._updateCustomViews();
});
return callback(null);
},
],
@ -167,4 +188,40 @@ exports.getModule = class ActivityPubUserConfig extends MenuModule {
}
);
}
_toggleEnabledViewGroup() {
const enabledToggleView = this.getView('main', MciViewIds.main.enabledToggle);
EnabledViewGroup.forEach(id => {
const v = this.getView('main', id);
v.acceptsFocus = enabledToggleView.isTrue();
});
}
_updateCustomViews() {
const enabledToggleView = this.getView('main', MciViewIds.main.enabledToggle);
const ws = this._webServer();
const enabled = enabledToggleView.isTrue();
const formatObj = {
enabled,
status: enabled ? 'enabled' : 'disabled',
subject: enabled
? ws
? userNameToSubject(this.client.user.username, ws)
: 'N/A'
: '',
};
this.updateCustomViewTextsWithFilter(
'main',
MciViewIds.main.customRangeStart,
formatObj
);
}
_webServer() {
if (undefined === this.webServer) {
this.webServer = getServer('codes.l33t.enigma.web.server');
}
return this.webServer ? this.webServer.instance : null;
}
};

View File

@ -26,6 +26,7 @@ exports.messageBodyToHtml = messageBodyToHtml;
exports.messageToHtml = messageToHtml;
exports.htmlToMessageBody = htmlToMessageBody;
exports.userNameFromSubject = userNameFromSubject;
exports.userNameToSubject = userNameToSubject;
exports.extractMessageMetadata = extractMessageMetadata;
exports.recipientIdsFromObject = recipientIdsFromObject;
exports.sendFollowRequest = sendFollowRequest;
@ -144,7 +145,7 @@ function getUserProfileTemplatedBody(
const varMap = {
ACTOR_OBJ: JSON.stringify(userAsActor),
SUBJECT: `@${user.username}@${webServer.getDomain()}`,
SUBJECT: userNameToSubject(user.username, webServer),
INBOX: userAsActor.inbox,
SHARED_INBOX: userAsActor.endpoints.sharedInbox,
OUTBOX: userAsActor.outbox,
@ -228,6 +229,10 @@ function userNameFromSubject(subject) {
return subject.replace(/^acct:(.+)$/, '$1');
}
function userNameToSubject(userName, webServer) {
return `@${userName}@${webServer.getDomain()}`;
}
function extractMessageMetadata(body) {
const metadata = { mentions: new Set(), hashTags: new Set() };

View File

@ -13,6 +13,9 @@ const ANSI = require('./ansi_term.js');
const UserProps = require('./user_property.js');
const SysProps = require('./system_property.js');
const SysLogKeys = require('./system_log.js');
const ActivityPubSettings = require('./activitypub/settings');
const { userNameToSubject } = require('./activitypub/util');
const { getServer } = require('./listening_server');
// deps
const packageJson = require('../package.json');
@ -82,6 +85,15 @@ function userStatAsCountString(client, statName, defaultValue) {
return toNumberWithCommas(value);
}
// lazy cache
let cachedWebServer;
function getWebServer() {
if (undefined === cachedWebServer) {
cachedWebServer = getServer('codes.l33t.enigma.web.server');
}
return cachedWebServer ? cachedWebServer.instance : null;
}
const PREDEFINED_MCI_GENERATORS = {
//
// Board
@ -133,6 +145,17 @@ const PREDEFINED_MCI_GENERATORS = {
UR: function realName(client) {
return userStatAsString(client, UserProps.RealName, '');
},
AS: function activityPubSubjectName(client) {
const activityPubSettings = ActivityPubSettings.fromUser(client.user);
if (!activityPubSettings.enabled) {
return '(disabled)';
}
const webServer = getWebServer();
if (!webServer) {
return 'N/A';
}
return userNameToSubject(client.user.username, webServer);
},
LO: function location(client) {
return userStatAsString(client, UserProps.Location, '');
},

View File

@ -87,6 +87,10 @@ ToggleMenuView.prototype.setFalse = function () {
this.updateSelection();
};
ToggleMenuView.prototype.isTrue = function () {
return this.focusedItemIndex === 0;
};
ToggleMenuView.prototype.setFromBoolean = function (bool) {
return bool ? this.setTrue() : this.setFalse();
};

View File

@ -39,6 +39,7 @@ There are many predefined MCI codes that can be used anywhere on the system (pla
| `UI` | Current user's user ID |
| `UG` | Current user's group membership(s) |
| `UR` | Current user's real name |
| `AS` | ActivityPub subject, ie: "@SomeUser@yourhost.com", "(disabled)" if AP is not enabled for the user |
| `LO` | Current user's location |
| `UA` | Current user's age |
| `BD` | Current user's birthday (using theme date format) |