fix: #12865, crash on liking a chat message

This commit is contained in:
Julian Lam
2024-10-25 12:11:37 -04:00
parent 7e450e1d2e
commit fc3243d617
2 changed files with 14 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ const crypto = require('crypto');
const meta = require('../meta'); const meta = require('../meta');
const posts = require('../posts'); const posts = require('../posts');
const categories = require('../categories'); const categories = require('../categories');
const messaging = require('../messaging');
const request = require('../request'); const request = require('../request');
const db = require('../database'); const db = require('../database');
const ttl = require('../cache/ttl'); const ttl = require('../cache/ttl');
@@ -263,6 +264,7 @@ Helpers.resolveObjects = async (ids) => {
} }
return activitypub.mocks.actors.user(resolvedId); return activitypub.mocks.actors.user(resolvedId);
} }
case 'post': { case 'post': {
const post = (await posts.getPostSummaryByPids( const post = (await posts.getPostSummaryByPids(
[resolvedId], [resolvedId],
@@ -277,12 +279,23 @@ Helpers.resolveObjects = async (ids) => {
} }
return activitypub.mocks.notes.public(post); return activitypub.mocks.notes.public(post);
} }
case 'category': { case 'category': {
if (!await categories.exists(resolvedId)) { if (!await categories.exists(resolvedId)) {
throw new Error('[[error:activitypub.invalid-id]]'); throw new Error('[[error:activitypub.invalid-id]]');
} }
return activitypub.mocks.actors.category(resolvedId); return activitypub.mocks.actors.category(resolvedId);
} }
case 'message': {
if (!await messaging.messageExists(resolvedId)) {
throw new Error('[[error:activitypub.invalid-id]]');
}
const messageObj = await messaging.getMessageFields(resolvedId, []);
messageObj.content = await messaging.parse(messageObj.content, messageObj.fromuid, 0, messageObj.roomId, false);
return activitypub.mocks.notes.private({ messageObj });
}
// if the type is not recognized, assume it's not a local ID and fetch the object from its origin // if the type is not recognized, assume it's not a local ID and fetch the object from its origin
default: { default: {
return activitypub.get('uid', 0, id); return activitypub.get('uid', 0, id);

View File

@@ -134,6 +134,7 @@ middleware.resolveObjects = async function (req, res, next) {
return res.sendStatus(424); return res.sendStatus(424);
} }
} }
next(); next();
}; };