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)
isekai-main
Barış Soner Uşaklı 2 years ago
parent 4586f68eaf
commit 55c5588a4b

@ -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}`,

Loading…
Cancel
Save