lotusbail
Version:
WhatsApp API x Button by PL
8 lines (7 loc) • 2.56 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});exports.getHistoryMsg=exports.downloadAndProcessHistorySyncNotification=exports.processHistoryMessage=exports.downloadHistory=void 0;
const util_1=require("util"),zlib_1=require("zlib"),WAProto_1=require("../../WAProto"),Types_1=require("../Types"),WABinary_1=require("../WABinary"),generics_1=require("./generics"),messages_1=require("./messages"),messages_media_1=require("./messages-media"),inflatePromise=(0,util_1.promisify)(zlib_1.inflate),downloadHistory=async(a,c)=>{a=await (0,messages_media_1.downloadContentFromMessage)(a,"md-msg-hist",{options:c});c=[];for await(var e of a)c.push(e);e=Buffer.concat(c);e=await inflatePromise(e);
return WAProto_1.proto.HistorySync.decode(e)};exports.downloadHistory=downloadHistory;
const processHistoryMessage=a=>{var c,e,g;const h=[],f=[],k=[];switch(a.syncType){case WAProto_1.proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:case WAProto_1.proto.HistorySync.HistorySyncType.RECENT:case WAProto_1.proto.HistorySync.HistorySyncType.FULL:case WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND:for(const d of a.conversations){f.push({id:d.id,name:d.name||void 0,lid:d.lidJid||void 0,jid:(0,WABinary_1.isJidUser)(d.id)?d.id:void 0});var b=d.messages||[];delete d.messages;for(const l of b)b=
l.message,h.push(b),null!==(c=d.messages)&&void 0!==c&&c.length||(d.messages=[{message:b}]),b.key.fromMe||d.lastMessageRecvTimestamp||(d.lastMessageRecvTimestamp=(0,generics_1.toNumber)(b.messageTimestamp)),(b.messageStubType===Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP||b.messageStubType===Types_1.WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB)&&(null===(e=b.messageStubParameters)||void 0===e?0:e[0])&&f.push({id:b.key.participant||b.key.remoteJid,verifiedName:null===(g=b.messageStubParameters)||
void 0===g?void 0:g[0]});k.push({...d})}break;case WAProto_1.proto.HistorySync.HistorySyncType.PUSH_NAME:for(b of a.pushnames)f.push({id:b.id,notify:b.pushname})}return{chats:k,contacts:f,messages:h,syncType:a.syncType,progress:a.progress}};exports.processHistoryMessage=processHistoryMessage;const downloadAndProcessHistorySyncNotification=async(a,c)=>{a=await (0,exports.downloadHistory)(a,c);return(0,exports.processHistoryMessage)(a)};exports.downloadAndProcessHistorySyncNotification=downloadAndProcessHistorySyncNotification;
const getHistoryMsg=a=>{var c;a=a?(0,messages_1.normalizeMessageContent)(a):void 0;return null===(c=null===a||void 0===a?void 0:a.protocolMessage)||void 0===c?void 0:c.historySyncNotification};exports.getHistoryMsg=getHistoryMsg;