A few bugs fixed with Note storage

This commit is contained in:
Bryan Ashby 2023-02-26 21:29:07 -07:00
parent 63cfc904aa
commit a968f21957
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
3 changed files with 50 additions and 19 deletions

View File

@ -5,7 +5,7 @@ const apDb = require('../database').dbs.activitypub;
const { getISOTimestampString } = require('../database'); const { getISOTimestampString } = require('../database');
const { Errors } = require('../enig_error.js'); const { Errors } = require('../enig_error.js');
const { const {
PublicCollectionId: APPublicCollectionId, PublicCollectionId,
ActivityStreamMediaType, ActivityStreamMediaType,
Collections, Collections,
ActorCollectionId, ActorCollectionId,
@ -23,10 +23,6 @@ module.exports = class Collection extends ActivityPubObject {
super(obj); super(obj);
} }
static get PublicCollectionId() {
return APPublicCollectionId;
}
static getRemoteCollectionStats(collectionUrl, cb) { static getRemoteCollectionStats(collectionUrl, cb) {
const headers = { const headers = {
Accept: ActivityStreamMediaType, Accept: ActivityStreamMediaType,
@ -162,7 +158,7 @@ module.exports = class Collection extends ActivityPubObject {
return Collection.addToCollection( return Collection.addToCollection(
Collections.SharedInbox, Collections.SharedInbox,
null, // N/A null, // N/A
Collection.PublicCollectionId, PublicCollectionId,
inboxItem.id, inboxItem.id,
inboxItem, inboxItem,
false, false,
@ -232,7 +228,7 @@ module.exports = class Collection extends ActivityPubObject {
ActorCollectionId, ActorCollectionId,
Collections.Actors, Collections.Actors,
getISOTimestampString(), getISOTimestampString(),
APPublicCollectionId, PublicCollectionId,
actor.id, actor.id,
JSON.stringify(actor), JSON.stringify(actor),
false, false,
@ -616,7 +612,7 @@ module.exports = class Collection extends ActivityPubObject {
); );
} }
} else { } else {
actorId = Collection.APPublicCollectionId; actorId = PublicCollectionId;
} }
isPrivate = isPrivate ? 1 : 0; isPrivate = isPrivate ? 1 : 0;

View File

@ -9,6 +9,7 @@ const {
htmlToMessageBody, htmlToMessageBody,
recipientIdsFromObject, recipientIdsFromObject,
} = require('./util'); } = require('./util');
const { PublicCollectionId } = require('./const');
const { isAnsi } = require('../string_util'); const { isAnsi } = require('../string_util');
// deps // deps
@ -118,9 +119,7 @@ module.exports = class Note extends ActivityPubObject {
}, },
(replyToNoteId, fromUser, fromActor, remoteActor, callback) => { (replyToNoteId, fromUser, fromActor, remoteActor, callback) => {
const to = [ const to = [
message.isPrivate() message.isPrivate() ? remoteActor.id : PublicCollectionId,
? remoteActor.id
: Collection.PublicCollectionId,
]; ];
const sourceMediaType = isAnsi(message.message) const sourceMediaType = isAnsi(message.message)

View File

@ -10,6 +10,7 @@ const {
ActivityStreamMediaType, ActivityStreamMediaType,
WellKnownActivity, WellKnownActivity,
Collections, Collections,
PublicCollectionId,
} = require('../../../activitypub/const'); } = require('../../../activitypub/const');
const Config = require('../../../config').get; const Config = require('../../../config').get;
const Activity = require('../../../activitypub/activity'); const Activity = require('../../../activitypub/activity');
@ -381,7 +382,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
recipientActorIds, recipientActorIds,
(actorId, nextActorId) => { (actorId, nextActorId) => {
switch (actorId) { switch (actorId) {
case Collection.PublicCollectionId: case PublicCollectionId:
this._deliverNoteToSharedInbox(activity, note, err => { this._deliverNoteToSharedInbox(activity, note, err => {
return nextActorId(err); return nextActorId(err);
}); });
@ -436,6 +437,32 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
}); });
} }
_getMatchingObjectsForDeleteRequest(objectId, cb) {
async.waterfall(
[
callback => {
return Collection.objectsById(objectId, callback);
},
(objectsInfo, callback) => {
Collection.objectByEmbeddedId(objectId, (err, obj, objInfo) => {
if (err) {
return callback(err);
}
const allObjsInfo = objectsInfo;
if (obj) {
allObjsInfo.push({ info: objInfo, object: obj });
}
return callback(null, objectsInfo);
});
},
],
(err, objectsInfo) => {
return cb(err, objectsInfo);
}
);
}
_inboxDeleteActivity(inboxType, signature, resp, activity) { _inboxDeleteActivity(inboxType, signature, resp, activity) {
const objectId = _.get(activity, 'object.id', activity.object); const objectId = _.get(activity, 'object.id', activity.object);
@ -443,7 +470,8 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
// :TODO: we need to DELETE the existing stored Message object if this is a Note, or associated if this is an Actor // :TODO: we need to DELETE the existing stored Message object if this is a Note, or associated if this is an Actor
// :TODO: delete / invalidate any actor cache if actor // :TODO: delete / invalidate any actor cache if actor
Collection.objectsById(objectId, (err, objectsInfo) => {
this._getMatchingObjectsForDeleteRequest(objectId, (err, objectsInfo) => {
if (err) { if (err) {
this.log.warn({ objectId }); this.log.warn({ objectId });
// We'll respond accepted so they don't keep trying // We'll respond accepted so they don't keep trying
@ -750,7 +778,10 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
_deliverNoteToSharedInbox(activity, note, cb) { _deliverNoteToSharedInbox(activity, note, cb) {
this.log.info({ noteId: note.id }, 'Delivering Note to Public inbox'); this.log.info(
{ activityId: activity.id, noteId: note.id },
'Delivering Note to Public inbox'
);
Collection.addSharedInboxItem(activity, true, err => { Collection.addSharedInboxItem(activity, true, err => {
if (err) { if (err) {
@ -768,16 +799,21 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
_deliverNoteToLocalActor(actorId, activity, note, cb) { _deliverNoteToLocalActor(actorId, activity, note, cb) {
this.log.info( // Skip over e.g. actorId = https://someethingsomething/users/Actor/followers
{ noteId: note.id, actorId },
'Delivering Note to local Actor Private inbox'
);
userFromActorId(actorId, (err, localUser) => { userFromActorId(actorId, (err, localUser) => {
if (err) { if (err) {
this.log.trace(
{ activityId: activity.id, noteId: note.id, actorId },
`No Actor by ID ${actorId}`
);
return cb(null); // not found/etc., just bail return cb(null); // not found/etc., just bail
} }
this.log.info(
{ activityId: activity.id, noteId: note.id, actorId },
'Delivering Note to local Actor Private inbox'
);
Collection.addInboxItem(activity, localUser, this.webServer, false, err => { Collection.addInboxItem(activity, localUser, this.webServer, false, err => {
if (err) { if (err) {
return cb(err); return cb(err);