Download message attachments (images, documents, etc)

This commit is contained in:
Pedro Lopez
2019-11-24 04:23:08 -04:00
parent dfcf76c139
commit 64912dccfd
4 changed files with 74 additions and 6 deletions

View File

@@ -8,12 +8,12 @@ exports.ExposeStore = (moduleRaidStr) => {
window.mR = moduleRaid();
window.Store = window.mR.findModule("Chat")[1].default;
window.Store.AppState = window.mR.findModule("STREAM")[0].default;
window.Store.CryptoLib = window.mR.findModule("decryptE2EMedia")[0];
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
}
exports.LoadCustomSerializers = () => {
exports.LoadUtils = () => {
window.WWebJS = {};
window.WWebJS.getChatModel = chat => {
@@ -37,6 +37,45 @@ exports.LoadCustomSerializers = () => {
const chats = Store.Chat.models;
return chats.map(chat => WWebJS.getChatModel(chat));
}
window.WWebJS.downloadBuffer = (url) => {
return new Promise(function(resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (xhr.status == 200) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send(null);
});
}
window.WWebJS.readBlobAsync = (blob) => {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.onload = () => {
resolve(reader.result);
};
reader.onerror = reject;
reader.readAsDataURL(blob);
})
}
}
exports.MarkAllRead = () => {