nodebb-plugin-admin-chats 3.2.0 → 3.3.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.
- package/library.js +38 -25
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -113,7 +113,6 @@ async function getLockedActionMessage(uid) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
const ADMIN_CHAT_PAGE_SIZE = 30;
|
|
116
|
-
const ADMIN_CHAT_SCAN_SIZE = 100;
|
|
117
116
|
|
|
118
117
|
async function canAccessAdminChats(uid) {
|
|
119
118
|
if (!uid) {
|
|
@@ -970,42 +969,57 @@ async function getPrivateRoomCount() {
|
|
|
970
969
|
}
|
|
971
970
|
|
|
972
971
|
async function getAdminRecentChats(uid, start, limit) {
|
|
973
|
-
|
|
974
|
-
const
|
|
972
|
+
const offset = Math.max(0, parseInt(start, 10) || 0);
|
|
973
|
+
const pageSize = Math.max(0, parseInt(limit, 10) || 0);
|
|
974
|
+
const allRoomIds = await db.getSortedSetRevRange('chat:rooms', 0, -1);
|
|
975
975
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
976
|
+
if (!allRoomIds.length || !pageSize) {
|
|
977
|
+
return {
|
|
978
|
+
rooms: [],
|
|
979
|
+
nextStart: offset,
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const allRooms = await Messaging.getRoomsData(allRoomIds);
|
|
984
|
+
const roomPairs = (await Promise.all(allRooms.map(async (room, index) => {
|
|
985
|
+
const roomId = parseInt(allRoomIds[index], 10) || 0;
|
|
986
|
+
if (!room || room.public || !roomId) {
|
|
987
|
+
return null;
|
|
980
988
|
}
|
|
981
989
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
});
|
|
989
|
-
}
|
|
990
|
-
});
|
|
990
|
+
return {
|
|
991
|
+
roomId,
|
|
992
|
+
room,
|
|
993
|
+
lastActivity: await getAdminRoomLastActivity(roomId, room),
|
|
994
|
+
};
|
|
995
|
+
}))).filter(Boolean);
|
|
991
996
|
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
}
|
|
997
|
+
roomPairs.sort((a, b) => (
|
|
998
|
+
b.lastActivity - a.lastActivity ||
|
|
999
|
+
b.roomId - a.roomId
|
|
1000
|
+
));
|
|
997
1001
|
|
|
998
|
-
const
|
|
999
|
-
const
|
|
1002
|
+
const pagedRooms = roomPairs.slice(offset, offset + pageSize);
|
|
1003
|
+
const rooms = pagedRooms.map(item => item.room);
|
|
1004
|
+
const roomIds = pagedRooms.map(item => item.roomId);
|
|
1000
1005
|
|
|
1001
1006
|
await enrichAdminRecentRooms(uid, roomIds, rooms);
|
|
1002
1007
|
|
|
1003
1008
|
return {
|
|
1004
1009
|
rooms,
|
|
1005
|
-
nextStart:
|
|
1010
|
+
nextStart: offset + rooms.length,
|
|
1006
1011
|
};
|
|
1007
1012
|
}
|
|
1008
1013
|
|
|
1014
|
+
async function getAdminRoomLastActivity(roomId, room) {
|
|
1015
|
+
const lastMessage = await db.getSortedSetRevRangeWithScores(`chat:room:${roomId}:mids`, 0, 0);
|
|
1016
|
+
if (lastMessage.length) {
|
|
1017
|
+
return parseInt(lastMessage[0].score, 10) || 0;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return parseInt(room && room.timestamp, 10) || 0;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1009
1023
|
async function enrichAdminRecentRooms(uid, roomIds, rooms) {
|
|
1010
1024
|
if (!roomIds.length) {
|
|
1011
1025
|
return;
|
|
@@ -1248,4 +1262,3 @@ module.exports = plugin;
|
|
|
1248
1262
|
|
|
1249
1263
|
|
|
1250
1264
|
|
|
1251
|
-
|