Fix up message header for public AP, Undo following, some bugs around following local Actors...

This commit is contained in:
Bryan Ashby 2023-02-24 22:54:19 -07:00
parent 5b08d21966
commit a205445dd1
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
6 changed files with 75 additions and 28 deletions

View File

@ -176,6 +176,10 @@ module.exports = class Actor extends ActivityPubObject {
}
};
if (!id) {
return cb(Errors.Invalid('Invalid Actor ID'));
}
Actor._fromCache(id, (err, actor, subject, needsRefresh) => {
if (!err) {
// cache hit

View File

@ -20,11 +20,6 @@ function sendFollowRequest(fromUser, toActor, webServer, cb) {
// We always add to the following collection;
// We expect an async follow up request to our server of
// Accept or Reject but it's not guaranteed
Collection.addFollowing(fromUser, toActor, webServer, true, err => {
if (err) {
return cb(err);
}
const followRequest = new ActivityPubObject({
id: ActivityPubObject.makeObjectId(webServer, 'follow'),
type: WellKnownActivity.Follow,
@ -32,6 +27,12 @@ function sendFollowRequest(fromUser, toActor, webServer, cb) {
object: toActor.id,
});
toActor._followRequest = followRequest;
Collection.addFollowing(fromUser, toActor, webServer, true, err => {
if (err) {
return cb(err);
}
return followRequest.sendTo(toActor.inbox, fromUser, webServer, cb);
});
}
@ -46,8 +47,23 @@ function sendUnfollowRequest(fromUser, toActor, webServer, cb) {
);
}
// Fetch previously saved 'Follow'; We're going to Undo it &
// need a copy.
Collection.ownedObjectByNameAndId(
Collections.Following,
fromUser,
toActor.id,
(err, followedActor) => {
if (err) {
return cb(err);
}
// Always remove from the local collection, notify the remote server
Collection.removeOwnedById(Collections.Following, fromUser, toActor.inbox, err => {
Collection.removeOwnedById(
Collections.Following,
fromUser,
toActor.id,
err => {
if (err) {
return cb(err);
}
@ -56,9 +72,12 @@ function sendUnfollowRequest(fromUser, toActor, webServer, cb) {
id: ActivityPubObject.makeObjectId(webServer, 'undo'),
type: WellKnownActivity.Undo,
actor: fromActorId,
object: toActor.id,
object: followedActor._followRequest,
});
return undoRequest.sendTo(toActor.inbox, fromUser, webServer, cb);
});
}
);
}
);
}

View File

@ -17,6 +17,7 @@ const { encode, decode } = require('html-entities');
const { isString } = require('lodash');
const { stripHtml } = require('string-strip-html');
exports.getActorId = o => o.actor?.id || o.actor;
exports.parseTimestampOrNow = parseTimestampOrNow;
exports.isValidLink = isValidLink;
exports.userFromActorId = userFromActorId;

View File

@ -37,7 +37,7 @@ const moment = require('moment');
const fse = require('fs-extra');
const fs = require('graceful-fs');
const paths = require('path');
const sanatizeFilename = require('sanitize-filename');
const sanitizeFilename = require('sanitize-filename');
const { ErrorReasons } = require('./enig_error.js');
exports.moduleInfo = {
@ -350,7 +350,7 @@ exports.FullScreenEditorModule =
return {
// :TODO: ensure we show real names for form/to if they are enforced in the area
fromUserName: this.message.fromUserName,
toUserName: this.message.toUserName,
toUserName: this._viewModeToField(),
// :TODO:
//fromRealName
//toRealName
@ -1108,6 +1108,24 @@ exports.FullScreenEditorModule =
this.setViewText('header', id, text);
}
_viewModeToField() {
// Imported messages may have no explicit 'to' on various public forums
if (this.message.toUserName) {
return this.message.toUserName;
}
const toRemoteUser = _.get(this.message, 'meta.System.remote_to_user');
if (toRemoteUser) {
return toRemoteUser;
}
if (this.message.isPublic()) {
return '(Public)';
}
this.menuConfig.config.remoteUserNotAvail || 'N/A';
}
initHeaderViewMode() {
// Only set header text for from view if it is on the form
if (
@ -1115,7 +1133,7 @@ exports.FullScreenEditorModule =
) {
this.setHeaderText(MciViewIds.header.from, this.message.fromUserName);
}
this.setHeaderText(MciViewIds.header.to, this.message.toUserName);
this.setHeaderText(MciViewIds.header.to, this._viewModeToField());
this.setHeaderText(MciViewIds.header.subject, this.message.subject);
this.setHeaderText(
@ -1199,7 +1217,7 @@ exports.FullScreenEditorModule =
const outputFileName = paths.join(
sysTempDownloadDir,
sanatizeFilename(
sanitizeFilename(
`(${msgInfo.messageId}) ${
msgInfo.subject
}_(${this.message.modTimestamp.format('YYYY-MM-DD')}).txt`

View File

@ -91,6 +91,10 @@ module.exports = class Message {
return Message.isPrivateAreaTag(this.areaTag);
}
isPublic() {
return !this.isPrivate();
}
isFromRemoteUser() {
return null !== this.getRemoteFromUser();
}

View File

@ -3,6 +3,7 @@ const {
userFromActorId,
getUserProfileTemplatedBody,
DefaultProfileTemplate,
getActorId,
} = require('../../../activitypub/util');
const Endpoints = require('../../../activitypub/endpoint');
const {
@ -257,7 +258,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
}
// Fetch and validate the signature of the remote Actor
Actor.fromId(activity.actor, (err, remoteActor) => {
Actor.fromId(getActorId(activity), (err, remoteActor) => {
if (err) {
return this.webServer.internalServerError(resp, err);
}
@ -318,7 +319,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
activity
);
} else {
this.log.warn(`Unsupported Undo for type "${type}`);
this.log.warn(`Unsupported Undo for type "${type}"`);
}
}
break;
@ -920,7 +921,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
const accept = Activity.makeAccept(
this.webServer,
localActor,
localActor.id,
requestActivity
);