A few bugs fixed with Note storage
This commit is contained in:
parent
63cfc904aa
commit
a968f21957
|
@ -5,7 +5,7 @@ const apDb = require('../database').dbs.activitypub;
|
|||
const { getISOTimestampString } = require('../database');
|
||||
const { Errors } = require('../enig_error.js');
|
||||
const {
|
||||
PublicCollectionId: APPublicCollectionId,
|
||||
PublicCollectionId,
|
||||
ActivityStreamMediaType,
|
||||
Collections,
|
||||
ActorCollectionId,
|
||||
|
@ -23,10 +23,6 @@ module.exports = class Collection extends ActivityPubObject {
|
|||
super(obj);
|
||||
}
|
||||
|
||||
static get PublicCollectionId() {
|
||||
return APPublicCollectionId;
|
||||
}
|
||||
|
||||
static getRemoteCollectionStats(collectionUrl, cb) {
|
||||
const headers = {
|
||||
Accept: ActivityStreamMediaType,
|
||||
|
@ -162,7 +158,7 @@ module.exports = class Collection extends ActivityPubObject {
|
|||
return Collection.addToCollection(
|
||||
Collections.SharedInbox,
|
||||
null, // N/A
|
||||
Collection.PublicCollectionId,
|
||||
PublicCollectionId,
|
||||
inboxItem.id,
|
||||
inboxItem,
|
||||
false,
|
||||
|
@ -232,7 +228,7 @@ module.exports = class Collection extends ActivityPubObject {
|
|||
ActorCollectionId,
|
||||
Collections.Actors,
|
||||
getISOTimestampString(),
|
||||
APPublicCollectionId,
|
||||
PublicCollectionId,
|
||||
actor.id,
|
||||
JSON.stringify(actor),
|
||||
false,
|
||||
|
@ -616,7 +612,7 @@ module.exports = class Collection extends ActivityPubObject {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
actorId = Collection.APPublicCollectionId;
|
||||
actorId = PublicCollectionId;
|
||||
}
|
||||
|
||||
isPrivate = isPrivate ? 1 : 0;
|
||||
|
|
|
@ -9,6 +9,7 @@ const {
|
|||
htmlToMessageBody,
|
||||
recipientIdsFromObject,
|
||||
} = require('./util');
|
||||
const { PublicCollectionId } = require('./const');
|
||||
const { isAnsi } = require('../string_util');
|
||||
|
||||
// deps
|
||||
|
@ -118,9 +119,7 @@ module.exports = class Note extends ActivityPubObject {
|
|||
},
|
||||
(replyToNoteId, fromUser, fromActor, remoteActor, callback) => {
|
||||
const to = [
|
||||
message.isPrivate()
|
||||
? remoteActor.id
|
||||
: Collection.PublicCollectionId,
|
||||
message.isPrivate() ? remoteActor.id : PublicCollectionId,
|
||||
];
|
||||
|
||||
const sourceMediaType = isAnsi(message.message)
|
||||
|
|
|
@ -10,6 +10,7 @@ const {
|
|||
ActivityStreamMediaType,
|
||||
WellKnownActivity,
|
||||
Collections,
|
||||
PublicCollectionId,
|
||||
} = require('../../../activitypub/const');
|
||||
const Config = require('../../../config').get;
|
||||
const Activity = require('../../../activitypub/activity');
|
||||
|
@ -381,7 +382,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
recipientActorIds,
|
||||
(actorId, nextActorId) => {
|
||||
switch (actorId) {
|
||||
case Collection.PublicCollectionId:
|
||||
case PublicCollectionId:
|
||||
this._deliverNoteToSharedInbox(activity, note, 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) {
|
||||
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: delete / invalidate any actor cache if actor
|
||||
Collection.objectsById(objectId, (err, objectsInfo) => {
|
||||
|
||||
this._getMatchingObjectsForDeleteRequest(objectId, (err, objectsInfo) => {
|
||||
if (err) {
|
||||
this.log.warn({ objectId });
|
||||
// We'll respond accepted so they don't keep trying
|
||||
|
@ -750,7 +778,10 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
}
|
||||
|
||||
_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 => {
|
||||
if (err) {
|
||||
|
@ -768,16 +799,21 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
}
|
||||
|
||||
_deliverNoteToLocalActor(actorId, activity, note, cb) {
|
||||
this.log.info(
|
||||
{ noteId: note.id, actorId },
|
||||
'Delivering Note to local Actor Private inbox'
|
||||
);
|
||||
|
||||
// Skip over e.g. actorId = https://someethingsomething/users/Actor/followers
|
||||
userFromActorId(actorId, (err, localUser) => {
|
||||
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
|
||||
}
|
||||
|
||||
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 => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
|
|
Loading…
Reference in New Issue