-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkQueue.js
38 lines (31 loc) · 929 Bytes
/
checkQueue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import fs from 'fs'
const initMessages = JSON.parse(fs.readFileSync('messages.json', 'utf-8'))
const gotMessages = JSON.parse(fs.readFileSync('got.json', 'utf-8'))
function groupByChatId (messages) {
const map = new Map()
for (const msg of messages) {
const chatId = msg.key
const accountId = msg.value
if (map.get(chatId)) {
map.set(chatId, [...map.get(chatId), accountId])
} else {
map.set(chatId, [accountId])
}
}
return map
}
const grouped = groupByChatId(initMessages)
main: for (const entry of grouped.entries()) {
const chatId = entry[0]
let lastIdx = 0
for (const msg of entry[1]) {
const curIdx = gotMessages.findIndex(m => m.value === msg)
if (curIdx >= lastIdx) {
lastIdx = curIdx
} else {
console.log(`queue corrupted for chatId ${chatId}`, msg, { curIdx, lastIdx })
break main
}
}
console.log('success for chat', chatId)
}