Skip to content

Commit 53e2cf6

Browse files
authored
fix: update group message and chats checks to use id.isGroup() method (wppconnect-team#3275)
1 parent bd9afd0 commit 53e2cf6

File tree

10 files changed

+17
-14
lines changed

10 files changed

+17
-14
lines changed

src/chat/events/registerNewMessageEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function register() {
5252
if (typeof MsgModel.prototype.isGroupMsg === 'undefined') {
5353
Object.defineProperty(MsgModel.prototype, 'isGroupMsg', {
5454
get: function () {
55-
return this?.chat?.isGroup;
55+
return this?.chat?.id?.isGroup();
5656
},
5757
configurable: true,
5858
});

src/chat/functions/deleteMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function deleteMessage(
7171
let isDeleted = false;
7272
const isSentByMe = msg.senderObj.isMe;
7373
let imAdmin = false;
74-
if (chat.isGroup) imAdmin = await iAmAdmin(chatId);
74+
if (chat.id.isGroup()) imAdmin = await iAmAdmin(chatId);
7575

7676
const canRevoke = isSentByMe || imAdmin;
7777

src/chat/functions/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function find(chatId: string | Wid): Promise<ChatModel> {
3232
// This ensures the chat is properly initialized and can be opened/clicked
3333
const { chat } = await findOrCreateLatestChat(wid, 'newChatFlow');
3434

35-
if (chat.isGroup) {
35+
if (chat.id.isGroup()) {
3636
await GroupMetadataStore.find(chat.id);
3737
}
3838

src/chat/functions/getNotes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function getNotes(
3838
'connected_device_not_is_business',
3939
`Connected device not is business account`
4040
);
41-
} else if (chat.isGroup) {
41+
} else if (chat.id.isGroup()) {
4242
throw new WPPError(
4343
'can_not_get_notes_for_groups',
4444
`You can not get notes for groups. ChatId: ${chatId}`

src/chat/functions/list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ export async function list(
102102
}
103103

104104
if (options.onlyGroups) {
105-
models = models.filter((c) => c.isGroup);
105+
models = models.filter((c) => c.id.isGroup());
106106
}
107107

108108
if (options.onlyCommunities) {
109109
models = models.filter(
110-
(c) => c.isGroup && c.groupMetadata?.groupType === 'COMMUNITY'
110+
(c) => c.id.isGroup() && c.groupMetadata?.groupType === 'COMMUNITY'
111111
);
112112
}
113113

@@ -145,7 +145,7 @@ export async function list(
145145
// Attaching Group Metadata on Found Chats.
146146
if (!options?.ignoreGroupMetadata) {
147147
for (const chat of models) {
148-
if (chat.isGroup) {
148+
if (chat.id.isGroup()) {
149149
await GroupMetadataStore.find(chat.id);
150150
}
151151
}

src/chat/functions/pinMsg.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,23 @@ export async function pinMsg(
9999
const chat = assertGetChat(msg.id.remote);
100100
const pinned = PinInChatStore.getByParentMsgKey(msg.id);
101101

102-
if (chat.isNewsletter) {
102+
if (chat.id.isNewsletter()) {
103103
throw new WPPError(
104104
`${pin ? 'pin' : 'unpin'}_error`,
105105
`The msg ${msgId.toString()} was not pinned. Not can pin in Newsletter`,
106106
{ msgId, pin }
107107
);
108-
} else if (chat.isGroup && !chat.groupMetadata?.participants?.iAmMember()) {
108+
} else if (
109+
chat.id.isGroup() &&
110+
!chat.groupMetadata?.participants?.iAmMember()
111+
) {
109112
throw new WPPError(
110113
`${pin ? 'pin' : 'unpin'}_error`,
111114
`You not a member of group, to pin msg ${msgId.toString()}`,
112115
{ msgId, pin }
113116
);
114117
} else if (
115-
chat.isGroup &&
118+
chat.id.isGroup() &&
116119
(chat.groupMetadata?.restrict || chat.groupMetadata?.announce) &&
117120
!chat.groupMetadata?.participants.iAmAdmin()
118121
) {

src/chat/functions/prepareRawMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export async function prepareRawMessage<T extends RawMessage>(
148148
*/
149149
if (
150150
options.detectMentioned &&
151-
chat.isGroup &&
151+
chat.id.isGroup() &&
152152
(!options.mentionedList || !options.mentionedList.length)
153153
) {
154154
const text = message.type === 'chat' ? message.body : message.caption;

src/chat/functions/sendRawMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function sendRawMessage(
6262
* When the group is groupType 'COMMUNITY', its a instance of a group created, you can
6363
* not send message for this grouptype. You only can send message for linked announcement groups
6464
*/
65-
if (chat.isGroup && chat.isParentGroup) {
65+
if (chat.id.isGroup() && chat.isParentGroup) {
6666
const groupData = GroupMetadataStore.get(chat.id?.toString());
6767
if (groupData?.groupType == 'COMMUNITY') {
6868
const announceGroup = getAnnouncementGroup(groupData.id);

src/chat/functions/setNotes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function setNotes(
4747
'missing_content_for_notes',
4848
`Missing content for notes`
4949
);
50-
} else if (chat.isGroup) {
50+
} else if (chat.id.isGroup()) {
5151
throw new WPPError(
5252
'can_not_set_notes_for_groups',
5353
`You can not set notes for groups. ChatId: ${chatId}`

src/group/functions/ensureGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { GroupMetadataStore, Wid } from '../../whatsapp';
2121
export async function ensureGroup(groupId: string | Wid, checkIsAdmin = false) {
2222
const groupChat = assertGetChat(groupId);
2323

24-
if (!groupChat.isGroup) {
24+
if (!groupChat.id.isGroup()) {
2525
throw new WPPError(
2626
'not_a_group',
2727
`Chat ${groupChat.id._serialized} is not a group`

0 commit comments

Comments
 (0)