Skip to content

Commit

Permalink
fix: Migrated many stores to WA-JS
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 29, 2021
1 parent 68e7a54 commit b55dab3
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/lib/wapi/business/get-business-profiles-products.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/

export async function getBusinessProfilesProducts(id) {
let catalog = window.Store.Catalog.get(id);
let catalog = WPP.whatsapp.CatalogStore.get(id);
if (!catalog) {
catalog = await window.Store.Catalog.find(
catalog = await WPP.whatsapp.CatalogStore.find(
WPP.whatsapp.WidFactory.createWid(id)
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/business/get-order-by-msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export async function getOrderbyMsg(msgId) {
message: 'Message is not an order',
};
}
let order = window.Store.Order.get(msg.orderId);
let order = WPP.whatsapp.OrderStore.get(msg.orderId);
if (!order) {
order = await window.Store.Order.findOrder(
order = await WPP.whatsapp.OrderStore.findOrder(
msg.orderId,
msg.sellerJid,
msg.token
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-all-contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

export const getAllContacts = async function () {
let contacts = await Promise.all(
window.Store.Contact.map(async (contact) => {
WPP.whatsapp.ContactStore.map(async (contact) => {
return await WAPI._serializeContactObj(contact);
})
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

export const getContact = function (id, done) {
const found = window.Store.Contact.get(id);
const found = WPP.whatsapp.ContactStore.get(id);

if (done !== undefined) done(window.WAPI._serializeContactObj(found));
return window.WAPI._serializeContactObj(found);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

export function getMe(done) {
const rawMe = window.Store.Contact.get(window.Store.Conn.me);
const rawMe = WPP.whatsapp.ContactStore.get(window.Store.Conn.me);

if (done !== undefined) done(rawMe.all);
return rawMe.all;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-my-contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

export const getMyContacts = function (done) {
const contacts = window.Store.Contact.filter(
const contacts = WPP.whatsapp.ContactStore.filter(
(contact) => contact.isMyContact === true
).map((contact) => WAPI._serializeContactObj(contact));
if (done !== undefined) done(contacts);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/wapi/functions/is-logged-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
export function isLoggedIn(done) {
// Contact always exists when logged in
const isLogged =
window.Store.Contact && window.Store.Contact.checksum !== undefined;
WPP.whatsapp.ContactStore &&
WPP.whatsapp.ContactStore.checksum !== undefined;

if (done !== undefined) done(isLogged);
return isLogged;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/open-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

export async function openChat(chatId) {
const chat = WPP.whatsapp.ChatStore.get(chatId);
const result = Store.Cmd.default.openChatBottom(chat);
const result = WPP.whatsapp.Cmd.openChatBottom(chat);
return result;
}

Expand All @@ -36,6 +36,6 @@ export async function openChatAt(chatId, messageId) {
msg: atMessage,
isUnreadDivider: false,
};
const result = await Store.Cmd.default._openChat(chat, args);
const result = await WPP.whatsapp.Cmd._openChat(chat, args);
return result;
}
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/reject-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

async function rejectCallByCallId(callId) {
const call = await Store.Call.get(callId);
const call = WPP.whatsapp.CallStore.get(callId);

if (!call) {
throw {
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function rejectCall(callId) {
return 1;
}

const calls = Store.Call.models.filter(
const calls = WPP.whatsapp.CallStore.models.filter(
(c) => c.getState() === 'INCOMING_RING'
);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-image-with-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function sendImageWithProduct(
productId,
done
) {
Store.Catalog.findCarouselCatalog(bizNumber).then((cat) => {
WPP.whatsapp.CatalogStore.findCarouselCatalog(bizNumber).then((cat) => {
if (cat && cat[0]) {
const product = cat[0].productCollection.get(productId);
const temp = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function sendLocation(
var result =
(
await Promise.all(
Store.WPP.whatsapp.functions.addAndSendMsgToChat(chat, message)
WPP.whatsapp.functions.addAndSendMsgToChat(chat, message)
)
)[1] || '';
var m = {
Expand Down
14 changes: 7 additions & 7 deletions src/lib/wapi/functions/sendMessageOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function sendMessageOptions(chatId, content, options = {}) {

if (options.mentionedJidList) {
options.mentionedJidList = options.mentionedJidList.map(
(cId) => window.Store.Contact.get(cId).id
(cId) => WPP.whatsapp.ContactStore.get(cId).id
);
}

Expand All @@ -68,19 +68,19 @@ export async function sendMessageOptions(chatId, content, options = {}) {

let vcardOptions = {};
if (options.contactCard) {
let contact = window.Store.Contact.get(options.contactCard);
let contact = WPP.whatsapp.ContactStore.get(options.contactCard);
vcardOptions = {
body: window.Store.VCard.vcardFromContactModel(contact).vcard,
body: WPP.whatsapp.VCard.vcardFromContactModel(contact).vcard,
type: 'vcard',
vcardFormattedName: contact.formattedName,
};
delete options.contactCard;
} else if (options.contactCardList) {
let contacts = options.contactCardList.map((c) =>
window.Store.Contact.get(c)
WPP.whatsapp.ContactStore.get(c)
);
let vcards = contacts.map((c) =>
window.Store.VCard.vcardFromContactModel(c)
WPP.whatsapp.VCard.vcardFromContactModel(c)
);
vcardOptions = {
type: 'multi_vcard',
Expand All @@ -95,11 +95,11 @@ export async function sendMessageOptions(chatId, content, options = {}) {
) {
delete options.parseVCards;
try {
const parsed = await window.Store.VCard.parseVcard(content);
const parsed = await WPP.whatsapp.VCard.parseVcard(content);
if (parsed) {
vcardOptions = {
type: 'vcard',
vcardFormattedName: await window.Store.VCard.vcardGetNameFromParsed(
vcardFormattedName: await WPP.whatsapp.VCard.vcardGetNameFromParsed(
parsed
),
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ if (typeof window.WAPI === 'undefined') {
}

const chat = WAPI.getChat(chatId);
const users = await Store.Contact.serialize().filter((x) =>
const users = await WPP.whatsapp.ContactStore.serialize().filter((x) =>
mentioned.includes(x.id.user)
);

Expand Down

0 comments on commit b55dab3

Please sign in to comment.