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

View File

@ -256,8 +256,8 @@ exports.getModule = class ActivityPubActorSearch extends MenuModule {
const actor = this._getSelectedActor(); // actor info -> actor
return this.selectedActorInfo._isFollowing
? sendFollowRequest(this.client.user, actor, this.webServer, finish)
: sendUnfollowRequest(this.client.user, actor, this.webServer, finish);
? sendFollowRequest(this.client.user, actor, finish)
: sendUnfollowRequest(this.client.user, actor, finish);
}
_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);
return Collection.addToCollection(
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';
return Collection.addToCollection(
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);
return Collection.addToCollection(
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);
return Collection.addToCollection(
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);
return Collection.addToCollection(
Collections.Inbox,
@ -483,7 +483,6 @@ module.exports = class Collection extends ActivityPubObject {
includePrivate,
page,
mapper,
webServer,
cb
) {
const privateQuery = includePrivate ? '' : ' AND is_private = FALSE';

View File

@ -7,7 +7,7 @@ const Collection = require('./collection');
exports.sendFollowRequest = sendFollowRequest;
exports.sendUnfollowRequest = sendUnfollowRequest;
function sendFollowRequest(fromUser, toActor, webServer, cb) {
function sendFollowRequest(fromUser, toActor, cb) {
const fromActorId = fromUser.getProperty(UserProps.ActivityPubActorId);
if (!fromActorId) {
return cb(
@ -21,23 +21,23 @@ function sendFollowRequest(fromUser, toActor, webServer, cb) {
// We expect an async follow up request to our server of
// Accept or Reject but it's not guaranteed
const followRequest = new ActivityPubObject({
id: ActivityPubObject.makeObjectId(webServer, 'follow'),
id: ActivityPubObject.makeObjectId('follow'),
type: WellKnownActivity.Follow,
actor: fromActorId,
object: toActor.id,
});
toActor._followRequest = followRequest;
Collection.addFollowing(fromUser, toActor, webServer, true, err => {
Collection.addFollowing(fromUser, toActor, true, err => {
if (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);
if (!fromActorId) {
return cb(
@ -69,13 +69,13 @@ function sendUnfollowRequest(fromUser, toActor, webServer, cb) {
}
const undoRequest = new ActivityPubObject({
id: ActivityPubObject.makeObjectId(webServer, 'undo'),
id: ActivityPubObject.makeObjectId('undo'),
type: WellKnownActivity.Undo,
actor: fromActorId,
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);
},
(fromUser, callback) => {
Actor.fromLocalUser(fromUser, webServer, (err, fromActor) => {
Actor.fromLocalUser(fromUser, (err, fromActor) => {
return callback(err, fromUser, fromActor);
});
},
@ -128,7 +128,7 @@ module.exports = class Note extends ActivityPubObject {
// https://docs.joinmastodon.org/spec/activitypub/#properties-used
const obj = {
id: ActivityPubObject.makeObjectId(webServer, 'note'),
id: ActivityPubObject.makeObjectId('note'),
type: 'Note',
published: getISOTimestampString(message.modTimestamp),
to,

View File

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

View File

@ -280,8 +280,8 @@ exports.getModule = class activityPubSocialManager extends MenuModule {
const actor = this._actorInfoToActor(actorInfo);
return wantsToFollow
? sendFollowRequest(this.client.user, actor, this.webServer, cb)
: sendUnfollowRequest(this.client.user, actor, this.webServer, cb);
? sendFollowRequest(this.client.user, actor, cb)
: sendUnfollowRequest(this.client.user, actor, cb);
}
_actorInfoToActor(actorInfo) {
@ -339,7 +339,7 @@ exports.getModule = class activityPubSocialManager extends MenuModule {
}
_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) => {
if (err) {
return cb(err);

View File

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

View File

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

View File

@ -125,7 +125,6 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
}
const activity = Activity.makeCreate(
this._webServer(),
note.attributedTo,
note,
context
@ -143,42 +142,37 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
allEndpoints,
4,
(inbox, nextInbox) => {
activity.sendTo(
inbox,
fromUser,
this._webServer(),
(err, respBody, res) => {
if (err) {
this.log.warn(
{
inbox,
error: err.message,
},
'Failed to send "Note" Activity to Inbox'
);
} else if (
res.statusCode === 200 ||
res.statusCode === 202
) {
this.log.debug(
{ inbox, uuid: message.uuid },
'Message delivered to Inbox'
);
} else {
this.log.warn(
{
inbox,
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);
activity.sendTo(inbox, fromUser, (err, respBody, res) => {
if (err) {
this.log.warn(
{
inbox,
error: err.message,
},
'Failed to send "Note" Activity to Inbox'
);
} else if (
res.statusCode === 200 ||
res.statusCode === 202
) {
this.log.debug(
{ inbox, uuid: message.uuid },
'Message delivered to Inbox'
);
} else {
this.log.warn(
{
inbox,
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);
});
},
() => {
return callback(null, activity, fromUser, note);
@ -190,7 +184,6 @@ exports.getModule = class ActivityPubScannerTosser extends MessageScanTossModule
fromUser,
activity,
message.isPrivate(),
this._webServer(),
false, // do not ignore dupes
(err, localId) => {
if (!err) {

View File

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

View File

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