Skip to content

Commit

Permalink
fix: Fixed some attributes in ChatModel (close #2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Nov 14, 2024
1 parent 5ec6a8e commit d87ea3d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/chat/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as webpack from '../webpack';
import { ChatModel, functions } from '../whatsapp';
import { wrapModuleFunction } from '../whatsapp/exportModule';
import {
isUnreadTypeMsg,
Expand All @@ -23,6 +24,7 @@ import {
} from '../whatsapp/functions';

webpack.onFullReady(applyPatch, 1000);
webpack.onFullReady(applyPatchModel);

function applyPatch() {
wrapModuleFunction(mediaTypeFromProtobuf, (func, ...args) => {
Expand Down Expand Up @@ -80,3 +82,28 @@ function applyPatch() {
return func(...args);
});
}

function applyPatchModel() {
const funcs: {
[key: string]: (...args: any[]) => any;
} = {
shouldAppearInList: functions.getShouldAppearInList,
isUser: functions.getIsUser,
isPSA: functions.getIsPSA,
previewMessage: functions.getPreviewMessage,
showChangeNumberNotification: functions.getShowChangeNumberNotification,
shouldShowUnreadDivider: functions.getShouldShowUnreadDivider,
};

for (const attr in funcs) {
const func = funcs[attr];
if (typeof (ChatModel.prototype as any)[attr] === 'undefined') {
Object.defineProperty(ChatModel.prototype, attr, {
get: function () {
return func(this);
},
configurable: true,
});
}
}
}
43 changes: 43 additions & 0 deletions src/whatsapp/functions/getShouldAppearInList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*!
* Copyright 2024 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 { exportModule } from '../exportModule';
import { ChatModel } from '../models';

/**
* @whatsapp WAWebGetters
*/
export declare function getShouldAppearInList(chat: ChatModel): boolean;
export declare function getPreviewMessage(chat: ChatModel): any[];
export declare function getShowChangeNumberNotification(
chat: ChatModel
): boolean;
export declare function getShouldShowUnreadDivider(chat: ChatModel): boolean;

exportModule(
exports,
{
getShouldAppearInList: 'getShouldAppearInList',
getPreviewMessage: 'getPreviewMessage',
getShowChangeNumberNotification: 'getShowChangeNumberNotification',
getShouldShowUnreadDivider: 'getShouldShowUnreadDivider',
},
(m) =>
m.getShouldAppearInList &&
m.getPreviewMessage &&
m.getShowChangeNumberNotification &&
m.getShouldShowUnreadDivider
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export * from './getPushname';
export * from './getQuotedMsgObj';
export * from './getReactions';
export * from './getSearchContext';
export * from './getShouldAppearInList';
export * from './getStatusList';
export * from './getTableVotes';
export * from './getVotes';
Expand Down
24 changes: 24 additions & 0 deletions src/whatsapp/models/ChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,41 @@ interface Session extends SessionChatBase {
interface Derived {
kind?: any;
isUser: boolean;
/**
* Deprecated in favor of getIsUser
* @deprecated
*/
isPSA: boolean;
/**
* Deprecated in favor of getIsPSA
* @deprecated
*/
isGroup: boolean;
isParentGroup: boolean;
isBroadcast: boolean;
isNewsletter: boolean;
canUnread: boolean;
hasUnread: boolean;
optimisticUnreadCount?: any;
/**
* Deprecated in favor of getShouldShowUnreadDivider
* @deprecated
*/
shouldShowUnreadDivider?: any;
/**
* Deprecated in favor of getShouldAppearInList
* @deprecated
*/
shouldAppearInList?: any;
/**
* Deprecated in favor of getPreviewMessage
* @deprecated
*/
previewMessage?: any;
/**
* Deprecated in favor of getShowChangeNumberNotification
* @deprecated
*/
showChangeNumberNotification?: any;
shouldShowUnreadInTitle?: any;
}
Expand Down

0 comments on commit d87ea3d

Please sign in to comment.