Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle new course faculty type notifications and user settings. #33

Merged
merged 10 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified dump.rdb
Binary file not shown.
1 change: 1 addition & 0 deletions install/data/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"notificationType_post-queue": "notification",
"notificationType_new-post-flag": "notification",
"notificationType_new-user-flag": "notification",
"notificationType_faculty-reply": "notification",
"topicStaleDays": 60,
"maxTopicsPerPage": 20,
"maxPostsPerPage": 20,
Expand Down
10 changes: 8 additions & 2 deletions public/language/ar/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to": "<strong>[COURSE FACULTY] %1</strong> أضاف ردًا إلى: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> أضاف ردا إلى: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand All @@ -62,6 +61,11 @@
"user-started-following-you-dual": "<strong>%1</strong> and <strong>%2</strong> started following you.",
"user-started-following-you-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> started following you.",
"user-started-following-you-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others started following you.",

"faculty-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"faculty-posted-to-dual" : "<strong>[COURSE FACULTY] %1</strong> and <strong>[COURSE FACULTY] %2</strong> have posted replies to: <strong>%3</strong>",
"faculty-posted-to-multiple" : "<strong>[COURSE FACULTY] %1</strong>, <strong>[COURSE FACULTY] %2</strong> and %3 other faculty members have posted replies to: <strong>%4</strong>",

"new-register": "<strong>%1</strong> sent a registration request.",
"new-register-multiple": "There are <strong>%1</strong> registration requests awaiting review.",
"flag-assigned-to-you": "تم تخصيص العلامة 1% لك",
Expand Down Expand Up @@ -98,5 +102,7 @@
"notificationType-post-queue": "When a new post is queued",
"notificationType-new-post-flag": "When a post is flagged",
"notificationType-new-user-flag": "When a user is flagged",
"notificationType-new-reward": "When you earn a new reward"
"notificationType-new-reward": "When you earn a new reward",
"notificationType-faculty-reply": "When a course faculty replies to your post"

}
11 changes: 9 additions & 2 deletions public/language/en-GB/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to" : "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to-dual" : "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple" : "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
"user-posted-to-multiple" : "<strong>%1</strong>, <strong>%2</strong> and %3 others have posted replies to: <strong>%4</strong>",
"user-posted-topic": "<strong>%1</strong> has posted a new topic: <strong>%2</strong>",
"user-edited-post" : "<strong>%1</strong> has edited a post in <strong>%2</strong>",

"faculty-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"faculty-posted-to-dual" : "<strong>[COURSE FACULTY] %1</strong> and <strong>[COURSE FACULTY] %2</strong> have posted replies to: <strong>%3</strong>",
"faculty-posted-to-multiple" : "<strong>[COURSE FACULTY] %1</strong>, <strong>[COURSE FACULTY] %2</strong> and %3 other faculty members have posted replies to: <strong>%4</strong>",


"user-posted-topic-with-tag": "<strong>%1</strong> has posted a new topic with tag <strong>%2</strong>",
"user-posted-topic-with-tag-dual": "<strong>%1</strong> has posted a new topic with tags <strong>%2</strong> and <strong>%3</strong>",
"user-posted-topic-with-tag-triple": "<strong>%1</strong> has posted a new topic with tags <strong>%2</strong>, <strong>%3</strong> and <strong>%4</strong>",
Expand Down Expand Up @@ -90,6 +94,7 @@
"notification-only": "Notification Only",
"email-only": "Email Only",
"notification-and-email": "Notification & Email",

"notificationType-upvote": "When someone upvotes your post",
"notificationType-new-topic": "When someone you follow posts a topic",
"notificationType-new-topic-with-tag": "When a topic is posted with a tag you follow",
Expand All @@ -107,5 +112,7 @@
"notificationType-post-queue": "When a new post is queued",
"notificationType-new-post-flag": "When a post is flagged",
"notificationType-new-user-flag": "When a user is flagged",
"notificationType-new-reward": "When you earn a new reward"
"notificationType-new-reward": "When you earn a new reward",
"notificationType-faculty-reply": "When a course faculty replies to your post"

}
7 changes: 6 additions & 1 deletion public/language/en-US/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"user-flagged-user-dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand All @@ -62,6 +61,12 @@
"user-started-following-you-dual": "<strong>%1</strong> and <strong>%2</strong> started following you.",
"user-started-following-you-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> started following you.",
"user-started-following-you-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others started following you.",

"faculty-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"faculty-posted-to-dual" : "<strong>[COURSE FACULTY] %1</strong> and <strong>[COURSE FACULTY] %2</strong> have posted replies to: <strong>%3</strong>",
"faculty-posted-to-multiple" : "<strong>[COURSE FACULTY] %1</strong>, <strong>[COURSE FACULTY] %2</strong> and %3 other faculty members have posted replies to: <strong>%4</strong>",
"notificationType-faculty-reply": "When a course faculty replies to your post",

