mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
Fullname in notifications (#10157)
* init - fullname notifications setting * fullname in topic reply * fullname for group-request-membership * fullname for group-leave notification * fullname for new-post-flag & new-user-flag * removed log * fullname for user follow * fullname in message notification * fullname in follow * fullname for sendNotificationToPostOwner * fullname in sendNotificationToTopicOwner * fullname in doExport * shorthand name set * shorter name set * fullname in notifications * displayname for notifications * removed unused require
This commit is contained in:
@@ -171,10 +171,11 @@ groupsAPI.leave = async function (caller, data) {
|
|||||||
throw new Error('[[error:no-privileges]]');
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
const username = await user.getUserField(data.uid, 'username');
|
const { displayname } = await user.getUserFields(data.uid, ['username']);
|
||||||
|
|
||||||
const notification = await notifications.create({
|
const notification = await notifications.create({
|
||||||
type: 'group-leave',
|
type: 'group-leave',
|
||||||
bodyShort: `[[groups:membership.leave.notification_title, ${username}, ${groupName}]]`,
|
bodyShort: `[[groups:membership.leave.notification_title, ${displayname}, ${groupName}]]`,
|
||||||
nid: `group:${validator.escape(groupName)}:uid:${data.uid}:group-leave`,
|
nid: `group:${validator.escape(groupName)}:uid:${data.uid}:group-leave`,
|
||||||
path: `/groups/${slugify(groupName)}`,
|
path: `/groups/${slugify(groupName)}`,
|
||||||
from: data.uid,
|
from: data.uid,
|
||||||
|
|||||||
@@ -137,9 +137,11 @@ usersAPI.follow = async function (caller, data) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userData = await user.getUserFields(caller.uid, ['username', 'userslug']);
|
const userData = await user.getUserFields(caller.uid, ['username', 'userslug']);
|
||||||
|
const { displayname } = userData;
|
||||||
|
|
||||||
const notifObj = await notifications.create({
|
const notifObj = await notifications.create({
|
||||||
type: 'follow',
|
type: 'follow',
|
||||||
bodyShort: `[[notifications:user_started_following_you, ${userData.username}]]`,
|
bodyShort: `[[notifications:user_started_following_you, ${displayname}]]`,
|
||||||
nid: `follow:${data.uid}:uid:${caller.uid}`,
|
nid: `follow:${data.uid}:uid:${caller.uid}`,
|
||||||
from: caller.uid,
|
from: caller.uid,
|
||||||
path: `/uid/${data.uid}/followers`,
|
path: `/uid/${data.uid}/followers`,
|
||||||
|
|||||||
@@ -736,6 +736,9 @@ Flags.notify = async function (flagObj, uid) {
|
|||||||
]);
|
]);
|
||||||
let uids = admins.concat(globalMods);
|
let uids = admins.concat(globalMods);
|
||||||
let notifObj = null;
|
let notifObj = null;
|
||||||
|
|
||||||
|
const { displayname } = flagObj.reports[flagObj.reports.length - 1].reporter;
|
||||||
|
|
||||||
if (flagObj.type === 'post') {
|
if (flagObj.type === 'post') {
|
||||||
const [title, cid] = await Promise.all([
|
const [title, cid] = await Promise.all([
|
||||||
topics.getTitleByPid(flagObj.targetId),
|
topics.getTitleByPid(flagObj.targetId),
|
||||||
@@ -747,7 +750,7 @@ Flags.notify = async function (flagObj, uid) {
|
|||||||
|
|
||||||
notifObj = await notifications.create({
|
notifObj = await notifications.create({
|
||||||
type: 'new-post-flag',
|
type: 'new-post-flag',
|
||||||
bodyShort: `[[notifications:user_flagged_post_in, ${flagObj.reports[flagObj.reports.length - 1].reporter.username}, ${titleEscaped}]]`,
|
bodyShort: `[[notifications:user_flagged_post_in, ${displayname}, ${titleEscaped}]]`,
|
||||||
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
|
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
|
||||||
pid: flagObj.targetId,
|
pid: flagObj.targetId,
|
||||||
path: `/flags/${flagObj.flagId}`,
|
path: `/flags/${flagObj.flagId}`,
|
||||||
@@ -760,7 +763,7 @@ Flags.notify = async function (flagObj, uid) {
|
|||||||
} else if (flagObj.type === 'user') {
|
} else if (flagObj.type === 'user') {
|
||||||
notifObj = await notifications.create({
|
notifObj = await notifications.create({
|
||||||
type: 'new-user-flag',
|
type: 'new-user-flag',
|
||||||
bodyShort: `[[notifications:user_flagged_user, ${flagObj.reports[flagObj.reports.length - 1].reporter.username}, ${flagObj.target.username}]]`,
|
bodyShort: `[[notifications:user_flagged_user, ${displayname}, ${flagObj.target.user.displayname}]]`,
|
||||||
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
|
bodyLong: await plugins.hooks.fire('filter:parse.raw', String(flagObj.description || '')),
|
||||||
path: `/flags/${flagObj.flagId}`,
|
path: `/flags/${flagObj.flagId}`,
|
||||||
nid: `flag:user:${flagObj.targetId}`,
|
nid: `flag:user:${flagObj.targetId}`,
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ const notifications = require('../notifications');
|
|||||||
module.exports = function (Groups) {
|
module.exports = function (Groups) {
|
||||||
Groups.requestMembership = async function (groupName, uid) {
|
Groups.requestMembership = async function (groupName, uid) {
|
||||||
await inviteOrRequestMembership(groupName, uid, 'request');
|
await inviteOrRequestMembership(groupName, uid, 'request');
|
||||||
const username = await user.getUserField(uid, 'username');
|
const { displayname } = await user.getUserFields(uid, ['username']);
|
||||||
|
|
||||||
const [notification, owners] = await Promise.all([
|
const [notification, owners] = await Promise.all([
|
||||||
notifications.create({
|
notifications.create({
|
||||||
type: 'group-request-membership',
|
type: 'group-request-membership',
|
||||||
bodyShort: `[[groups:request.notification_title, ${username}]]`,
|
bodyShort: `[[groups:request.notification_title, ${displayname}]]`,
|
||||||
bodyLong: `[[groups:request.notification_text, ${username}, ${groupName}]]`,
|
bodyLong: `[[groups:request.notification_text, ${displayname}, ${groupName}]]`,
|
||||||
nid: `group:${groupName}:uid:${uid}:request`,
|
nid: `group:${groupName}:uid:${uid}:request`,
|
||||||
path: `/groups/${slugify(groupName)}`,
|
path: `/groups/${slugify(groupName)}`,
|
||||||
from: uid,
|
from: uid,
|
||||||
|
|||||||
@@ -57,11 +57,13 @@ module.exports = function (Messaging) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { displayname } = messageObj.fromUser;
|
||||||
|
|
||||||
const isGroupChat = await Messaging.isGroupChat(roomId);
|
const isGroupChat = await Messaging.isGroupChat(roomId);
|
||||||
const notification = await notifications.create({
|
const notification = await notifications.create({
|
||||||
type: isGroupChat ? 'new-group-chat' : 'new-chat',
|
type: isGroupChat ? 'new-group-chat' : 'new-chat',
|
||||||
subject: `[[email:notif.chat.subject, ${messageObj.fromUser.username}]]`,
|
subject: `[[email:notif.chat.subject, ${displayname}]]`,
|
||||||
bodyShort: `[[notifications:new_message_from, ${messageObj.fromUser.username}]]`,
|
bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
|
||||||
bodyLong: messageObj.content,
|
bodyLong: messageObj.content,
|
||||||
nid: `chat_${fromuid}_${roomId}`,
|
nid: `chat_${fromuid}_${roomId}`,
|
||||||
from: fromuid,
|
from: fromuid,
|
||||||
|
|||||||
@@ -80,18 +80,20 @@ SocketHelpers.sendNotificationToPostOwner = async function (pid, fromuid, comman
|
|||||||
if (!canRead || isIgnoring[0] || !postData.uid || fromuid === postData.uid) {
|
if (!canRead || isIgnoring[0] || !postData.uid || fromuid === postData.uid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const [username, topicTitle, postObj] = await Promise.all([
|
const [userData, topicTitle, postObj] = await Promise.all([
|
||||||
user.getUserField(fromuid, 'username'),
|
user.getUserFields(fromuid, ['username']),
|
||||||
topics.getTopicField(postData.tid, 'title'),
|
topics.getTopicField(postData.tid, 'title'),
|
||||||
posts.parsePost(postData),
|
posts.parsePost(postData),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const { displayname } = userData;
|
||||||
|
|
||||||
const title = utils.decodeHTMLEntities(topicTitle);
|
const title = utils.decodeHTMLEntities(topicTitle);
|
||||||
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
||||||
|
|
||||||
const notifObj = await notifications.create({
|
const notifObj = await notifications.create({
|
||||||
type: command,
|
type: command,
|
||||||
bodyShort: `[[${notification}, ${username}, ${titleEscaped}]]`,
|
bodyShort: `[[${notification}, ${displayname}, ${titleEscaped}]]`,
|
||||||
bodyLong: postObj.content,
|
bodyLong: postObj.content,
|
||||||
pid: pid,
|
pid: pid,
|
||||||
tid: postData.tid,
|
tid: postData.tid,
|
||||||
@@ -113,20 +115,23 @@ SocketHelpers.sendNotificationToTopicOwner = async function (tid, fromuid, comma
|
|||||||
|
|
||||||
fromuid = parseInt(fromuid, 10);
|
fromuid = parseInt(fromuid, 10);
|
||||||
|
|
||||||
const [username, topicData] = await Promise.all([
|
const [userData, topicData] = await Promise.all([
|
||||||
user.getUserField(fromuid, 'username'),
|
user.getUserFields(fromuid, ['username']),
|
||||||
topics.getTopicFields(tid, ['uid', 'slug', 'title']),
|
topics.getTopicFields(tid, ['uid', 'slug', 'title']),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (fromuid === topicData.uid) {
|
if (fromuid === topicData.uid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { displayname } = userData;
|
||||||
|
|
||||||
const ownerUid = topicData.uid;
|
const ownerUid = topicData.uid;
|
||||||
const title = utils.decodeHTMLEntities(topicData.title);
|
const title = utils.decodeHTMLEntities(topicData.title);
|
||||||
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
||||||
|
|
||||||
const notifObj = await notifications.create({
|
const notifObj = await notifications.create({
|
||||||
bodyShort: `[[${notification}, ${username}, ${titleEscaped}]]`,
|
bodyShort: `[[${notification}, ${displayname}, ${titleEscaped}]]`,
|
||||||
path: `/topic/${topicData.slug}`,
|
path: `/topic/${topicData.slug}`,
|
||||||
nid: `${command}:tid:${tid}:uid:${fromuid}`,
|
nid: `${command}:tid:${tid}:uid:${fromuid}`,
|
||||||
from: fromuid,
|
from: fromuid,
|
||||||
|
|||||||
@@ -93,8 +93,9 @@ module.exports = function (SocketUser) {
|
|||||||
child.on('exit', async () => {
|
child.on('exit', async () => {
|
||||||
await db.deleteObjectField('locks', `export:${data.uid}${type}`);
|
await db.deleteObjectField('locks', `export:${data.uid}${type}`);
|
||||||
const userData = await user.getUserFields(data.uid, ['username', 'userslug']);
|
const userData = await user.getUserFields(data.uid, ['username', 'userslug']);
|
||||||
|
const { displayname } = userData;
|
||||||
const n = await notifications.create({
|
const n = await notifications.create({
|
||||||
bodyShort: `[[notifications:${type}-exported, ${userData.username}]]`,
|
bodyShort: `[[notifications:${type}-exported, ${displayname}]]`,
|
||||||
path: `/api/user/${userData.userslug}/export/${type}`,
|
path: `/api/user/${userData.userslug}/export/${type}`,
|
||||||
nid: `${type}:export:${data.uid}`,
|
nid: `${type}:export:${data.uid}`,
|
||||||
from: data.uid,
|
from: data.uid,
|
||||||
|
|||||||
@@ -192,9 +192,11 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parseInt(uid, 10) || meta.config.allowGuestReplyNotifications) {
|
if (parseInt(uid, 10) || meta.config.allowGuestReplyNotifications) {
|
||||||
|
const { displayname } = postData.user;
|
||||||
|
|
||||||
Topics.notifyFollowers(postData, uid, {
|
Topics.notifyFollowers(postData, uid, {
|
||||||
type: 'new-reply',
|
type: 'new-reply',
|
||||||
bodyShort: translator.compile('notifications:user_posted_to', postData.user.username, postData.topic.title),
|
bodyShort: translator.compile('notifications:user_posted_to', displayname, postData.topic.title),
|
||||||
nid: `new_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`,
|
nid: `new_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`,
|
||||||
mergeId: `notifications:user_posted_to|${postData.topic.tid}`,
|
mergeId: `notifications:user_posted_to|${postData.topic.tid}`,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicD
|
|||||||
|
|
||||||
const notifObj = await notifications.create({
|
const notifObj = await notifications.create({
|
||||||
type: 'new-topic',
|
type: 'new-topic',
|
||||||
bodyShort: `[[notifications:user_posted_topic, ${postData.user.username}, ${title}]]`,
|
bodyShort: `[[notifications:user_posted_topic, ${postData.user.displayname}, ${title}]]`,
|
||||||
bodyLong: postData.content,
|
bodyLong: postData.content,
|
||||||
pid: postData.pid,
|
pid: postData.pid,
|
||||||
path: `/post/${postData.pid}`,
|
path: `/post/${postData.pid}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user