Skip to content

Commit

Permalink
fix: Fixed compatibility of ContactModel for WhatsApp >= 2.2327.4 (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 2, 2023
1 parent 659e72e commit b960710
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/contact/index.ts
Expand Up @@ -14,4 +14,6 @@
* limitations under the License.
*/

import './patch';

export * from './functions';
71 changes: 71 additions & 0 deletions src/contact/patch.ts
@@ -0,0 +1,71 @@
/*!
* Copyright 2023 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as webpack from '../webpack';
import { ContactModel, functions } from '../whatsapp';

webpack.onInjected(applyPatch);

function applyPatch() {
const funcs: {
[key: string]: (...args: any[]) => any;
} = {
isMyContact: functions.getIsMyContact,
mentionName: functions.getMentionName,
notifyName: functions.getNotifyName,
pnForLid: functions.getPnForLid,
displayNameOrPnForLid: functions.getDisplayNameOrPnForLid,
formattedPhone: functions.getFormattedPhone,
userid: functions.getUserid,
userhash: functions.getUserhash,
searchName: functions.getSearchName,
searchVerifiedName: functions.getSearchVerifiedName,
header: functions.getHeader,
isMe: functions.getIsMe,
isUser: functions.getIsUser,
isGroup: functions.getIsGroup,
isBroadcast: functions.getIsBroadcast,
isPSA: functions.getIsPSA,
isIAS: functions.getIsIAS,
isSupportAccount: functions.getIsSupportAccount,
formattedShortNameWithNonBreakingSpaces:
functions.getFormattedShortNameWithNonBreakingSpaces,
formattedShortName: functions.getFormattedShortName,
formattedName: functions.getFormattedName,
formattedUser: functions.getFormattedUser,
isWAContact: functions.getIsWAContact,
canRequestPhoneNumber: functions.getCanRequestPhoneNumber,
showBusinessCheckmarkAsPrimary: functions.getShowBusinessCheckmarkAsPrimary,
showBusinessCheckmarkAsSecondary:
functions.getShowBusinessCheckmarkAsSecondary,
showBusinessCheckmarkInChatlist:
functions.getShowBusinessCheckmarkInChatlist,
isDisplayNameApproved: functions.getIsDisplayNameApproved,
shouldForceBusinessUpdate: functions.getShouldForceBusinessUpdate,
};

for (const attr in funcs) {
const func = funcs[attr];
if (typeof (ContactModel.prototype as any)[attr] === 'undefined') {
Object.defineProperty(ContactModel.prototype, attr, {
get: function () {
return func(this);
},
configurable: true,
});
}
}
}
276 changes: 276 additions & 0 deletions src/whatsapp/functions/contactFunctions.ts
@@ -0,0 +1,276 @@
/*!
* Copyright 2023 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { injectFallbackModule } from '../../webpack';
import { exportModule } from '../exportModule';
import { ContactModel } from '../models';

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getMentionName(contact: ContactModel): string;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getNotifyName(contact: ContactModel): string;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getPremiumMessageName(contact: ContactModel): string;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getUserid(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getUserhash(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getSearchVerifiedName(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getHeader(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsMe(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsUser(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsGroup(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsBroadcast(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsPSA(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsIAS(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsSupportAccount(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsWAContact(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsMyContact(contact: ContactModel): boolean;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getCanRequestPhoneNumber(
contact: ContactModel
): boolean;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getShowBusinessCheckmarkAsPrimary(
contact: ContactModel
): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getShowBusinessCheckmarkAsSecondary(
contact: ContactModel
): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getShowBusinessCheckmarkInChatlist(
contact: ContactModel
): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getIsDisplayNameApproved(contact: ContactModel): any;

/**
* @whatsapp 660666 >= 2.2327.4
*/
export declare function getShouldForceBusinessUpdate(
contact: ContactModel
): any;

exportModule(
exports,
{
getNotifyName: 'getNotifyName',
getMentionName: 'getMentionName',
getPremiumMessageName: 'getPremiumMessageName',
getUserid: 'getUserid',
getUserhash: 'getUserhash',
getSearchVerifiedName: 'getSearchVerifiedName',
getHeader: 'getHeader',
getIsMe: 'getIsMe',
getIsUser: 'getIsUser',
getIsGroup: 'getIsGroup',
getIsBroadcast: 'getIsBroadcast',
getIsPSA: 'getIsPSA',
getIsIAS: 'getIsIAS',
getIsSupportAccount: 'getIsSupportAccount',
getIsWAContact: 'getIsWAContact',
getIsMyContact: 'getIsMyContact',
getCanRequestPhoneNumber: 'getCanRequestPhoneNumber',
getShowBusinessCheckmarkAsPrimary: 'getShowBusinessCheckmarkAsPrimary',
getShowBusinessCheckmarkAsSecondary: 'getShowBusinessCheckmarkAsSecondary',
getShowBusinessCheckmarkInChatlist: 'getShowBusinessCheckmarkInChatlist',
getIsDisplayNameApproved: 'getIsDisplayNameApproved',
getShouldForceBusinessUpdate: 'getShouldForceBusinessUpdate',
},
(m) => m.getIsMyContact
);

injectFallbackModule('getIsMyContact', {
getNotifyName: (contact: ContactModel) => contact.notifyName,
getMentionName: (contact: ContactModel) => contact.mentionName,
getPremiumMessageName: (contact: ContactModel) => contact.premiumMessageName,
getUserid: (contact: ContactModel) => contact.userid,
getUserhash: (contact: ContactModel) => contact.userhash,
getSearchVerifiedName: (contact: ContactModel) => contact.searchVerifiedName,
getHeader: (contact: ContactModel) => contact.header,
getIsMe: (contact: ContactModel) => contact.isMe,
getIsUser: (contact: ContactModel) => contact.isUser,
getIsGroup: (contact: ContactModel) => contact.isGroup,
getIsBroadcast: (contact: ContactModel) => contact.isBroadcast,
getIsPSA: (contact: ContactModel) => contact.isPSA,
getIsIAS: (contact: ContactModel) => contact.isIAS,
getIsSupportAccount: (contact: ContactModel) => contact.isSupportAccount,
getIsWAContact: (contact: ContactModel) => contact.isWAContact,
getIsMyContact: (contact: ContactModel) => contact.isMyContact,
getCanRequestPhoneNumber: (contact: ContactModel) =>
contact.canRequestPhoneNumber,
getShowBusinessCheckmarkAsPrimary: (contact: ContactModel) =>
contact.showBusinessCheckmarkAsPrimary,
getShowBusinessCheckmarkAsSecondary: (contact: ContactModel) =>
contact.showBusinessCheckmarkAsSecondary,
getShowBusinessCheckmarkInChatlist: (contact: ContactModel) =>
contact.showBusinessCheckmarkInChatlist,
getIsDisplayNameApproved: (contact: ContactModel) =>
contact.isDisplayNameApproved,
getShouldForceBusinessUpdate: (contact: ContactModel) =>
contact.shouldForceBusinessUpdate,
});

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getDisplayName(contact: ContactModel): string;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getPnForLid(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getDisplayNameOrPnForLid(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getFormattedPhone(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getSearchName(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getFormattedShortNameWithNonBreakingSpaces(
contact: ContactModel
): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getFormattedShortName(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getFormattedName(contact: ContactModel): any;

/**
* @whatsapp 714574 >= 2.2327.4
*/
export declare function getFormattedUser(contact: ContactModel): any;

exportModule(
exports,
{
getDisplayName: 'getDisplayName',
getPnForLid: 'getPnForLid',
getDisplayNameOrPnForLid: 'getDisplayNameOrPnForLid',
getFormattedPhone: 'getFormattedPhone',
getSearchName: 'getSearchName',
getFormattedShortNameWithNonBreakingSpaces:
'getFormattedShortNameWithNonBreakingSpaces',
getFormattedShortName: 'getFormattedShortName',
getFormattedName: 'getFormattedName',
getFormattedUser: 'getFormattedUser',
},
(m) => m.getDisplayName
);
injectFallbackModule('getDisplayName', {
getDisplayName: (contact: ContactModel) => contact.displayName,
getPnForLid: (contact: ContactModel) => contact.pnForLid,
getDisplayNameOrPnForLid: (contact: ContactModel) =>
contact.displayNameOrPnForLid,
getFormattedPhone: (contact: ContactModel) => contact.formattedPhone,
getSearchName: (contact: ContactModel) => contact.searchName,
getFormattedShortNameWithNonBreakingSpaces: (contact: ContactModel) =>
contact.formattedShortNameWithNonBreakingSpaces,
getFormattedShortName: (contact: ContactModel) => contact.formattedShortName,
getFormattedName: (contact: ContactModel) => contact.formattedName,
getFormattedUser: (contact: ContactModel) => contact.formattedUser,
});
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -22,6 +22,7 @@ export * from './canEditMsg';
export * from './canReplyMsg';
export * from './changeOptInStatusForExternalWebBeta';
export * from './collections';
export * from './contactFunctions';
export * from './createFanoutMsgStanza';
export * from './createGroup';
export * from './createMsgProtobuf';
Expand Down

0 comments on commit b960710

Please sign in to comment.