nodebb-plugin-admin-chats 3.0.0 → 3.0.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.
Files changed (2) hide show
  1. package/client.js +58 -0
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -588,6 +588,64 @@ $(document).ready(function() {
588
588
  return await response.json();
589
589
  }
590
590
 
591
+ async function injectProfileChatsMenu() {
592
+ const allowed = await resolveAdminChatsAccess();
593
+ if (!allowed) {
594
+ return;
595
+ }
596
+
597
+ const isUserProfile = $(".account").length && window.location.pathname.includes("/user/");
598
+ if (!isUserProfile) {
599
+ return;
600
+ }
601
+
602
+ const userSlug = (ajaxify && ajaxify.data && (ajaxify.data.userslug || (ajaxify.data.user && ajaxify.data.user.userslug))) || null;
603
+ if (!userSlug) {
604
+ return;
605
+ }
606
+
607
+ const relativePath = config.relative_path || "";
608
+ const menuItemHtml = `
609
+ <li role="presentation" class="admin-chats-profile-link">
610
+ <a class="dropdown-item rounded-1 d-flex align-items-center gap-2" href="${relativePath}/user/${userSlug}/chats" role="menuitem">
611
+ <i class="far fa-fw fa-comments"></i>
612
+ <span>${t("viewChats")}</span>
613
+ </a>
614
+ </li>
615
+ `;
616
+
617
+ let menu = $(".account-sub-links");
618
+ if (!menu.length) {
619
+ const container = $(".account .flex-shrink-0.d-flex.gap-1").first();
620
+ const fallbackContainer = container.length ? container : $(".account .flex-shrink-0").first();
621
+
622
+ if (fallbackContainer.length) {
623
+ const menuHtml = `
624
+ <div class="btn-group bottom-sheet admin-chats-privileges-menu">
625
+ <button type="button" class="btn btn-light dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
626
+ <i class="fa fa-gear fa-fw"></i>
627
+ </button>
628
+ <ul class="dropdown-menu dropdown-menu-end p-1 text-sm account-sub-links" role="menu"></ul>
629
+ </div>
630
+ `;
631
+ fallbackContainer.append(menuHtml);
632
+ menu = fallbackContainer.find(".account-sub-links").last();
633
+ }
634
+ }
635
+
636
+ if (menu.length) {
637
+ menu.find(".admin-chats-profile-link").remove();
638
+ menu.find(".admin-chats-profile-divider").remove();
639
+ menu.find(`a[href*="/user/${userSlug}/chats"]`).parent().remove();
640
+ menu.prepend(menuItemHtml);
641
+
642
+ const hasOtherItems = menu.find("li").not(".admin-chats-profile-link").length > 0;
643
+ if (hasOtherItems) {
644
+ menu.find(".admin-chats-profile-link").after('<li role="presentation" class="dropdown-divider admin-chats-profile-divider"></li>');
645
+ }
646
+ }
647
+ }
648
+
591
649
  $(window).on('action:ajaxify.end', function(ev, data) {
592
650
  syncAdminAccessFromAjaxify();
593
651
  fetchAdminPrivileges();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-admin-chats",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A plugin that allows the administrator to view and manage user chats.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {