mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-04 14:50:47 +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]]');
|
||||
}
|
||||
|
||||
const username = await user.getUserField(data.uid, 'username');
|
||||
const { displayname } = await user.getUserFields(data.uid, ['username']);
|
||||
|
||||
const notification = await notifications.create({
|
||||
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`,
|
||||
path: `/groups/${slugify(groupName)}`,
|
||||
from: data.uid,
|
||||
|
||||
@@ -137,9 +137,11 @@ usersAPI.follow = async function (caller, data) {
|
||||
});
|
||||
|
||||
const userData = await user.getUserFields(caller.uid, ['username', 'userslug']);
|
||||
const { displayname } = userData;
|
||||
|
||||
const notifObj = await notifications.create({
|
||||
type: 'follow',
|
||||
bodyShort: `[[notifications:user_started_following_you, ${userData.username}]]`,
|
||||
bodyShort: `[[notifications:user_started_following_you, ${displayname}]]`,
|
||||
nid: `follow:${data.uid}:uid:${caller.uid}`,
|
||||
from: caller.uid,
|
||||
path: `/uid/${data.uid}/followers`,
|
||||
|
||||
@@ -736,6 +736,9 @@ Flags.notify = async function (flagObj, uid) {
|
||||
]);
|
||||
let uids = admins.concat(globalMods);
|
||||
let notifObj = null;
|
||||
|
||||
const { displayname } = flagObj.reports[flagObj.reports.length - 1].reporter;
|
||||
|
||||
if (flagObj.type === 'post') {
|
||||
const [title, cid] = await Promise.all([
|
||||
topics.getTitleByPid(flagObj.targetId),
|
||||
@@ -747,7 +750,7 @@ Flags.notify = async function (flagObj, uid) {
|
||||
|
||||
notifObj = await notifications.create({
|
||||
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 || '')),
|
||||
pid: flagObj.targetId,
|
||||
path: `/flags/${flagObj.flagId}`,
|
||||
@@ -760,7 +763,7 @@ Flags.notify = async function (flagObj, uid) {
|
||||
} else if (flagObj.type === 'user') {
|
||||
notifObj = await notifications.create({
|
||||
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 || '')),
|
||||
path: `/flags/${flagObj.flagId}`,
|
||||
nid: `flag:user:${flagObj.targetId}`,
|
||||
|
||||
@@ -11,12 +11,13 @@ const notifications = require('../notifications');
|
||||
module.exports = function (Groups) {
|
||||
Groups.requestMembership = async function (groupName, uid) {
|
||||
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([
|
||||
notifications.create({
|
||||
type: 'group-request-membership',
|
||||
bodyShort: `[[groups:request.notification_title, ${username}]]`,
|
||||
bodyLong: `[[groups:request.notification_text, ${username}, ${groupName}]]`,
|
||||
bodyShort: `[[groups:request.notification_title, ${displayname}]]`,
|
||||
bodyLong: `[[groups:request.notification_text, ${displayname}, ${groupName}]]`,
|
||||
nid: `group:${groupName}:uid:${uid}:request`,
|
||||
path: `/groups/${slugify(groupName)}`,
|
||||
from: uid,
|
||||
|
||||
@@ -57,11 +57,13 @@ module.exports = function (Messaging) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { displayname } = messageObj.fromUser;
|
||||
|
||||
const isGroupChat = await Messaging.isGroupChat(roomId);
|
||||
const notification = await notifications.create({
|
||||
type: isGroupChat ? 'new-group-chat' : 'new-chat',
|
||||
subject: `[[email:notif.chat.subject, ${messageObj.fromUser.username}]]`,
|
||||
bodyShort: `[[notifications:new_message_from, ${messageObj.fromUser.username}]]`,
|
||||
subject: `[[email:notif.chat.subject, ${displayname}]]`,
|
||||
bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
|
||||
bodyLong: messageObj.content,
|
||||
nid: `chat_${fromuid}_${roomId}`,
|
||||
from: fromuid,
|
||||
|
||||
@@ -80,18 +80,20 @@ SocketHelpers.sendNotificationToPostOwner = async function (pid, fromuid, comman
|
||||
if (!canRead || isIgnoring[0] || !postData.uid || fromuid === postData.uid) {
|
||||
return;
|
||||
}
|
||||
const [username, topicTitle, postObj] = await Promise.all([
|
||||
user.getUserField(fromuid, 'username'),
|
||||
const [userData, topicTitle, postObj] = await Promise.all([
|
||||
user.getUserFields(fromuid, ['username']),
|
||||
topics.getTopicField(postData.tid, 'title'),
|
||||
posts.parsePost(postData),
|
||||
]);
|
||||
|
||||
const { displayname } = userData;
|
||||
|
||||
const title = utils.decodeHTMLEntities(topicTitle);
|
||||
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
||||
|
||||
const notifObj = await notifications.create({
|
||||
type: command,
|
||||
bodyShort: `[[${notification}, ${username}, ${titleEscaped}]]`,
|
||||
bodyShort: `[[${notification}, ${displayname}, ${titleEscaped}]]`,
|
||||
bodyLong: postObj.content,
|
||||
pid: pid,
|
||||
tid: postData.tid,
|
||||
@@ -113,20 +115,23 @@ SocketHelpers.sendNotificationToTopicOwner = async function (tid, fromuid, comma
|
||||
|
||||
fromuid = parseInt(fromuid, 10);
|
||||
|
||||
const [username, topicData] = await Promise.all([
|
||||
user.getUserField(fromuid, 'username'),
|
||||
const [userData, topicData] = await Promise.all([
|
||||
user.getUserFields(fromuid, ['username']),
|
||||
topics.getTopicFields(tid, ['uid', 'slug', 'title']),
|
||||
]);
|
||||
|
||||
if (fromuid === topicData.uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { displayname } = userData;
|
||||
|
||||
const ownerUid = topicData.uid;
|
||||
const title = utils.decodeHTMLEntities(topicData.title);
|
||||
const titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
||||
|
||||
const notifObj = await notifications.create({
|
||||
bodyShort: `[[${notification}, ${username}, ${titleEscaped}]]`,
|
||||
bodyShort: `[[${notification}, ${displayname}, ${titleEscaped}]]`,
|
||||
path: `/topic/${topicData.slug}`,
|
||||
nid: `${command}:tid:${tid}:uid:${fromuid}`,
|
||||
from: fromuid,
|
||||
|
||||
@@ -93,8 +93,9 @@ module.exports = function (SocketUser) {
|
||||
child.on('exit', async () => {
|
||||
await db.deleteObjectField('locks', `export:${data.uid}${type}`);
|
||||
const userData = await user.getUserFields(data.uid, ['username', 'userslug']);
|
||||
const { displayname } = userData;
|
||||
const n = await notifications.create({
|
||||
bodyShort: `[[notifications:${type}-exported, ${userData.username}]]`,
|
||||
bodyShort: `[[notifications:${type}-exported, ${displayname}]]`,
|
||||
path: `/api/user/${userData.userslug}/export/${type}`,
|
||||
nid: `${type}:export:${data.uid}`,
|
||||
from: data.uid,
|
||||
|
||||
@@ -192,9 +192,11 @@ module.exports = function (Topics) {
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) || meta.config.allowGuestReplyNotifications) {
|
||||
const { displayname } = postData.user;
|
||||
|
||||
Topics.notifyFollowers(postData, uid, {
|
||||
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}`,
|
||||
mergeId: `notifications:user_posted_to|${postData.topic.tid}`,
|
||||
});
|
||||
|
||||
@@ -184,7 +184,7 @@ UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicD
|
||||
|
||||
const notifObj = await notifications.create({
|
||||
type: 'new-topic',
|
||||
bodyShort: `[[notifications:user_posted_topic, ${postData.user.username}, ${title}]]`,
|
||||
bodyShort: `[[notifications:user_posted_topic, ${postData.user.displayname}, ${title}]]`,
|
||||
bodyLong: postData.content,
|
||||
pid: postData.pid,
|
||||
path: `/post/${postData.pid}`,
|
||||
|
||||
Reference in New Issue
Block a user