From 55c5588a4bf744a014313b637462829b65600aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 5 Aug 2022 08:11:11 -0400 Subject: [PATCH] fix: don't crash if target/user is undefined Error: TypeError: Cannot read properties of undefined (reading 'displayname') File: Flags.notify (/usr/src/app/src/flags.js:812:89) --- src/flags.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/flags.js b/src/flags.js index b5e3c53b64..cca52bb292 100644 --- a/src/flags.js +++ b/src/flags.js @@ -829,9 +829,10 @@ Flags.notify = async function (flagObj, uid, notifySelf = false) { }); uids = uids.concat(modUids[0]); } else if (flagObj.type === 'user') { + const targetDisplayname = flagObj.target && flagObj.target.user ? flagObj.target.user.displayname : '[[global:guest]]'; notifObj = await notifications.create({ type: 'new-user-flag', - bodyShort: `[[notifications:user_flagged_user, ${displayname}, ${flagObj.target.user.displayname}]]`, + bodyShort: `[[notifications:user_flagged_user, ${displayname}, ${targetDisplayname}]]`, bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')), path: `/flags/${flagObj.flagId}`, nid: `flag:user:${flagObj.targetId}`,