"new-register": "<strong>%1</strong> sent a registration request.",
"new-register-multiple": "There are <strong>%1</strong> registration requests awaiting review.",
"flag-assigned-to-you": "<strong>Flag %1</strong> has been assigned to you",
Expand Down
7 changes: 6 additions & 1 deletion public/language/es/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"user-flagged-user-dual": "<strong>%1</strong> y <strong>%2</strong> reportaron el perfil (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
"admin-posted-to" : "<strong>[COURSE FACULTY] %1</strong> ha respondido a: <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> ha respondido a: <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> y <strong>%2</strong> han respondido a <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have posted replies to: <strong>%4</strong>",
Expand All @@ -62,6 +61,12 @@
"user-started-following-you-dual": "<strong>%1</strong> y <strong>%2</strong> comenzaron a seguirte.",
"user-started-following-you-triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> started following you.",
"user-started-following-you-multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others started following you.",

"faculty-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"faculty-posted-to-dual" : "<strong>[COURSE FACULTY] %1</strong> and <strong>[COURSE FACULTY] %2</strong> have posted replies to: <strong>%3</strong>",
"faculty-posted-to-multiple" : "<strong>[COURSE FACULTY] %1</strong>, <strong>[COURSE FACULTY] %2</strong> and %3 other faculty members have posted replies to: <strong>%4</strong>",
"notificationType-faculty-reply": "When a course faculty replies to your post",

"new-register": "<strong>%1</strong> envió una solicitud de registro.",
"new-register-multiple": "Hay <strong>%1</strong> peticiones de registros pendientes de revisión",
"flag-assigned-to-you": "<strong>Reporte %1</strong> te ha sido asignado.",
Expand Down
7 changes: 6 additions & 1 deletion public/language/fr/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"user-flagged-user-dual": "<strong>%1</strong> et <strong>%2</strong> ont signalé un profil utilisateur (%3)",
"user-flagged-user-triple": "<strong>%1</strong>, <strong>%2</strong> et <strong>%3</strong> ont signalé un profil utilisateur (%4)",
"user-flagged-user-multiple": "<strong>%1</strong>, <strong>%2</strong> et %3 autres ont signalé un profil utilisateur (%4)",
"admin-posted-to": "<strong>[COURSE FACULTY] %1</strong> a répondu à : <strong>%2</strong>",
"user-posted-to": "<strong>%1</strong> a répondu à : <strong>%2</strong>",
"user-posted-to-dual": "<strong>%1</strong> et <strong>%2</strong> ont posté une réponse à : <strong>%3</strong>",
"user-posted-to-triple": "<strong>%1</strong>, <strong>%2</strong> et <strong>%3</strong> ont publié des réponses à : <strong>%4</strong>",
Expand All @@ -62,6 +61,12 @@
"user-started-following-you-dual": "<strong>%1</strong> et <strong>%2</strong> se sont abonnés à votre compte.",
"user-started-following-you-triple": "<strong>%1</strong>, <strong>%2</strong> et <strong>%3</strong> ont commencé à vous suivre.",
"user-started-following-you-multiple": "<strong>%1</strong>, <strong>%2</strong> et %3 autres ont commencé à vous suivre.",

"faculty-posted-to" : "<strong>[COURSE FACULTY] %1</strong> has posted a reply to: <strong>%2</strong>",
"faculty-posted-to-dual" : "<strong>[COURSE FACULTY] %1</strong> and <strong>[COURSE FACULTY] %2</strong> have posted replies to: <strong>%3</strong>",
"faculty-posted-to-multiple" : "<strong>[COURSE FACULTY] %1</strong>, <strong>[COURSE FACULTY] %2</strong> and %3 other faculty members have posted replies to: <strong>%4</strong>",
"notificationType-faculty-reply": "When a course faculty replies to your post",

"new-register": "<strong>%1</strong> a envoyé une demande d'incription.",
"new-register-multiple": "<strong>%1</strong> inscription(s) est en attente de validation.",
"flag-assigned-to-you": "<strong>Signalement %1</strong> vous a été assigné",
Expand Down
8 changes: 7 additions & 1 deletion public/openapi/components/schemas/SettingsObj.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Settings:
type: object
properties:
# Adding faculty reply to the api schema
notificationType_faculty-reply:
type: string
description: Notification type for when a course faculty replies to your post
enum: [none, notification, email, notificationemail]
showemail:
type: boolean
description: Show user email in profile page
Expand Down Expand Up @@ -161,4 +166,5 @@ Settings:
- notificationType_new-user-flag
- categoryWatchState
- notificationType_group-request-membership
- uid
- uid
- notificationType_faculty-reply
8 changes: 7 additions & 1 deletion src/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Notifications.baseTypes = [
'notificationType_group-leave',
'notificationType_group-request-membership',
'notificationType_new-reward',
// Adding the new notification type
'notificationType_faculty-reply',
];

