From 7397873db355d5449e9de3e6ca39b47b4cb34813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 27 Mar 2023 22:16:41 -0400 Subject: [PATCH 1/5] fix: fire action:user.online on user login --- src/controllers/authentication.js | 2 +- src/user/online.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index 82dc6b1660..bb6e6bf49f 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -383,7 +383,7 @@ authenticationController.onSuccessfulLogin = async function (req, uid) { }), user.auth.addSession(uid, req.sessionID), user.updateLastOnlineTime(uid), - user.updateOnlineUsers(uid), + user.onUserOnline(uid, Date.now()), analytics.increment('logins'), db.incrObjectFieldBy('global', 'loginCount', 1), ]); diff --git a/src/user/online.js b/src/user/online.js index ffba4c9a94..b7c6b9d45a 100644 --- a/src/user/online.js +++ b/src/user/online.js @@ -27,9 +27,13 @@ module.exports = function (User) { if (now - parseInt(userOnlineTime, 10) < 300000) { return; } - await db.sortedSetAdd('users:online', now, uid); + await User.onUserOnline(uid, now); topics.pushUnreadCount(uid); - plugins.hooks.fire('action:user.online', { uid: uid, timestamp: now }); + }; + + User.onUserOnline = async (uid, timestamp) => { + await db.sortedSetAdd('users:online', timestamp, uid); + plugins.hooks.fire('action:user.online', { uid, timestamp }); }; User.isOnline = async function (uid) { From 4d2d76897a02e7068ab74c81d17a2febfae8bfb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 28 Mar 2023 08:08:59 -0400 Subject: [PATCH 2/5] fix: don't crash on objects with toString property --- src/socket.io/index.js | 65 +++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 30e4e23581..963267ed9a 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -112,48 +112,49 @@ async function onMessage(socket, payload) { return winston.warn('[socket.io] Empty payload'); } - const eventName = payload.data[0]; + let eventName = payload.data[0]; const params = typeof payload.data[1] === 'function' ? {} : payload.data[1]; const callback = typeof payload.data[payload.data.length - 1] === 'function' ? payload.data[payload.data.length - 1] : function () {}; - if (!eventName) { - return winston.warn('[socket.io] Empty method name'); - } - - if (typeof eventName !== 'string') { - const escapedName = validator.escape(String(eventName)); - return callback({ message: `[[error:invalid-event, ${escapedName}]]` }); - } + try { + if (!eventName) { + return winston.warn('[socket.io] Empty method name'); + } - const parts = eventName.split('.'); - const namespace = parts[0]; - const methodToCall = parts.reduce((prev, cur) => { - if (prev !== null && prev[cur] && (!prev.hasOwnProperty || prev.hasOwnProperty(cur))) { - return prev[cur]; + if (typeof eventName !== 'string') { + eventName = typeof eventName; + const escapedName = validator.escape(eventName); + return callback({ message: `[[error:invalid-event, ${escapedName}]]` }); } - return null; - }, Namespaces); - if (!methodToCall || typeof methodToCall !== 'function') { - if (process.env.NODE_ENV === 'development') { - winston.warn(`[socket.io] Unrecognized message: ${eventName}`); + const parts = eventName.split('.'); + const namespace = parts[0]; + const methodToCall = parts.reduce((prev, cur) => { + if (prev !== null && prev[cur] && (!prev.hasOwnProperty || prev.hasOwnProperty(cur))) { + return prev[cur]; + } + return null; + }, Namespaces); + + if (!methodToCall || typeof methodToCall !== 'function') { + if (process.env.NODE_ENV === 'development') { + winston.warn(`[socket.io] Unrecognized message: ${eventName}`); + } + const escapedName = validator.escape(String(eventName)); + return callback({ message: `[[error:invalid-event, ${escapedName}]]` }); } - const escapedName = validator.escape(String(eventName)); - return callback({ message: `[[error:invalid-event, ${escapedName}]]` }); - } - socket.previousEvents = socket.previousEvents || []; - socket.previousEvents.push(eventName); - if (socket.previousEvents.length > 20) { - socket.previousEvents.shift(); - } + socket.previousEvents = socket.previousEvents || []; + socket.previousEvents.push(eventName); + if (socket.previousEvents.length > 20) { + socket.previousEvents.shift(); + } - if (!eventName.startsWith('admin.') && ratelimit.isFlooding(socket)) { - winston.warn(`[socket.io] Too many emits! Disconnecting uid : ${socket.uid}. Events : ${socket.previousEvents}`); - return socket.disconnect(); - } + if (!eventName.startsWith('admin.') && ratelimit.isFlooding(socket)) { + winston.warn(`[socket.io] Too many emits! Disconnecting uid : ${socket.uid}. Events : ${socket.previousEvents}`); + return socket.disconnect(); + } - try { await checkMaintenance(socket); await validateSession(socket, '[[error:revalidate-failure]]'); From e0b20658029bcec26528881d9ea14b2793f05305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 28 Mar 2023 08:15:42 -0400 Subject: [PATCH 3/5] test: update socket.io test --- test/socket.io.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/socket.io.js b/test/socket.io.js index 110258a0de..3628e3b0d0 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -110,8 +110,7 @@ describe('socket.io', () => { it('should return error for invalid eventName type', (done) => { const eventName = ['topics.loadMoreTags']; io.emit(eventName, (err) => { - const eventAsString = String(eventName); - assert.strictEqual(err.message, `[[error:invalid-event, ${eventAsString}]]`); + assert.strictEqual(err.message, `[[error:invalid-event, object]]`); done(); }); }); From 67055006df503f0d4ac32f2302f31caa4899dde3 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 29 Mar 2023 10:31:39 -0400 Subject: [PATCH 4/5] docs: update readme with new screenshot and updated copy for Harmony --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d06bc0362a..a45ba24ab8 100644 --- a/README.md +++ b/README.md @@ -24,17 +24,14 @@ NodeBB's theming engine is highly flexible and does not restrict your design cho [![](http://i.imgur.com/LmHtPhob.png)](http://i.imgur.com/LmHtPho.png) [![](http://i.imgur.com/paiJPJkb.jpg)](http://i.imgur.com/paiJPJk.jpg) -Our minimalist "Persona" theme gets you going right away, no coding experience required. - -[![](http://i.imgur.com/HwNEXGu.png)](http://i.imgur.com/HwNEXGu.png) -[![](http://i.imgur.com/II1byYs.png)](http://i.imgur.com/II1byYs.png) - +Our minimalist "Harmony" theme gets you going right away, no coding experience required. +![Rendering of a NodeBB install on desktop and mobile devices](https://user-images.githubusercontent.com/923011/228570420-2a4db745-b20d-474a-a571-1b59259508ef.png) ## How can I follow along/contribute? * If you are a developer, feel free to check out the source and submit pull requests. We also have a wide array of [plugins](http://community.nodebb.org/category/7/nodebb-plugins) which would be a great starting point for learning the codebase. -* If you are a designer, [NodeBB needs themes](http://community.nodebb.org/category/10/nodebb-themes)! NodeBB's theming system allows extension of the base templates as well as styling via LESS or CSS. NodeBB's base theme utilizes [Bootstrap 3](http://getbootstrap.com/) but themes can choose to use a different framework altogether. +* If you are a designer, [NodeBB needs themes](http://community.nodebb.org/category/10/nodebb-themes)! NodeBB's theming system allows extension of the base templates as well as styling via SCSS or CSS. NodeBB's base theme utilizes [Bootstrap 5](http://getbootstrap.com/) as a frontend toolkit. * If you know languages other than English you can help us translate NodeBB. We use [Transifex](https://explore.transifex.com/nodebb/nodebb/) for internationalization. * Please don't forget to **like**, **follow**, and **star our repo**! Join our growing [community](http://community.nodebb.org) to keep up to date with the latest NodeBB development. @@ -42,7 +39,7 @@ Our minimalist "Persona" theme gets you going right away, no coding experience r NodeBB requires the following software to be installed: -* A version of Node.js at least 12 or greater ([installation/upgrade instructions](https://github.com/nodesource/distributions)) +* A version of Node.js at least 16 or greater ([installation/upgrade instructions](https://github.com/nodesource/distributions)) * MongoDB, version 3.6 or greater **or** Redis, version 2.8.9 or greater * If you are using [clustering](https://docs.nodebb.org/configuring/scaling/) you need Redis installed and configured. * nginx, version 1.3.13 or greater (**only if** intending to use nginx to proxy requests to a NodeBB) @@ -76,10 +73,10 @@ Interested in a sublicense agreement for use of NodeBB in a non-free/restrictive * [Demo](https://try.nodebb.org) * [Developer Community](http://community.nodebb.org) -* [Documentation & Installation Instructions](http://docs.nodebb.org) +* [Documentation & Installation Instructions](https://docs.nodebb.org) * [Help translate NodeBB](https://explore.transifex.com/nodebb/nodebb/) -* [NodeBB Blog](http://blog.nodebb.org) -* [Premium Hosting for NodeBB](http://www.nodebb.org/ "NodeBB") +* [NodeBB Blog](https://nodebb.org/blog) +* [Premium Hosting for NodeBB](https://www.nodebb.org/ "NodeBB") * Unofficial IRC community – channel `#nodebb` on Libera.chat * [Follow us on Twitter](http://www.twitter.com/NodeBB/ "NodeBB Twitter") * [Like us on Facebook](http://www.facebook.com/NodeBB/ "NodeBB Facebook") From c33730530e4f3a5474447b975cba4e6b7c7660c0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 29 Mar 2023 10:32:05 -0400 Subject: [PATCH 5/5] Revert "docs: update readme with new screenshot and updated copy for Harmony" This reverts commit 67055006df503f0d4ac32f2302f31caa4899dde3. --- README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a45ba24ab8..d06bc0362a 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,17 @@ NodeBB's theming engine is highly flexible and does not restrict your design cho [![](http://i.imgur.com/LmHtPhob.png)](http://i.imgur.com/LmHtPho.png) [![](http://i.imgur.com/paiJPJkb.jpg)](http://i.imgur.com/paiJPJk.jpg) -Our minimalist "Harmony" theme gets you going right away, no coding experience required. +Our minimalist "Persona" theme gets you going right away, no coding experience required. + +[![](http://i.imgur.com/HwNEXGu.png)](http://i.imgur.com/HwNEXGu.png) +[![](http://i.imgur.com/II1byYs.png)](http://i.imgur.com/II1byYs.png) + -![Rendering of a NodeBB install on desktop and mobile devices](https://user-images.githubusercontent.com/923011/228570420-2a4db745-b20d-474a-a571-1b59259508ef.png) ## How can I follow along/contribute? * If you are a developer, feel free to check out the source and submit pull requests. We also have a wide array of [plugins](http://community.nodebb.org/category/7/nodebb-plugins) which would be a great starting point for learning the codebase. -* If you are a designer, [NodeBB needs themes](http://community.nodebb.org/category/10/nodebb-themes)! NodeBB's theming system allows extension of the base templates as well as styling via SCSS or CSS. NodeBB's base theme utilizes [Bootstrap 5](http://getbootstrap.com/) as a frontend toolkit. +* If you are a designer, [NodeBB needs themes](http://community.nodebb.org/category/10/nodebb-themes)! NodeBB's theming system allows extension of the base templates as well as styling via LESS or CSS. NodeBB's base theme utilizes [Bootstrap 3](http://getbootstrap.com/) but themes can choose to use a different framework altogether. * If you know languages other than English you can help us translate NodeBB. We use [Transifex](https://explore.transifex.com/nodebb/nodebb/) for internationalization. * Please don't forget to **like**, **follow**, and **star our repo**! Join our growing [community](http://community.nodebb.org) to keep up to date with the latest NodeBB development. @@ -39,7 +42,7 @@ Our minimalist "Harmony" theme gets you going right away, no coding experience r NodeBB requires the following software to be installed: -* A version of Node.js at least 16 or greater ([installation/upgrade instructions](https://github.com/nodesource/distributions)) +* A version of Node.js at least 12 or greater ([installation/upgrade instructions](https://github.com/nodesource/distributions)) * MongoDB, version 3.6 or greater **or** Redis, version 2.8.9 or greater * If you are using [clustering](https://docs.nodebb.org/configuring/scaling/) you need Redis installed and configured. * nginx, version 1.3.13 or greater (**only if** intending to use nginx to proxy requests to a NodeBB) @@ -73,10 +76,10 @@ Interested in a sublicense agreement for use of NodeBB in a non-free/restrictive * [Demo](https://try.nodebb.org) * [Developer Community](http://community.nodebb.org) -* [Documentation & Installation Instructions](https://docs.nodebb.org) +* [Documentation & Installation Instructions](http://docs.nodebb.org) * [Help translate NodeBB](https://explore.transifex.com/nodebb/nodebb/) -* [NodeBB Blog](https://nodebb.org/blog) -* [Premium Hosting for NodeBB](https://www.nodebb.org/ "NodeBB") +* [NodeBB Blog](http://blog.nodebb.org) +* [Premium Hosting for NodeBB](http://www.nodebb.org/ "NodeBB") * Unofficial IRC community – channel `#nodebb` on Libera.chat * [Follow us on Twitter](http://www.twitter.com/NodeBB/ "NodeBB Twitter") * [Like us on Facebook](http://www.facebook.com/NodeBB/ "NodeBB Facebook")