mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-28 02:09:52 +01:00
commit072a11b89fMerge:25ef62dc6b8fb0ed82b8Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 13:10:01 2024 -0500 Merge branch 'develop' of https://github.com/NodeBB/NodeBB into develop commit25ef62dc6bAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 13:09:56 2024 -0500 chore: up harmony commit8fb0ed82b8Author: Misty Release Bot <deploy@nodebb.org> Date: Thu Feb 29 18:08:50 2024 +0000 chore(i18n): fallback strings for new resources: nodebb.themes-harmony commit96bc5d6f84Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 13:08:25 2024 -0500 add harmony setting label commit516c8d0424Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 12:53:39 2024 -0500 chore(deps): update commitlint monorepo to v19 (#12369) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commita8abc7aea4Merge:3aaa072756aa6859dfaeAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 10:42:42 2024 -0500 Merge branch 'develop' of https://github.com/NodeBB/NodeBB into develop commit3aaa072756Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 10:42:37 2024 -0500 chore: up peace commitaa6859dfaeAuthor: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 10:42:16 2024 -0500 fix(deps): update dependency nodemailer to v6.9.11 (#12380) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit2c3540b25cAuthor: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 10:42:07 2024 -0500 fix(deps): update dependency express to v4.18.3 (#12379) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commitc8a5e24aeeAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 10:39:02 2024 -0500 test: fix test commit5556c1d549Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 10:29:37 2024 -0500 add missing btn class commitfb98dc054dAuthor: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 09:43:17 2024 -0500 fix(deps): update dependency nodebb-plugin-markdown to v12.2.6 (#12371) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit9de0ab3165Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 09:42:13 2024 -0500 fix(deps): update dependency archiver to v7 (#12374) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit131d2fe78bAuthor: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 09:41:56 2024 -0500 fix(deps): update dependency chart.js to v4.4.2 (#12376) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit0ab1982cb8Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Thu Feb 29 09:41:37 2024 -0500 chore(deps): update dependency smtp-server to v3.13.3 (#12378) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit65f3c73493Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Thu Feb 29 09:31:17 2024 -0500 chore: up peace commita5101dcbe1Author: Misty Release Bot <deploy@nodebb.org> Date: Thu Feb 29 09:19:05 2024 +0000 Latest translations and fallbacks commit0f11533c23Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Wed Feb 28 16:04:25 2024 -0500 cache page changes commit53b3c5d669Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Wed Feb 28 11:41:18 2024 -0500 feat: add chat widget areas, closes #12375 commit1ed4d76363Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Wed Feb 28 11:14:20 2024 -0500 fix(deps): update dependency bootswatch to v5.3.3 (#12373) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commitea99401a0dMerge:f4c651fe25caf8722fd5Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Wed Feb 28 09:19:09 2024 -0500 Merge branch 'master' into develop commitcaf8722fd5Author: Misty Release Bot <deploy@nodebb.org> Date: Wed Feb 28 14:17:10 2024 +0000 chore: update changelog for v3.6.7 commit78b8fab3e7Author: Misty Release Bot <deploy@nodebb.org> Date: Wed Feb 28 14:17:09 2024 +0000 chore: incrementing version number - v3.6.7 commitf4c651fe25Author: Misty Release Bot <deploy@nodebb.org> Date: Wed Feb 28 09:18:50 2024 +0000 Latest translations and fallbacks commit5eb503440dMerge:7207814b905f597dc97fAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Tue Feb 27 15:22:23 2024 -0500 Merge branch 'master' into develop commit5f597dc97fAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Tue Feb 27 15:13:06 2024 -0500 align center commit107f5613bfAuthor: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Tue Feb 27 15:07:23 2024 -0500 fix: #12372, fix manual digest buttons commit7207814b90Author: Barış Soner Uşaklı <barisusakli@gmail.com> Date: Tue Feb 27 09:20:44 2024 -0500 feat: add hook into user.posts.isReady can be used to disable post delays or apply custom logic closes https://github.com/NodeBB/NodeBB/pull/12367 commit1df37c0153Author: Misty Release Bot <deploy@nodebb.org> Date: Tue Feb 27 09:19:09 2024 +0000 Latest translations and fallbacks
149 lines
4.6 KiB
JavaScript
149 lines
4.6 KiB
JavaScript
'use strict';
|
|
|
|
const db = require('../database');
|
|
const meta = require('../meta');
|
|
const privileges = require('../privileges');
|
|
const plugins = require('../plugins');
|
|
const groups = require('../groups');
|
|
|
|
module.exports = function (User) {
|
|
User.isReadyToPost = async function (uid, cid) {
|
|
await isReady(uid, cid, 'lastposttime');
|
|
};
|
|
|
|
User.isReadyToQueue = async function (uid, cid) {
|
|
await isReady(uid, cid, 'lastqueuetime');
|
|
};
|
|
|
|
User.checkMuted = async function (uid) {
|
|
const now = Date.now();
|
|
const mutedUntil = await User.getUserField(uid, 'mutedUntil');
|
|
if (mutedUntil > now) {
|
|
let muteLeft = ((mutedUntil - now) / (1000 * 60));
|
|
if (muteLeft > 60) {
|
|
muteLeft = (muteLeft / 60).toFixed(0);
|
|
throw new Error(`[[error:user-muted-for-hours, ${muteLeft}]]`);
|
|
} else {
|
|
throw new Error(`[[error:user-muted-for-minutes, ${muteLeft.toFixed(0)}]]`);
|
|
}
|
|
}
|
|
};
|
|
|
|
async function isReady(uid, cid, field) {
|
|
if (parseInt(uid, 10) === 0) {
|
|
return;
|
|
}
|
|
const [userData, isAdminOrMod, isMemberOfExempt] = await Promise.all([
|
|
User.getUserFields(uid, ['uid', 'mutedUntil', 'joindate', 'email', 'reputation'].concat([field])),
|
|
privileges.categories.isAdminOrMod(cid, uid),
|
|
groups.isMemberOfAny(uid, meta.config.groupsExemptFromNewUserRestrictions),
|
|
]);
|
|
|
|
if (!userData.uid) {
|
|
throw new Error('[[error:no-user]]');
|
|
}
|
|
|
|
if (isAdminOrMod) {
|
|
return;
|
|
}
|
|
|
|
await User.checkMuted(uid);
|
|
|
|
const { shouldIgnoreDelays } = await plugins.hooks.fire('filter:user.posts.isReady', {
|
|
shouldIgnoreDelays: false,
|
|
user: userData,
|
|
cid,
|
|
field,
|
|
isAdminOrMod,
|
|
isMemberOfExempt,
|
|
});
|
|
if (shouldIgnoreDelays) {
|
|
return;
|
|
}
|
|
|
|
const now = Date.now();
|
|
if (now - userData.joindate < meta.config.initialPostDelay * 1000) {
|
|
throw new Error(`[[error:user-too-new, ${meta.config.initialPostDelay}]]`);
|
|
}
|
|
|
|
const lasttime = userData[field] || 0;
|
|
|
|
if (
|
|
!isMemberOfExempt &&
|
|
meta.config.newbiePostDelay > 0 &&
|
|
meta.config.newbieReputationThreshold > userData.reputation &&
|
|
now - lasttime < meta.config.newbiePostDelay * 1000
|
|
) {
|
|
if (meta.config.newbiewPostDelay % 60 === 0) {
|
|
throw new Error(`[[error:too-many-posts-newbie-minutes, ${Math.floor(meta.config.newbiePostDelay / 60)}, ${meta.config.newbieReputationThreshold}]]`);
|
|
} else {
|
|
throw new Error(`[[error:too-many-posts-newbie, ${meta.config.newbiePostDelay}, ${meta.config.newbieReputationThreshold}]]`);
|
|
}
|
|
} else if (now - lasttime < meta.config.postDelay * 1000) {
|
|
throw new Error(`[[error:too-many-posts, ${meta.config.postDelay}]]`);
|
|
}
|
|
}
|
|
|
|
User.onNewPostMade = async function (postData) {
|
|
// For scheduled posts, use "action" time. It'll be updated in related cron job when post is published
|
|
const lastposttime = postData.timestamp > Date.now() ? Date.now() : postData.timestamp;
|
|
|
|
await Promise.all([
|
|
User.addPostIdToUser(postData),
|
|
User.setUserField(postData.uid, 'lastposttime', lastposttime),
|
|
User.updateLastOnlineTime(postData.uid),
|
|
]);
|
|
};
|
|
|
|
User.addPostIdToUser = async function (postData) {
|
|
await db.sortedSetsAdd([
|
|
`uid:${postData.uid}:posts`,
|
|
`cid:${postData.cid}:uid:${postData.uid}:pids`,
|
|
], postData.timestamp, postData.pid);
|
|
await User.updatePostCount(postData.uid);
|
|
};
|
|
|
|
User.updatePostCount = async (uids) => {
|
|
uids = Array.isArray(uids) ? uids : [uids];
|
|
const exists = await User.exists(uids);
|
|
uids = uids.filter((uid, index) => exists[index]);
|
|
if (uids.length) {
|
|
const counts = await db.sortedSetsCard(uids.map(uid => `uid:${uid}:posts`));
|
|
await Promise.all([
|
|
db.setObjectBulk(uids.map((uid, index) => ([`user:${uid}`, { postcount: counts[index] }]))),
|
|
db.sortedSetAdd('users:postcount', counts, uids),
|
|
]);
|
|
}
|
|
};
|
|
|
|
User.incrementUserPostCountBy = async function (uid, value) {
|
|
return await incrementUserFieldAndSetBy(uid, 'postcount', 'users:postcount', value);
|
|
};
|
|
|
|
User.incrementUserReputationBy = async function (uid, value) {
|
|
return await incrementUserFieldAndSetBy(uid, 'reputation', 'users:reputation', value);
|
|
};
|
|
|
|
User.incrementUserFlagsBy = async function (uid, value) {
|
|
return await incrementUserFieldAndSetBy(uid, 'flags', 'users:flags', value);
|
|
};
|
|
|
|
async function incrementUserFieldAndSetBy(uid, field, set, value) {
|
|
value = parseInt(value, 10);
|
|
if (!value || !field || !(parseInt(uid, 10) > 0)) {
|
|
return;
|
|
}
|
|
const exists = await User.exists(uid);
|
|
if (!exists) {
|
|
return;
|
|
}
|
|
const newValue = await User.incrementUserFieldBy(uid, field, value);
|
|
await db.sortedSetAdd(set, newValue, uid);
|
|
return newValue;
|
|
}
|
|
|
|
User.getPostIds = async function (uid, start, stop) {
|
|
return await db.getSortedSetRevRange(`uid:${uid}:posts`, start, stop);
|
|
};
|
|
};
|