nodebb-plugin-chat-search 0.0.1 → 0.0.2

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/library.js CHANGED
@@ -23,7 +23,6 @@ async function searchGlobal(socket, data) {
23
23
  }
24
24
 
25
25
  let targetUid = socket.uid;
26
- // בדיקת הרשאות (אדמין צופה במישהו אחר)
27
26
  if (data.targetUid && parseInt(data.targetUid, 10) !== parseInt(socket.uid, 10)) {
28
27
  const isAdmin = await user.isAdministrator(socket.uid);
29
28
  if (!isAdmin) {
@@ -38,12 +37,10 @@ async function searchGlobal(socket, data) {
38
37
  let allResults = [];
39
38
 
40
39
  for (const roomId of roomIds) {
41
- // בדיקת חברות
42
40
  const inRoom = await messaging.isUserInRoom(targetUid, roomId);
43
41
  if (!inRoom) continue;
44
42
 
45
43
  try {
46
- // 1. שליפת הודעות
47
44
  const messages = await messaging.getMessages({
48
45
  callerUid: socket.uid,
49
46
  uid: targetUid,
@@ -60,32 +57,41 @@ async function searchGlobal(socket, data) {
60
57
  );
61
58
 
62
59
  if (matches.length > 0) {
63
- // --- תיקון שליפת המשתתפים ---
64
- // במקום להסתמך על roomData, נשלוף UIDs ואז Users
60
+ // שליפת משתמשים
65
61
  const uids = await messaging.getUidsInRoom(roomId, 0, -1);
66
- const usersData = await user.getUsersFields(uids, ['uid', 'username', 'picture']);
62
+ const usersData = await user.getUsersFields(uids, ['uid', 'username']);
67
63
 
68
- // סינון המשתמש שבו אנו צופים
69
- const participants = usersData
70
- .filter(u => parseInt(u.uid, 10) !== parseInt(targetUid, 10))
71
- .map(u => u.username)
72
- .join(', ');
64
+ // סינון המשתמש הנוכחי (משאירים רק את הפרטנרים)
65
+ const otherUsers = usersData.filter(u => parseInt(u.uid, 10) !== parseInt(targetUid, 10));
66
+
67
+ // --- לוגיקת הקיצור (2 שמות + ועוד X) ---
68
+ let displayName = '';
69
+
70
+ if (otherUsers.length === 0) {
71
+ displayName = 'צ\'אט עצמי'; // או משתמש מחוק
72
+ } else if (otherUsers.length <= 2) {
73
+ // אם יש 1 או 2, מציגים את כולם
74
+ displayName = otherUsers.map(u => u.username).join(', ');
75
+ } else {
76
+ // אם יש יותר מ-2, לוקחים את ה-2 הראשונים ומוסיפים את היתרה
77
+ const firstTwo = otherUsers.slice(0, 2).map(u => u.username).join(', ');
78
+ const remaining = otherUsers.length - 2;
79
+ displayName = `${firstTwo} ועוד ${remaining} משתמשים`;
80
+ }
81
+ // ----------------------------------------
73
82
 
74
- // --- תיקון שליפת שם החדר ---
75
83
  const roomData = await messaging.getRoomData(roomId);
76
- let roomName = (roomData && roomData.roomName) || participants || `חדר ${roomId}`;
84
+ // שם החדר: אם יש שם מוגדר לקבוצה - קח אותו, אחרת קח את השמות שיצרנו
85
+ let roomName = (roomData && roomData.roomName) || displayName;
77
86
 
78
- // --- תיקון שם השולח (במקרה שחסר בהודעה) ---
79
- // אם חסר אובייקט user בהודעה, נשלים אותו מתוך usersData ששלפנו הרגע
80
87
  matches.forEach(m => {
81
88
  if (!m.user || !m.user.username) {
82
89
  const sender = usersData.find(u => parseInt(u.uid, 10) === parseInt(m.fromuid, 10));
83
90
  m.user = sender || { username: 'Unknown' };
84
91
  }
85
-
86
92
  m.roomName = roomName;
87
- m.chatWith = participants;
88
93
  m.targetUid = targetUid;
94
+ // מחקנו את chatWith כי כבר לא צריך אותו
89
95
  });
90
96
 
91
97
  allResults = allResults.concat(matches);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-chat-search",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A plugin to search text within NodeBB chats",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  $(document).ready(function () {
4
- console.log('[Chat Search] Loaded (AJAX Fix).');
4
+ console.log('[Chat Search] Loaded (Clean UI).');
5
5
 
6
- // בכל מעבר דף, אנחנו מוחקים את הישן ומתחילים חיפוש חדש של הקונטיינר
7
6
  $(window).on('action:ajaxify.end', function (ev, data) {
8
- $('#global-chat-search-container').remove(); // איפוס
7
+ $('#global-chat-search-container').remove();
9
8
 
10
- // בדיקה: האם אנחנו בעמוד צ'אטים?
11
- // גם לפי URL וגם לפי Template
12
9
  const isChatUrl = data.url.match(/^(user\/[^\/]+\/)?chats/);
13
10
  const isChatTemplate = data.template && data.template.name === 'chats';
14
11
 
@@ -21,8 +18,7 @@ $(document).ready(function () {
21
18
  handleScrollToMessage();
22
19
  });
23
20
 
24
- // הרצה ראשונית (למקרה של ריענון מלא)
25
- if (ajaxify.data.template && ajaxify.data.template.name === 'chats') {
21
+ if (ajaxify.data && ajaxify.data.template && ajaxify.data.template.name === 'chats') {
26
22
  waitForElementAndAdd();
27
23
  }
28
24
 
@@ -30,19 +26,16 @@ $(document).ready(function () {
30
26
  let attempts = 0;
31
27
  const interval = setInterval(function() {
32
28
  attempts++;
33
-
34
- // חיפוש הקונטיינר החדש שנוצר
35
29
  let container = $('[component="chat/nav-wrapper"]');
36
30
  if (container.length === 0) container = $('.chats-page').find('.col-md-4').first();
37
31
 
38
- // ברגע שמצאנו - מזריקים ועוצרים
39
32
  if (container.length > 0) {
40
33
  addGlobalSearchBar(container);
41
34
  clearInterval(interval);
42
- } else if (attempts >= 20) { // מנסים במשך 4 שניות
35
+ } else if (attempts >= 20) {
43
36
  clearInterval(interval);
44
37
  }
45
- }, 200); // בדיקה מהירה כל 200ms
38
+ }, 200);
46
39
  }
47
40
 
48
41
  function addGlobalSearchBar(container) {
@@ -108,50 +101,9 @@ $(document).ready(function () {
108
101
  const chatLink = baseUrl + '/' + msg.roomId + '?mid=' + msg.mid;
109
102
  const senderName = (msg.user && msg.user.username) ? msg.user.username : 'Unknown';
110
103
 
111
- let participantsHtml = '';
112
- if (msg.chatWith) {
113
- participantsHtml = `<div style="font-size:11px; color:#005999; margin-bottom:2px;"><i class="fa fa-users"></i> עם: <strong>${msg.chatWith}</strong></div>`;
114
- }
104
+ // הסרנו את השורה של "עם: ..."
115
105
 
116
106
  html += `
117
- <li class="list-group-item search-result" style="cursor:pointer; border-bottom: 1px solid #f0f0f0; padding: 8px;" onclick="ajaxify.go('${chatLink}')">
118
- <div style="font-size:13px; color:#333; margin-bottom:2px;">
119
- <strong>${msg.roomName}</strong>
120
- <span class="pull-left text-muted" style="font-size:10px;">${date}</span>
121
- </div>
122
- ${participantsHtml}
123
- <div style="font-size:12px; color:#444; background: #f9f9f9; padding: 4px; border-radius: 3px; border-right: 2px solid #007bff;">
124
- <strong>${senderName}:</strong> ${msg.content}
125
- </div>
126
- </li>
127
- `;
128
- });
129
- html += '</ul>';
130
- resultsContainer.html(html);
131
- });
132
- }
133
-
134
- function handleScrollToMessage() {
135
- const params = new URLSearchParams(window.location.search);
136
- const mid = params.get('mid');
137
- if (!mid) return;
138
-
139
- scrollToId(mid);
140
- let attempts = 0;
141
- const scrollInt = setInterval(() => {
142
- attempts++;
143
- if (scrollToId(mid) || attempts > 10) clearInterval(scrollInt);
144
- }, 500);
145
- }
146
-
147
- function scrollToId(mid) {
148
- const el = $('[data-mid="' + mid + '"]');
149
- if (el.length > 0) {
150
- el[0].scrollIntoView({ behavior: 'smooth', block: 'center' });
151
- el.css('background', '#fffeca').css('transition', 'background 1s');
152
- setTimeout(() => el.css('background', ''), 2000);
153
- return true;
154
- }
155
- return false;
156
- }
157
- });
107
+ <li class="list-group-item search-result" style="cursor:pointer; border-bottom: 1px solid #f0f0f0; padding: 10px 8px;" onclick="ajaxify.go('${chatLink}')">
108
+ <div style="font-size:13px; color:#333; margin-bottom:5px;">
109
+ <span class="pull-left text-muted"