Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletions src/core/engines/gows/session.gows.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,38 +539,42 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
msg?.Message?.protocolMessage?.key !== undefined
);
}),
mergeMap(async (message): Promise<WAMessageRevokedBody> => {
const afterMessage = await this.toWAMessage(message);
// Extract the revoked message ID from protocolMessage.key
const revokedMessageId = message.Message.protocolMessage.key?.ID;
return {
after: afterMessage,
before: null,
revokedMessageId: revokedMessageId,
_data: message,
};
}),
mergeMap(
async (message): Promise<WAMessageRevokedBody> => {
const afterMessage = await this.toWAMessage(message);
// Extract the revoked message ID from protocolMessage.key
const revokedMessageId = message.Message.protocolMessage.key?.ID;
return {
after: afterMessage,
before: null,
revokedMessageId: revokedMessageId,
_data: message,
};
},
),
);
this.events2.get(WAHAEvents.MESSAGE_REVOKED).switch(messagesRevoked$);

// Handle edited messages
const messagesEdited$ = messages$.pipe(
filter((message) => IsEditedMessage(message.Message)),
mergeMap(async (message): Promise<WAMessageEditedBody> => {
const waMessage = await this.toWAMessage(message);
const content = normalizeMessageContent(message.Message);
// Extract the body from editedMessage using extractBody function
const body = extractBody(content.protocolMessage.editedMessage) || '';
// Extract the original message ID from protocolMessage.key
// @ts-ignore
const editedMessageId = content.protocolMessage.key?.ID;
return {
...waMessage,
body: body,
editedMessageId: editedMessageId,
_data: message,
};
}),
mergeMap(
async (message): Promise<WAMessageEditedBody> => {
const waMessage = await this.toWAMessage(message);
const content = normalizeMessageContent(message.Message);
// Extract the body from editedMessage using extractBody function
const body = extractBody(content.protocolMessage.editedMessage) || '';
// Extract the original message ID from protocolMessage.key
// @ts-ignore
const editedMessageId = content.protocolMessage.key?.ID;
return {
...waMessage,
body: body,
editedMessageId: editedMessageId,
_data: message,
};
},
),
);
this.events2.get(WAHAEvents.MESSAGE_EDITED).switch(messagesEdited$);

Expand Down Expand Up @@ -1874,6 +1878,14 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
id: id,
name: name || null,
picture: picture,
isGroup: chat.id?.endsWith?.('@g.us') || false,
isReadOnly: chat.readOnly || false,
timestamp: chat.conversationTimestamp || chat.timestamp || null,
archived: chat.archived || false,
pinned: chat.pinned || false,
isMuted: chat.mute !== undefined ? chat.mute !== 0 : false,
muteExpiration: chat.mute || 0,
unreadCount: chat.unreadCount || 0,
lastMessage: message,
_chat: chat,
};
Expand Down
9 changes: 9 additions & 0 deletions src/core/engines/noweb/session.noweb.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,19 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
{},
);
const message = messages.length > 0 ? messages[0] : null;
const chatAny = chat as any;
return {
id: id,
name: name || null,
picture: picture,
isGroup: chat.id?.endsWith?.('@g.us') || false,
isReadOnly: chatAny.readOnly || false,
timestamp: chatAny.conversationTimestamp || chatAny.t || null,
archived: chat.archived,
pinned: chatAny.pinned || chatAny.pin || false,
isMuted: chatAny.mute !== undefined ? chatAny.mute !== 0 : false,
muteExpiration: chatAny.mute || 0,
unreadCount: chat.unreadCount,
lastMessage: message,
_chat: chat,
};
Expand Down
63 changes: 38 additions & 25 deletions src/core/engines/webjs/session.webjs.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
const message = this.recreateMessage(messageId);
const options = {
// It's fine to sent just ids instead of Contact object
mentions: request.mentions as unknown as string[],
mentions: (request.mentions as unknown) as string[],
linkPreview: request.linkPreview,
};
return message.edit(request.text, options);
Expand Down Expand Up @@ -940,6 +940,14 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
id: chat.id._serialized,
name: chat.name || null,
picture: picture,
isGroup: chat.isGroup || false,
isReadOnly: chat.isReadOnly || false,
timestamp: chat.timestamp || null,
archived: chat.archived || false,
pinned: chat.pinned || false,
isMuted: chat.isMuted || false,
muteExpiration: chat.muteExpiration || 0,
unreadCount: chat.unreadCount || 0,
lastMessage: lastMessage,
_chat: chat,
};
Expand Down Expand Up @@ -1692,19 +1700,23 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
filter((evt: any) =>
this.jids.include(evt?.after?.id?.remote || evt?.before?.id?.remote),
),
map((event): WAMessageRevokedBody => {
const afterMessage = event.after ? this.toWAMessage(event.after) : null;
const beforeMessage = event.before
? this.toWAMessage(event.before)
: null;
// Extract the revoked message ID from the protocolMessageKey.id field
const revokedMessageId = afterMessage?._data?.protocolMessageKey?.id;
return {
after: afterMessage,
before: beforeMessage,
revokedMessageId: revokedMessageId,
};
}),
map(
(event): WAMessageRevokedBody => {
const afterMessage = event.after
? this.toWAMessage(event.after)
: null;
const beforeMessage = event.before
? this.toWAMessage(event.before)
: null;
// Extract the revoked message ID from the protocolMessageKey.id field
const revokedMessageId = afterMessage?._data?.protocolMessageKey?.id;
return {
after: afterMessage,
before: beforeMessage,
revokedMessageId: revokedMessageId,
};
},
),
);
this.events2.get(WAHAEvents.MESSAGE_REVOKED).switch(messagesRevoked$);

Expand All @@ -1725,15 +1737,17 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
);
const messagesEdit$ = messageEdit$.pipe(
filter((event: any) => this.jids.include(event?.message?.id?.remote)),
map((event): WAMessageEditedBody => {
const message = this.toWAMessage(event.message);
return {
...message,
body: event.newBody,
editedMessageId: message._data?.id?.id,
_data: event,
};
}),
map(
(event): WAMessageEditedBody => {
const message = this.toWAMessage(event.message);
return {
...message,
body: event.newBody,
editedMessageId: message._data?.id?.id,
_data: event,
};
},
),
);
this.events2.get(WAHAEvents.MESSAGE_EDITED).switch(messagesEdit$);

Expand Down Expand Up @@ -2145,8 +2159,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
}

export class WEBJSEngineMediaProcessor
implements IMediaEngineProcessor<Message>
{
implements IMediaEngineProcessor<Message> {
hasMedia(message: Message): boolean {
if (!message.hasMedia) {
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/structures/chats.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ export class ChatSummary {
id: string;
name: string | null;
picture: string | null;
isGroup?: boolean;
isReadOnly?: boolean;
timestamp?: number;
archived?: boolean;
pinned?: boolean;
isMuted?: boolean;
muteExpiration?: number;
unreadCount?: number;
lastMessage: any;
_chat: any;
}
Expand Down