From df55c3fa6d0720caa8785fcc6049f041dead3be7 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 11 Feb 2023 20:27:50 -0700 Subject: [PATCH] New MCI for AP subject, show subj and custom info format on config --- .../activitypub_user_config_main.ans | Bin 3177 -> 3193 bytes art/themes/luciano_blocktronics/theme.hjson | 6 ++ core/activitypub/note.js | 2 +- core/activitypub/user_config.js | 57 ++++++++++++++++++ core/activitypub/util.js | 7 ++- core/predefined_mci.js | 23 +++++++ core/toggle_menu_view.js | 4 ++ docs/_docs/art/mci.md | 1 + 8 files changed, 98 insertions(+), 2 deletions(-) diff --git a/art/themes/luciano_blocktronics/activitypub_user_config_main.ans b/art/themes/luciano_blocktronics/activitypub_user_config_main.ans index bd591ead34eb4a3c384ac3200cef33a9c46366ce..91c7f5f00b6641020f0a0da31180885c42c556aa 100644 GIT binary patch delta 46 zcmaDU@l#@h0Xvs;w6RgHYKV`a!Q@5`jmhV@IT`Oyu4R+hT*7{qg~ia2pJ%cwj|u=@ C_6@-R delta 31 ncmew<@ls-g0sCYFR&B=nlWW-|Hn*^!WnnQe{?9!*lt%>sx7`Yp diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index 361f7c3e..45237c24 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -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 + } } } } diff --git a/core/activitypub/note.js b/core/activitypub/note.js index 1d80ed79..185e750f 100644 --- a/core/activitypub/note.js +++ b/core/activitypub/note.js @@ -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}`; } diff --git a/core/activitypub/user_config.js b/core/activitypub/user_config.js index 89525387..220d7f55 100644 --- a/core/activitypub/user_config.js +++ b/core/activitypub/user_config.js @@ -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; + } }; diff --git a/core/activitypub/util.js b/core/activitypub/util.js index 88e249ff..9b1c6eac 100644 --- a/core/activitypub/util.js +++ b/core/activitypub/util.js @@ -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() }; diff --git a/core/predefined_mci.js b/core/predefined_mci.js index 01d81d90..321daec3 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -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, ''); }, diff --git a/core/toggle_menu_view.js b/core/toggle_menu_view.js index ad096152..0e70b94b 100644 --- a/core/toggle_menu_view.js +++ b/core/toggle_menu_view.js @@ -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(); }; diff --git a/docs/_docs/art/mci.md b/docs/_docs/art/mci.md index c1444f18..15b7b673 100644 --- a/docs/_docs/art/mci.md +++ b/docs/_docs/art/mci.md @@ -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) |