nodebb-plugin-admin-chats 3.8.3 → 3.8.4
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.
- package/lib/overrides.js +3 -2
- package/package.json +1 -1
- package/static/lib/switch-chat.js +42 -0
package/lib/overrides.js
CHANGED
|
@@ -51,7 +51,8 @@ function overrideCoreChatRedirect(controllers, renderAdminChatsPage) {
|
|
|
51
51
|
// its messages from that user's join timestamp, so for a private room the
|
|
52
52
|
// user is not in it comes out empty (title only). Send the viewer to a URL
|
|
53
53
|
// that can actually show the room — their own chats page if they are in it,
|
|
54
|
-
// otherwise the all-chats page.
|
|
54
|
+
// otherwise the all-chats page. This includes the viewer's own slug: an admin
|
|
55
|
+
// reading a room they are not in must stay on the all-chats page.
|
|
55
56
|
function overrideCoreChatsPage(controllers) {
|
|
56
57
|
const chatsController = controllers && controllers.accounts && controllers.accounts.chats;
|
|
57
58
|
if (!chatsController || typeof chatsController.get !== 'function' || chatsController.get._adminChatsWrapped) {
|
|
@@ -64,7 +65,7 @@ function overrideCoreChatsPage(controllers) {
|
|
|
64
65
|
const isSwitch = res.locals.isAPI && parseInt(req.query.switch, 10) === 1;
|
|
65
66
|
if (roomId && !isSwitch && req.uid && await canAccessAdminChats(req.uid)) {
|
|
66
67
|
const uid = await User.getUidByUserslug(req.params.userslug);
|
|
67
|
-
if (uid
|
|
68
|
+
if (uid) {
|
|
68
69
|
const [room, isOwnerInRoom, isCallerInRoom] = await Promise.all([
|
|
69
70
|
Messaging.getRoomData(roomId),
|
|
70
71
|
isUserMemberOfRoom(uid, roomId),
|
package/package.json
CHANGED
|
@@ -215,6 +215,48 @@ $(document).ready(function () {
|
|
|
215
215
|
});
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
// Core's chat scroll handler (updateUrlWithMessageIndex) always rewrites the
|
|
219
|
+
// address to user/<viewer-slug>/chats/<roomId>/<index>. On the all-chats page
|
|
220
|
+
// the viewer is usually not in the room, and that URL renders the room from
|
|
221
|
+
// the viewer's (missing) join timestamp — so a reload/back landed on a room
|
|
222
|
+
// that could not scroll past the first batch. Keep the admin URL scheme.
|
|
223
|
+
function patchReplaceStateForAdminAll() {
|
|
224
|
+
if (!history.replaceState || history.replaceState._adminAllChatsPatched) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const originalReplaceState = history.replaceState;
|
|
229
|
+
const patchedReplaceState = function (state, title, url) {
|
|
230
|
+
const userslug = ajaxify && ajaxify.data && ajaxify.data.userslug;
|
|
231
|
+
if (isAdminAllChatsPage() && userslug && typeof url === 'string') {
|
|
232
|
+
const prefix = `${config.relative_path || ''}/user/${userslug}/chats/`;
|
|
233
|
+
const parsed = new URL(url, window.location.href);
|
|
234
|
+
// Non-ASCII slugs come back percent-encoded in URL#pathname
|
|
235
|
+
let pathname = parsed.pathname;
|
|
236
|
+
try {
|
|
237
|
+
pathname = decodeURIComponent(pathname);
|
|
238
|
+
} catch (err) {
|
|
239
|
+
// keep the raw pathname
|
|
240
|
+
}
|
|
241
|
+
const match = pathname.startsWith(prefix) &&
|
|
242
|
+
pathname.slice(prefix.length).match(/^(\d+(?:\/\d+)?)$/);
|
|
243
|
+
if (match) {
|
|
244
|
+
const newUrl = getAdminChatsPageUrl(match[1]);
|
|
245
|
+
parsed.pathname = `${config.relative_path || ''}/${newUrl}`;
|
|
246
|
+
url = parsed.href;
|
|
247
|
+
if (state && typeof state.url === 'string') {
|
|
248
|
+
state = { ...state, url: newUrl + parsed.search };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return originalReplaceState.call(this, state, title, url);
|
|
253
|
+
};
|
|
254
|
+
patchedReplaceState._adminAllChatsPatched = true;
|
|
255
|
+
history.replaceState = patchedReplaceState;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
patchReplaceStateForAdminAll();
|
|
259
|
+
|
|
218
260
|
$(window).on('action:ajaxify.end', function (ev, data) {
|
|
219
261
|
if (isAdminAllChatsPage()) {
|
|
220
262
|
patchForumChatsForAdminAll();
|