Notifications.privilegedTypes = [
Expand Down Expand Up @@ -155,6 +157,10 @@ Notifications.create = async function (data) {
if (!result.data) {
return null;
}
// Handle faculty reply notification
if (result.data.type === 'faculty-reply') {
result.data.importance = result.data.importance || 6; // Setting a higher importance for faculty replies
}
await Promise.all([
db.sortedSetAdd('notifications', now, data.nid),
db.setObject(`notifications:${data.nid}`, data),
Expand Down Expand Up @@ -241,7 +247,7 @@ async function pushToUids(uids, notification) {
results = await getUidsBySettings(data.uids);
}
await sendNotification(results.uidsToNotify);
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat'];
const delayNotificationTypes = ['new-chat', 'new-group-chat', 'new-public-chat', 'faculty-reply'];
if (delayNotificationTypes.includes(notification.type)) {
const cacheKey = `${notification.mergeId}|${results.uidsToEmail.join(',')}`;
if (notificationCache.has(cacheKey)) {
Expand Down
40 changes: 18 additions & 22 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,38 +209,34 @@ module.exports = function (Topics) {
if (parseInt(uid, 10) || meta.config.allowGuestReplyNotifications) {
const { displayname } = postData.user;

// Checks if the user is an admin
const isAdmin = await privileges.users.isAdministrator(uid);
let notificationType = 'new-reply';
let notificationMessage;
let nid;
let mergeId;

if (isAdmin) {
// Handles admin/instructor notification separately so it doesn't get bundled with
// notifications of non-admin replies.
// It does this by using a different notification ID and merge ID for admin replies.
notificationMessage = translator.compile('notifications:admin-posted-to', displayname, postData.topic.title);
Topics.notifyFollowers(postData, uid, {
type: 'new-reply',
bodyShort: notificationMessage,
nid: `admin_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`,
mergeId: `notifications:admin-posted-to|${postData.topic.tid}`,
});
notificationType = 'faculty-reply';
notificationMessage = translator.compile('notifications:faculty-posted-to', displayname, postData.topic.title);
nid = `faculty_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`;
mergeId = `notifications:faculty-posted-to|${postData.topic.tid}`;
} else {
// This code handles non-admin replies, allowing bundling.
notificationMessage = translator.compile('notifications:user-posted-to', displayname, postData.topic.title);

Topics.notifyFollowers(postData, uid, {
type: 'new-reply',
bodyShort: notificationMessage,
nid: `new_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`,
mergeId: `notifications:user-posted-to|${postData.topic.tid}`,
});
nid = `new_post:tid:${postData.topic.tid}:pid:${postData.pid}:uid:${uid}`;
mergeId = `notifications:user-posted-to|${postData.topic.tid}`;
}

await Topics.notifyFollowers(postData, uid, {
type: notificationType,
bodyShort: notificationMessage,
nid: nid,
mergeId: mergeId,
});

analytics.increment(['posts', `posts:byCid:${data.cid}`]);
plugins.hooks.fire('action:topic.reply', { post: _.clone(postData), data: data });

return postData;
}

return postData;
};

async function onNewPost(postData, data) {
Expand Down
1 change: 1 addition & 0 deletions src/upgrades/1.7.6/notification_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
notificationType_upvote: config.notificationType_upvote || 'notification',
'notificationType_new-topic': config['notificationType_new-topic'] || 'notification',
'notificationType_new-reply': config['notificationType_new-reply'] || postNotifications,
'notificationType_faculty-reply': config['notificationType_faculty-reply'] || 'notification',
notificationType_follow: config.notificationType_follow || 'notification',
'notificationType_new-chat': config['notificationType_new-chat'] || chatNotifications,
'notificationType_group-invite': config['notificationType_group-invite'] || 'notification',
Expand Down
24 changes: 24 additions & 0 deletions src/upgrades/3.8.4/add_faculty_reply_notification_setting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const db = require('../../database');
const batch = require('../../batch');

module.exports = {
name: 'Add_faculty_reply_notification_setting_for_all_users',
timestamp: Date.UTC(2024, 10, 8),
method: async function () {
const { progress } = this;

await batch.processSortedSet('users:joindate', async (uids) => {
await Promise.all(uids.map(async (uid) => {
await db.setObjectField(`user:${uid}:settings`, 'notificationType_faculty-reply', 'notification');
}));

if (progress) {
progress.incr(uids.length);
}
}, {
batch: 500,
});
},
};
9 changes: 9 additions & 0 deletions src/user/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module.exports = function (User) {
settings[notificationType] = getSetting(settings, notificationType, 'notification');
});

// Load the faculty reply notification setting
settings['notificationType_faculty-reply'] = getSetting(settings, 'notificationType_faculty-reply', 'notification');

return settings;
}

Expand Down Expand Up @@ -155,6 +158,12 @@ module.exports = function (User) {
settings[notificationType] = data[notificationType];
}
});

// Handling for faculty-reply notification
if (data['notificationType_faculty-reply']) {
settings['notificationType_faculty-reply'] = data['notificationType_faculty-reply'];
}

const result = await plugins.hooks.fire('filter:user.saveSettings', { uid: uid, settings: settings, data: data });
await db.setObject(`user:${uid}:settings`, result.settings);
await User.updateDigestSetting(uid, data.dailyDigestFreq);
Expand Down
Loading