mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: add linting
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { downloadContentFromMessage } from "./messages-media"
|
||||
import { proto } from "../../WAProto"
|
||||
import { promisify } from 'util'
|
||||
import { inflate } from "zlib"
|
||||
import { Chat, Contact } from "../Types"
|
||||
import { inflate } from 'zlib'
|
||||
import { proto } from '../../WAProto'
|
||||
import { Chat, Contact } from '../Types'
|
||||
import { downloadContentFromMessage } from './messages-media'
|
||||
|
||||
const inflatePromise = promisify(inflate)
|
||||
|
||||
export const downloadHistory = async(msg: proto.IHistorySyncNotification) => {
|
||||
const stream = await downloadContentFromMessage(msg, 'history')
|
||||
let buffer = Buffer.from([])
|
||||
for await(const chunk of stream) {
|
||||
for await (const chunk of stream) {
|
||||
buffer = Buffer.concat([buffer, chunk])
|
||||
}
|
||||
|
||||
// decompress buffer
|
||||
buffer = await inflatePromise(buffer)
|
||||
|
||||
@@ -24,45 +25,47 @@ export const processHistoryMessage = (item: proto.IHistorySync, historyCache: Se
|
||||
const messages: proto.IWebMessageInfo[] = []
|
||||
const contacts: Contact[] = []
|
||||
const chats: Chat[] = []
|
||||
switch(item.syncType) {
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.INITIAL_BOOTSTRAP:
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.RECENT:
|
||||
for(const chat of item.conversations) {
|
||||
const contactId = `c:${chat.id}`
|
||||
if(chat.name && !historyCache.has(contactId)) {
|
||||
contacts.push({
|
||||
id: chat.id,
|
||||
name: chat.name
|
||||
})
|
||||
historyCache.add(contactId)
|
||||
}
|
||||
switch (item.syncType) {
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.INITIAL_BOOTSTRAP:
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.RECENT:
|
||||
for(const chat of item.conversations) {
|
||||
const contactId = `c:${chat.id}`
|
||||
if(chat.name && !historyCache.has(contactId)) {
|
||||
contacts.push({
|
||||
id: chat.id,
|
||||
name: chat.name
|
||||
})
|
||||
historyCache.add(contactId)
|
||||
}
|
||||
|
||||
for(const { message } of chat.messages || []) {
|
||||
const uqId = `${message?.key.remoteJid}:${message.key.id}`
|
||||
if(message && !historyCache.has(uqId)) {
|
||||
messages.push(message)
|
||||
historyCache.add(uqId)
|
||||
}
|
||||
}
|
||||
|
||||
delete chat.messages
|
||||
if(!historyCache.has(chat.id)) {
|
||||
chats.push(chat)
|
||||
historyCache.add(chat.id)
|
||||
for(const { message } of chat.messages || []) {
|
||||
const uqId = `${message?.key.remoteJid}:${message.key.id}`
|
||||
if(message && !historyCache.has(uqId)) {
|
||||
messages.push(message)
|
||||
historyCache.add(uqId)
|
||||
}
|
||||
}
|
||||
break
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.PUSH_NAME:
|
||||
for(const c of item.pushnames) {
|
||||
const contactId = `c:${c.id}`
|
||||
if(historyCache.has(contactId)) {
|
||||
contacts.push({ notify: c.pushname, id: c.id })
|
||||
historyCache.add(contactId)
|
||||
}
|
||||
|
||||
delete chat.messages
|
||||
if(!historyCache.has(chat.id)) {
|
||||
chats.push(chat)
|
||||
historyCache.add(chat.id)
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.INITIAL_STATUS_V3:
|
||||
// TODO
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.PUSH_NAME:
|
||||
for(const c of item.pushnames) {
|
||||
const contactId = `c:${c.id}`
|
||||
if(historyCache.has(contactId)) {
|
||||
contacts.push({ notify: c.pushname, id: c.id })
|
||||
historyCache.add(contactId)
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
case proto.HistorySync.HistorySyncHistorySyncType.INITIAL_STATUS_V3:
|
||||
// TODO
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user