Merge branch '459-activitypub-integration' of ssh://numinibsd/git/base/enigma-bbs into 459-activitypub-integration

This commit is contained in:
Bryan Ashby 2023-04-20 20:43:09 -06:00
commit e5fdc2450c
7 changed files with 1438 additions and 226 deletions

View File

@ -20,7 +20,7 @@ const async = require('async');
const { isString, isObject, truncate } = require('lodash'); const { isString, isObject, truncate } = require('lodash');
const PublicMessageIdNamespace = 'a26ae389-5dfb-4b24-a58e-5472085c8e42'; const PublicMessageIdNamespace = 'a26ae389-5dfb-4b24-a58e-5472085c8e42';
const APDefaultSummary = '[ActivityPub]'; const APDefaultSummary = '[No Subject]';
module.exports = class Note extends ActivityPubObject { module.exports = class Note extends ActivityPubObject {
constructor(obj) { constructor(obj) {
@ -202,20 +202,6 @@ module.exports = class Note extends ActivityPubObject {
message.fromUserName = fromActorSubject || this.attributedTo; message.fromUserName = fromActorSubject || this.attributedTo;
//
// Note's can be addressed to 1:N users, but a Message is a 1:1
// relationship. This method requires the mapping up front via options
//
if (isPrivate) {
message.toUserName = options.toUser.username;
message.meta.System[Message.SystemMetaNames.LocalToUserID] =
options.toUser.userId;
} else {
message.toUser = 'All';
}
message.areaTag = options.areaTag || Message.WellKnownAreaTags.Private;
// :TODO: it would be better to do some basic HTML to ANSI or pipe codes perhaps // :TODO: it would be better to do some basic HTML to ANSI or pipe codes perhaps
message.message = htmlToMessageBody( message.message = htmlToMessageBody(
// try to handle various implementations // try to handle various implementations
@ -223,7 +209,11 @@ module.exports = class Note extends ActivityPubObject {
// - https://indieweb.org/post-type-discovery#Algorithm // - https://indieweb.org/post-type-discovery#Algorithm
this.content || this.name || this.summary this.content || this.name || this.summary
); );
message.subject = this._getSubject(message);
this._setToUserName(message, isPrivate, options.toUser);
this._setSubject(message);
message.areaTag = options.areaTag || Message.WellKnownAreaTags.Private;
// List all attachments // List all attachments
if (Array.isArray(this.attachment) && this.attachment.length > 0) { if (Array.isArray(this.attachment) && this.attachment.length > 0) {
@ -396,13 +386,15 @@ module.exports = class Note extends ActivityPubObject {
}); });
} }
_getSubject(message) { _setSubject(message) {
if (this.summary) { if (this.summary) {
return this.summary.trim(); message.subject = this.summary.trim();
return;
} }
if (this.name) { if (this.name) {
return this.name.trim(); message.subject = this.name.trim();
return;
} }
// //
@ -421,6 +413,21 @@ module.exports = class Note extends ActivityPubObject {
subject = truncate(subject, { length: 32, omission: '...' }); subject = truncate(subject, { length: 32, omission: '...' });
subject = subject || APDefaultSummary; subject = subject || APDefaultSummary;
return subject; message.subject = subject;
}
_setToUserName(message, isPrivate, toUser) {
if (isPrivate) {
message.toUserName = toUser.username;
message.meta.System[Message.SystemMetaNames.LocalToUserID] = toUser.userId;
return;
}
const m = /^@([^ ]+) ./.exec(message.message);
if (m && m[1]) {
message.toUserName = m[1];
}
message.toUserName = message.toUserName || 'All';
} }
}; };

View File

@ -2,7 +2,7 @@ const { Errors } = require('./enig_error.js');
// deps // deps
const { isString, isObject, truncate } = require('lodash'); const { isString, isObject, truncate } = require('lodash');
const https = require('https'); const { https } = require('follow-redirects');
const httpSignature = require('http-signature'); const httpSignature = require('http-signature');
const crypto = require('crypto'); const crypto = require('crypto');

View File

@ -994,7 +994,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return cb(err); return cb(err);
} }
message.persist(err => { message.persist((err, messageId) => {
if (!err) { if (!err) {
if (_.isObject(localAddressedTo)) { if (_.isObject(localAddressedTo)) {
localAddressedTo = localAddressedTo.username; localAddressedTo = localAddressedTo.username;
@ -1004,8 +1004,9 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
localAddressedTo, localAddressedTo,
activityId, activityId,
noteId: note.id, noteId: note.id,
messageId,
}, },
'Note delivered as message to private mailbox' 'Note persisted as local Message'
); );
} else if (err.code === 'SQLITE_CONSTRAINT') { } else if (err.code === 'SQLITE_CONSTRAINT') {
return cb(null); return cb(null);

View File

@ -57,7 +57,11 @@ function queryWebFinger(query, cb) {
} }
const contentType = res.headers['content-type'] || ''; const contentType = res.headers['content-type'] || '';
if (!contentType.startsWith('application/jrd+json')) { if (
!['application/jrd+json', 'application/json'].some(ct =>
contentType.startsWith(ct)
)
) {
return cb( return cb(
Errors.Invalid( Errors.Invalid(
`Invalid Content-Type for WebFinger URL ${webFingerUrl}: ${contentType}` `Invalid Content-Type for WebFinger URL ${webFingerUrl}: ${contentType}`

1201
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@
"deepdash": "^5.3.9", "deepdash": "^5.3.9",
"easy-table": "^1.2.0", "easy-table": "^1.2.0",
"exiftool": "^0.0.3", "exiftool": "^0.0.3",
"follow-redirects": "^1.15.2",
"fs-extra": "10.1.0", "fs-extra": "10.1.0",
"glob": "8.0.3", "glob": "8.0.3",
"graceful-fs": "^4.2.10", "graceful-fs": "^4.2.10",

402
yarn.lock

File diff suppressed because it is too large Load Diff