nodebb-plugin-admin-chats 3.6.0 → 3.6.1
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/hooks.js +7 -1
- package/package.json +1 -1
- package/static/lib/profile-link.js +25 -7
package/lib/hooks.js
CHANGED
|
@@ -94,13 +94,19 @@ hooks.addProfileLink = async function (data) {
|
|
|
94
94
|
return data;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// Nothing to moderate on your own profile — /user/<self>/chats is just the
|
|
98
|
+
// regular chat list, already reachable from the main menu.
|
|
99
|
+
if (parseInt(data.uid, 10) === parseInt(viewerUid, 10)) {
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
data.links.push({
|
|
98
104
|
id: 'admin-view-chats',
|
|
99
105
|
route: 'chats',
|
|
100
106
|
icon: 'fa-comments',
|
|
101
107
|
name: '[[admin-chats:profile.viewChats]]',
|
|
102
108
|
visibility: {
|
|
103
|
-
self:
|
|
109
|
+
self: false, other: true, moderator: true, globalMod: true, admin: true,
|
|
104
110
|
},
|
|
105
111
|
});
|
|
106
112
|
|
package/package.json
CHANGED
|
@@ -28,7 +28,18 @@ $(document).ready(function () {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// Drop everything a previous run of this function left behind. Runs can
|
|
32
|
+
// overlap (ajaxify.end may fire more than once per page) and each one
|
|
33
|
+
// awaits, so without this a bail-out — or a second run — leaves an orphan
|
|
34
|
+
// gear button on the page.
|
|
35
|
+
function removePreviousInjection() {
|
|
36
|
+
$('.admin-chats-privileges-menu').remove();
|
|
37
|
+
$('.admin-chats-profile-link, .admin-chats-profile-divider').remove();
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
async function injectProfileChatsLink() {
|
|
41
|
+
removePreviousInjection();
|
|
42
|
+
|
|
32
43
|
const isUserProfile = $('.account').length && window.location.pathname.includes('/user/');
|
|
33
44
|
if (!isUserProfile || !await resolveAdminChatsAccess()) {
|
|
34
45
|
return;
|
|
@@ -39,6 +50,15 @@ $(document).ready(function () {
|
|
|
39
50
|
return;
|
|
40
51
|
}
|
|
41
52
|
|
|
53
|
+
// Own profile: /user/<self>/chats is just the regular chat list, so the
|
|
54
|
+
// moderation entry point has nothing to add there. Harmony doesn't
|
|
55
|
+
// render its own gear menu here either ({{{ if !isSelf }}}), so bailing
|
|
56
|
+
// out has to leave no button behind at all.
|
|
57
|
+
const profileUid = parseInt(ajaxify.data.uid || (ajaxify.data.user && ajaxify.data.user.uid), 10);
|
|
58
|
+
if (profileUid && parseInt(app.user.uid, 10) === profileUid) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
42
62
|
const relativePath = config.relative_path || '';
|
|
43
63
|
// Injected via jQuery rather than a template, so [[...]] needs an
|
|
44
64
|
// explicit translator call here — nothing else will resolve it.
|
|
@@ -56,11 +76,13 @@ $(document).ready(function () {
|
|
|
56
76
|
</li>
|
|
57
77
|
`;
|
|
58
78
|
|
|
59
|
-
|
|
79
|
+
const menu = $('.account-sub-links').first();
|
|
60
80
|
if (!menu.length) {
|
|
61
81
|
// No admin/ban/mute menu was rendered for this viewer (they only
|
|
62
82
|
// hold the admin-chats privilege) — build a minimal dropdown of
|
|
63
|
-
// our own next to the other profile action buttons.
|
|
83
|
+
// our own next to the other profile action buttons. The item goes
|
|
84
|
+
// in before the dropdown is attached, so a half-built gear can
|
|
85
|
+
// never end up on the page.
|
|
64
86
|
const container = $('.account .flex-shrink-0.d-flex.gap-1').first();
|
|
65
87
|
const fallbackContainer = container.length ? container : $('.account .flex-shrink-0').first();
|
|
66
88
|
|
|
@@ -70,14 +92,10 @@ $(document).ready(function () {
|
|
|
70
92
|
<button type="button" class="btn btn-light dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
71
93
|
<i class="fa fa-gear fa-fw"></i>
|
|
72
94
|
</button>
|
|
73
|
-
<ul class="dropdown-menu dropdown-menu-end p-1 text-sm account-sub-links" role="menu"
|
|
95
|
+
<ul class="dropdown-menu dropdown-menu-end p-1 text-sm account-sub-links" role="menu">${menuItemHtml}</ul>
|
|
74
96
|
</div>
|
|
75
97
|
`);
|
|
76
|
-
menu = fallbackContainer.find('.account-sub-links').last();
|
|
77
98
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!menu.length) {
|
|
81
99
|
return;
|
|
82
100
|
}
|
|
83
101
|
|