fix: inReplyTo incorrectly including system messages, #12834

This commit is contained in:
Julian Lam
2024-10-10 12:36:25 -04:00
parent ca683c6d52
commit 7ad7bc4743

View File

@@ -485,8 +485,13 @@ Mocks.notes.private = async ({ messageObj }) => {
if (!inReplyTo) {
// Get immediately preceding message
const index = await db.sortedSetRank(`chat:room:${messageObj.roomId}:mids`, messageObj.mid);
const previousMid = await db.getSortedSetRange(`chat:room:${messageObj.roomId}:mids`, index - 1, index - 1);
inReplyTo = utils.isNumber(previousMid) ? `${nconf.get('url')}/message/${previousMid}` : previousMid;
if (index > 0) {
const mids = await db.getSortedSetRevRange(`chat:room:${messageObj.roomId}:mids`, 1, -1);
let isSystem = await messaging.getMessagesFields(mids, ['system']);
isSystem = isSystem.map(o => o.system);
inReplyTo = mids.reduce((memo, mid, idx) => (memo || (!isSystem[idx] ? mid : undefined)), undefined);
inReplyTo = utils.isNumber(inReplyTo) ? `${nconf.get('url')}/message/${inReplyTo}` : inReplyTo;
}
}
const object = {