Bunch more removals of unneeded webServer instance

This commit is contained in:
Bryan Ashby 2023-03-18 14:58:37 -06:00
parent fb02fc599a
commit 26c44b91a6
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
13 changed files with 73 additions and 80 deletions

View File

@ -17,9 +17,9 @@ module.exports = class Activity extends ActivityPubObject {
return new Activity(obj); return new Activity(obj);
} }
static makeFollow(webServer, localActor, remoteActor) { static makeFollow(localActor, remoteActor) {
return new Activity({ return new Activity({
id: Activity.activityObjectId(webServer), id: Activity.activityObjectId(),
type: WellKnownActivity.Follow, type: WellKnownActivity.Follow,
actor: localActor, actor: localActor,
object: remoteActor.id, object: remoteActor.id,
@ -27,19 +27,19 @@ module.exports = class Activity extends ActivityPubObject {
} }
// https://www.w3.org/TR/activitypub/#accept-activity-inbox // https://www.w3.org/TR/activitypub/#accept-activity-inbox
static makeAccept(webServer, localActor, followRequest) { static makeAccept(localActor, followRequest) {
return new Activity({ return new Activity({
id: Activity.activityObjectId(webServer), id: Activity.activityObjectId(),
type: WellKnownActivity.Accept, type: WellKnownActivity.Accept,
actor: localActor, actor: localActor,
object: followRequest, // previous request Activity object: followRequest, // previous request Activity
}); });
} }
static makeCreate(webServer, actor, obj, context) { static makeCreate(actor, obj, context) {
const activity = new Activity( const activity = new Activity(
{ {
id: Activity.activityObjectId(webServer), id: Activity.activityObjectId(),
to: obj.to, to: obj.to,
type: WellKnownActivity.Create, type: WellKnownActivity.Create,
actor, actor,
@ -76,7 +76,7 @@ module.exports = class Activity extends ActivityPubObject {
return recipientIdsFromObject(this); return recipientIdsFromObject(this);
} }
static activityObjectId(webServer) { static activityObjectId() {
return ActivityPubObject.makeObjectId(webServer, 'activity'); return ActivityPubObject.makeObjectId('activity');
} }
}; };

View File

@ -80,7 +80,7 @@ module.exports = class Actor extends ActivityPubObject {
]; ];
} }
static fromLocalUser(user, webServer, cb) { static fromLocalUser(user, cb) {
const userActorId = user.getProperty(UserProps.ActivityPubActorId); const userActorId = user.getProperty(UserProps.ActivityPubActorId);
if (!userActorId) { if (!userActorId) {
return cb( return cb(

View File

@ -256,8 +256,8 @@ exports.getModule = class ActivityPubActorSearch extends MenuModule {
const actor = this._getSelectedActor(); // actor info -> actor const actor = this._getSelectedActor(); // actor info -> actor
return this.selectedActorInfo._isFollowing return this.selectedActorInfo._isFollowing
? sendFollowRequest(this.client.user, actor, this.webServer, finish) ? sendFollowRequest(this.client.user, actor, finish)
: sendUnfollowRequest(this.client.user, actor, this.webServer, finish); : sendUnfollowRequest(this.client.user, actor, finish);
} }
_getSelectedActor() { _getSelectedActor() {

View File

@ -83,7 +83,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
static addFollower(owningUser, followingActor, webServer, ignoreDupes, cb) { static addFollower(owningUser, followingActor, ignoreDupes, cb) {
const collectionId = Endpoints.followers(owningUser); const collectionId = Endpoints.followers(owningUser);
return Collection.addToCollection( return Collection.addToCollection(
Collections.Followers, Collections.Followers,
@ -97,7 +97,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
static addFollowRequest(owningUser, requestingActor, webServer, ignoreDupes, cb) { static addFollowRequest(owningUser, requestingActor, ignoreDupes, cb) {
const collectionId = Endpoints.makeUserUrl(owningUser) + 'follow-requests'; const collectionId = Endpoints.makeUserUrl(owningUser) + 'follow-requests';
return Collection.addToCollection( return Collection.addToCollection(
Collections.FollowRequests, Collections.FollowRequests,
@ -111,7 +111,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
static addFollowing(owningUser, followingActor, webServer, ignoreDupes, cb) { static addFollowing(owningUser, followingActor, ignoreDupes, cb) {
const collectionId = Endpoints.following(owningUser); const collectionId = Endpoints.following(owningUser);
return Collection.addToCollection( return Collection.addToCollection(
Collections.Following, Collections.Following,
@ -125,7 +125,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
static addOutboxItem(owningUser, outboxItem, isPrivate, webServer, ignoreDupes, cb) { static addOutboxItem(owningUser, outboxItem, isPrivate, ignoreDupes, cb) {
const collectionId = Endpoints.outbox(owningUser); const collectionId = Endpoints.outbox(owningUser);
return Collection.addToCollection( return Collection.addToCollection(
Collections.Outbox, Collections.Outbox,
@ -139,7 +139,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
static addInboxItem(inboxItem, owningUser, webServer, ignoreDupes, cb) { static addInboxItem(inboxItem, owningUser, ignoreDupes, cb) {
const collectionId = Endpoints.inbox(owningUser); const collectionId = Endpoints.inbox(owningUser);
return Collection.addToCollection( return Collection.addToCollection(
Collections.Inbox, Collections.Inbox,
@ -483,7 +483,6 @@ module.exports = class Collection extends ActivityPubObject {
includePrivate, includePrivate,
page, page,
mapper, mapper,
webServer,
cb cb
) { ) {
const privateQuery = includePrivate ? '' : ' AND is_private = FALSE'; const privateQuery = includePrivate ? '' : ' AND is_private = FALSE';

View File

@ -7,7 +7,7 @@ const Collection = require('./collection');
exports.sendFollowRequest = sendFollowRequest; exports.sendFollowRequest = sendFollowRequest;
exports.sendUnfollowRequest = sendUnfollowRequest; exports.sendUnfollowRequest = sendUnfollowRequest;
function sendFollowRequest(fromUser, toActor, webServer, cb) { function sendFollowRequest(fromUser, toActor, cb) {
const fromActorId = fromUser.getProperty(UserProps.ActivityPubActorId); const fromActorId = fromUser.getProperty(UserProps.ActivityPubActorId);
if (!fromActorId) { if (!fromActorId) {
return cb( return cb(
@ -21,23 +21,23 @@ function sendFollowRequest(fromUser, toActor, webServer, cb) {
// We expect an async follow up request to our server of // We expect an async follow up request to our server of
// Accept or Reject but it's not guaranteed // Accept or Reject but it's not guaranteed
const followRequest = new ActivityPubObject({ const followRequest = new ActivityPubObject({
id: ActivityPubObject.makeObjectId(webServer, 'follow'), id: ActivityPubObject.makeObjectId('follow'),
type: WellKnownActivity.Follow, type: WellKnownActivity.Follow,
actor: fromActorId, actor: fromActorId,
object: toActor.id, object: toActor.id,
}); });
toActor._followRequest = followRequest; toActor._followRequest = followRequest;
Collection.addFollowing(fromUser, toActor, webServer, true, err => { Collection.addFollowing(fromUser, toActor, true, err => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
return followRequest.sendTo(toActor.inbox, fromUser, webServer, cb); return followRequest.sendTo(toActor.inbox, fromUser, cb);
}); });
} }
function sendUnfollowRequest(fromUser, toActor, webServer, cb) { function sendUnfollowRequest(fromUser, toActor, cb) {
const fromActorId = fromUser.getProperty(UserProps.ActivityPubActorId); const fromActorId = fromUser.getProperty(UserProps.ActivityPubActorId);
if (!fromActorId) { if (!fromActorId) {
return cb( return cb(
@ -69,13 +69,13 @@ function sendUnfollowRequest(fromUser, toActor, webServer, cb) {
} }
const undoRequest = new ActivityPubObject({ const undoRequest = new ActivityPubObject({
id: ActivityPubObject.makeObjectId(webServer, 'undo'), id: ActivityPubObject.makeObjectId('undo'),
type: WellKnownActivity.Undo, type: WellKnownActivity.Undo,
actor: fromActorId, actor: fromActorId,
object: followedActor._followRequest, object: followedActor._followRequest,
}); });
return undoRequest.sendTo(toActor.inbox, fromUser, webServer, cb); return undoRequest.sendTo(toActor.inbox, fromUser, cb);
} }
); );
} }

View File

@ -83,7 +83,7 @@ module.exports = class Note extends ActivityPubObject {
return User.getUser(localUserId, callback); return User.getUser(localUserId, callback);
}, },
(fromUser, callback) => { (fromUser, callback) => {
Actor.fromLocalUser(fromUser, webServer, (err, fromActor) => { Actor.fromLocalUser(fromUser, (err, fromActor) => {
return callback(err, fromUser, fromActor); return callback(err, fromUser, fromActor);
}); });
}, },
@ -128,7 +128,7 @@ module.exports = class Note extends ActivityPubObject {
// https://docs.joinmastodon.org/spec/activitypub/#properties-used // https://docs.joinmastodon.org/spec/activitypub/#properties-used
const obj = { const obj = {
id: ActivityPubObject.makeObjectId(webServer, 'note'), id: ActivityPubObject.makeObjectId('note'),
type: 'Note', type: 'Note',
published: getISOTimestampString(message.modTimestamp), published: getISOTimestampString(message.modTimestamp),
to, to,

View File

@ -83,11 +83,11 @@ module.exports = class ActivityPubObject {
this['@context'] = context; this['@context'] = context;
} }
static makeObjectId(webServer, objectType) { static makeObjectId(objectType) {
return Endpoints.objectId(objectType); return Endpoints.objectId(objectType);
} }
sendTo(inboxEndpoint, fromUser, webServer, cb) { sendTo(inboxEndpoint, fromUser, cb) {
const privateKey = fromUser.getProperty(UserProps.PrivateActivityPubSigningKey); const privateKey = fromUser.getProperty(UserProps.PrivateActivityPubSigningKey);
if (isEmpty(privateKey)) { if (isEmpty(privateKey)) {
return cb( return cb(

View File

@ -280,8 +280,8 @@ exports.getModule = class activityPubSocialManager extends MenuModule {
const actor = this._actorInfoToActor(actorInfo); const actor = this._actorInfoToActor(actorInfo);
return wantsToFollow return wantsToFollow
? sendFollowRequest(this.client.user, actor, this.webServer, cb) ? sendFollowRequest(this.client.user, actor, cb)
: sendUnfollowRequest(this.client.user, actor, this.webServer, cb); : sendUnfollowRequest(this.client.user, actor, cb);
} }
_actorInfoToActor(actorInfo) { _actorInfoToActor(actorInfo) {
@ -339,7 +339,7 @@ exports.getModule = class activityPubSocialManager extends MenuModule {
} }
_fetchActorList(collectionName, cb) { _fetchActorList(collectionName, cb) {
const collectionId = Endpoints[collectionName](this.webServer, this.client.user); const collectionId = Endpoints[collectionName](this.client.user);
Collection[collectionName](collectionId, 'all', (err, collection) => { Collection[collectionName](collectionId, 'all', (err, collection) => {
if (err) { if (err) {
return cb(err); return cb(err);

View File

@ -99,7 +99,6 @@ function userFromActorId(actorId, cb) {
} }
function getUserProfileTemplatedBody( function getUserProfileTemplatedBody(
webServer,
templateFile, templateFile,
user, user,
userAsActor, userAsActor,
@ -147,7 +146,7 @@ function getUserProfileTemplatedBody(
const varMap = { const varMap = {
ACTOR_OBJ: JSON.stringify(userAsActor), ACTOR_OBJ: JSON.stringify(userAsActor),
SUBJECT: userNameToSubject(user.username, webServer), SUBJECT: userNameToSubject(user.username),
INBOX: userAsActor.inbox, INBOX: userAsActor.inbox,
SHARED_INBOX: userAsActor.endpoints.sharedInbox, SHARED_INBOX: userAsActor.endpoints.sharedInbox,
OUTBOX: userAsActor.outbox, OUTBOX: userAsActor.outbox,

View File

@ -321,6 +321,14 @@ module.exports = () => {
nodeInfo2: { nodeInfo2: {
enabled: true, enabled: true,
}, },
webFinger: {
enabled: false,
profileTemplate: './wf/profile.template.html',
},
activityPub: {
enabled: false,
selfTemplate: './wf/profile.template.html',
},
}, },
resetPassword: { resetPassword: {

View File

@ -125,7 +125,6 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
} }
const activity = Activity.makeCreate( const activity = Activity.makeCreate(
this._webServer(),
note.attributedTo, note.attributedTo,
note, note,
context context
@ -143,42 +142,37 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
allEndpoints, allEndpoints,
4, 4,
(inbox, nextInbox) => { (inbox, nextInbox) => {
activity.sendTo( activity.sendTo(inbox, fromUser, (err, respBody, res) => {
inbox, if (err) {
fromUser, this.log.warn(
this._webServer(), {
(err, respBody, res) => { inbox,
if (err) { error: err.message,
this.log.warn( },
{ 'Failed to send "Note" Activity to Inbox'
inbox, );
error: err.message, } else if (
}, res.statusCode === 200 ||
'Failed to send "Note" Activity to Inbox' res.statusCode === 202
); ) {
} else if ( this.log.debug(
res.statusCode === 200 || { inbox, uuid: message.uuid },
res.statusCode === 202 'Message delivered to Inbox'
) { );
this.log.debug( } else {
{ inbox, uuid: message.uuid }, this.log.warn(
'Message delivered to Inbox' {
); inbox,
} else { statusCode: res.statusCode,
this.log.warn( body: _.truncate(respBody, 128),
{ },
inbox, 'Unexpected status code'
statusCode: res.statusCode, );
body: _.truncate(respBody, 128),
},
'Unexpected status code'
);
}
// If we can't send now, no harm, we'll record to the outbox
return nextInbox(null);
} }
);
// If we can't send now, no harm, we'll record to the outbox
return nextInbox(null);
});
}, },
() => { () => {
return callback(null, activity, fromUser, note); return callback(null, activity, fromUser, note);
@ -190,7 +184,6 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
fromUser, fromUser,
activity, activity,
message.isPrivate(), message.isPrivate(),
this._webServer(),
false, // do not ignore dupes false, // do not ignore dupes
(err, localId) => { (err, localId) => {
if (!err) { if (!err) {

View File

@ -201,7 +201,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return this.webServer.resourceNotFound(resp); return this.webServer.resourceNotFound(resp);
} }
Actor.fromLocalUser(localUser, this.webServer, (err, localActor) => { Actor.fromLocalUser(localUser, (err, localActor) => {
if (err) { if (err) {
return this.webServer.internalServerError(resp, err); return this.webServer.internalServerError(resp, err);
} }
@ -715,7 +715,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
Collection.addFollowRequest( Collection.addFollowRequest(
localUser, localUser,
remoteActor, remoteActor,
this.webServer,
true, // ignore dupes true, // ignore dupes
err => { err => {
if (err) { if (err) {
@ -924,7 +923,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
'Delivering Note to local Actor Private inbox' 'Delivering Note to local Actor Private inbox'
); );
Collection.addInboxItem(activity, localUser, this.webServer, false, err => { Collection.addInboxItem(activity, localUser, false, err => {
if (err) { if (err) {
return cb(err); return cb(err);
} }
@ -1059,13 +1058,12 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
return Collection.addFollower( return Collection.addFollower(
localUser, localUser,
remoteActor, remoteActor,
this.webServer,
true, // ignore dupes true, // ignore dupes
callback callback
); );
}, },
callback => { callback => {
Actor.fromLocalUser(localUser, this.webServer, (err, localActor) => { Actor.fromLocalUser(localUser, (err, localActor) => {
if (err) { if (err) {
this.log.warn( this.log.warn(
{ inbox: remoteActor.inbox, error: err.message }, { inbox: remoteActor.inbox, error: err.message },
@ -1075,7 +1073,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
const accept = Activity.makeAccept( const accept = Activity.makeAccept(
this.webServer,
localActor.id, localActor.id,
requestActivity requestActivity
); );
@ -1083,7 +1080,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
accept.sendTo( accept.sendTo(
remoteActor.inbox, remoteActor.inbox,
localUser, localUser,
this.webServer,
(err, respBody, res) => { (err, respBody, res) => {
if (err) { if (err) {
this.log.warn( this.log.warn(
@ -1152,7 +1148,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
// we'll fall back to the same default profile info as the WebFinger profile // we'll fall back to the same default profile info as the WebFinger profile
getUserProfileTemplatedBody( getUserProfileTemplatedBody(
this.webServer,
templateFile, templateFile,
localUser, localUser,
localActor, localActor,

View File

@ -99,13 +99,12 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
templateFile = this.webServer.resolveTemplatePath(templateFile); templateFile = this.webServer.resolveTemplatePath(templateFile);
} }
Actor.fromLocalUser(localUser, this.webServer, (err, localActor) => { Actor.fromLocalUser(localUser, (err, localActor) => {
if (err) { if (err) {
return this.webServer.internalServerError(resp, err); return this.webServer.internalServerError(resp, err);
} }
getUserProfileTemplatedBody( getUserProfileTemplatedBody(
this.webServer,
templateFile, templateFile,
localUser, localUser,
localActor, localActor,