nodebb-plugin-admin-chats 3.4.3 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/client.js +2 -5
  2. package/library.js +24 -5
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -253,11 +253,8 @@ $(document).ready(function() {
253
253
  });
254
254
  if (roomId) {
255
255
  ChatsMessages.scrollToBottomAfterImageLoad(mainWrapper.find('[component="chat/message/content"]'));
256
- // Core only marks a room read when its list element carries the
257
- // "unread" class — the admin list doesn't, so mark it explicitly
258
- require(['api'], function(api) {
259
- api.del(`/chats/${roomId}/state`, {}).catch(function() {});
260
- });
256
+ // Read-state is now cleared server-side when the room payload is
257
+ // built; just keep the list UI in sync
261
258
  $('[component="chat/nav-wrapper"]').find(`[data-roomid="${roomId}"]`).removeClass('unread');
262
259
  }
263
260
  if (history.pushState) {
package/library.js CHANGED
@@ -790,15 +790,17 @@ function registerRoutes(app, router, middleware) {
790
790
 
791
791
  const pageController = async (req, res, next) => {
792
792
  try {
793
- // If user is not allowed, redirect to user-specific chat URL
793
+ // Users without admin-chats access get core's behaviour: redirect to
794
+ // their own chats page (helpers.redirect also handles API/ajaxify
795
+ // requests via X-Redirect, so navigation works in one hop)
794
796
  if (req.uid && !await canAccessAdminChats(req.uid)) {
795
797
  const userSlug = await User.getUserField(req.uid, 'userslug');
796
- if (userSlug && req.params.roomId) {
797
- const redirectUrl = `${req.baseUrl || ''}/user/${userSlug}/chats/${req.params.roomId}${req.params.index ? `/${req.params.index}` : ''}`;
798
- return res.redirect(redirectUrl);
798
+ if (userSlug) {
799
+ const suffix = req.params.roomId ? `/${req.params.roomId}${req.params.index ? `/${req.params.index}` : ''}` : '';
800
+ return helpers.redirect(res, `/user/${userSlug}/chats${suffix}`);
799
801
  }
800
802
  }
801
-
803
+
802
804
  await renderAdminChatsPage(req, res, next);
803
805
  } catch (err) {
804
806
  next(err);
@@ -807,6 +809,13 @@ function registerRoutes(app, router, middleware) {
807
809
 
808
810
  const pageRouter = app || router;
809
811
  pageRouter.get('/chats/:roomId?/:index?', middleware.busyCheck, pageMiddlewares, middleware.buildHeader, pageController);
812
+ // Also own the page-API route. Without it, ajaxify entry into /chats/<roomId>
813
+ // (e.g. picking a room from the mobile chat dropdown) hit core's redirect
814
+ // route and bounced through an extra hop before the room finally rendered —
815
+ // showing the chat list in between. Registered on the core router before
816
+ // core's own routes, and covered by middleware.prepareAPI (mounted earlier),
817
+ // so res.render answers with ajaxify JSON in a single round-trip.
818
+ router.get('/api/chats/:roomId?/:index?', pageMiddlewares, pageController);
810
819
 
811
820
  router.get('/api/admin-chats', ...routeMiddleware, async (req, res) => {
812
821
  try {
@@ -1190,6 +1199,16 @@ async function buildAdminChatRoomPayload(uid, roomId, indexParam) {
1190
1199
  return null;
1191
1200
  }
1192
1201
 
1202
+ // Root fix for "message stays unread": core only clears unread state from the
1203
+ // client when the room's nav element carries the `unread` class, which the
1204
+ // admin list never sets. Mark the room read for the viewer on every load.
1205
+ try {
1206
+ await Messaging.markRead(uid, roomId);
1207
+ await Messaging.pushUnreadCount(uid);
1208
+ } catch (err) {
1209
+ // never let read-state bookkeeping break room rendering
1210
+ }
1211
+
1193
1212
  const [canViewInfo, canUploadImage, canUploadFile] = await privileges.global.can([
1194
1213
  'view:users:info', 'upload:post:image', 'upload:post:file',
1195
1214
  ], uid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-admin-chats",
3
- "version": "3.4.3",
3
+ "version": "3.5.0",
4
4
  "description": "A plugin that allows the administrator to view and manage user chats.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {