Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed compatibility of ContactModel for WhatsApp >= 2.2327.4 (fix …
- Loading branch information
1 parent
659e72e
commit b960710
Showing
5 changed files
with
484 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import './patch'; | ||
|
||
export * from './functions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.