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

Adding project 1 refactored code. #17

Closed
wants to merge 2 commits into from
Closed
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 added dump.rdb
Binary file not shown.
1 change: 1 addition & 0 deletions public/language/en-GB/notifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"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>Instructor %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 Down
53 changes: 33 additions & 20 deletions public/src/client/account/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,40 @@
}

function saveSettings(settings) {
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then((newSettings) => {
alerts.success('[[success:settings-saved]]');
let languageChanged = false;
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
languageChanged = true;
}
if (key === 'bootswatchSkin') {
savedSkin = newSettings.bootswatchSkin;
config.bootswatchSkin = savedSkin === 'noskin' ? '' : savedSkin;
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}
}
console.log('Logging Jullia Montejo');
api.put(`/users/${ajaxify.data.uid}/settings`, { settings }).then(handleNewSettings);
}

// Alerts the user that the settings have been saved and updates the configuration.
function handleNewSettings(newSettings) {
alerts.success('[[success:settings-saved]]');
processNewSettings(newSettings);
}

if (languageChanged && parseInt(app.user.uid, 10) === parseInt(ajaxify.data.theirid, 10)) {
window.location.reload();
// Processes the new settings and updates the configuration accordingly.
function processNewSettings(newSettings) {
for (const key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
checkAndUpdateConfig(key, newSettings);
}
});
}
}

// Updates the configuration based on the provided key and new settings.
function checkAndUpdateConfig(key, newSettings) {
if (key === 'userLang' && config.userLang !== newSettings.userLang) {
window.location.reload();
} else if (key === 'bootswatchSkin') {
updateSkin(newSettings.bootswatchSkin);
} else if (config.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}

// Updates the saved skin with the new skin.
function updateSkin(skin) {
savedSkin = skin;
config.bootswatchSkin = skin === 'noskin' ? '' : skin;
}

function toggleCustomRoute() {
Expand Down Expand Up @@ -162,4 +175,4 @@
};

return AccountSettings;
});
});

Check failure on line 178 in public/src/client/account/settings.js

View workflow job for this annotation

GitHub Actions / test

Newline required at end of file but not found
38 changes: 25 additions & 13 deletions src/topics/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,61 +167,73 @@
data = await plugins.hooks.fire('filter:topic.reply', data);
const { tid } = data;
const { uid } = data;

Check failure on line 170 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
const [topicData, isAdmin] = await Promise.all([
Topics.getTopicData(tid),
privileges.users.isAdministrator(uid),
]);

Check failure on line 175 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
await canReply(data, topicData);

Check failure on line 177 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
data.cid = topicData.cid;

Check failure on line 179 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
await guestHandleValid(data);
data.content = String(data.content || '').trimEnd();

Check failure on line 182 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
if (!data.fromQueue && !isAdmin) {
await user.isReadyToPost(uid, data.cid);
Topics.checkContent(data.content);
if (!await posts.canUserPostContentWithLinks(uid, data.content)) {
throw new Error(`[[error:not-enough-reputation-to-post-links, ${meta.config['min:rep:post-links']}]]`);
}
}

Check failure on line 190 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
// For replies to scheduled topics, don't have a timestamp older than topic's itself
if (topicData.scheduled) {
data.timestamp = topicData.lastposttime + 1;
}

Check failure on line 195 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
data.ip = data.req ? data.req.ip : null;
let postData = await posts.create(data);
postData = await onNewPost(postData, data);

Check failure on line 199 in src/topics/create.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
const settings = await user.getSettings(uid);
if (uid > 0 && settings.followTopicsOnReply) {
await Topics.follow(postData.tid, uid);
}

if (parseInt(uid, 10)) {
user.setUserField(uid, 'lastonline', Date.now());
}

if (parseInt(uid, 10) || meta.config.allowGuestReplyNotifications) {
const { displayname } = postData.user;

// Ensure isAdmin is correctly set
const isAdmin = await privileges.users.isAdministrator(uid);

// Modify notification message based on admin status
let notificationMessage = translator.compile('notifications:user-posted-to', displayname, postData.topic.title);
console.log('isnotadmin');
if (isAdmin) {
console.log('isAdmin:', isAdmin);
notificationMessage = translator.compile('notifications:admin-posted-to', displayname, postData.topic.title);
}

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

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

return postData;
};


async function onNewPost(postData, data) {
const { tid, uid } = postData;
Expand Down
Loading