Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore and do not decrypt received messages when offline, saving resources and increasing performance #870

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/Defaults/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const DEFAULT_CONNECTION_CONFIG: SocketConfig = {
retryRequestDelayMs: 250,
maxMsgRetryCount: 5,
fireInitQueries: true,
ignoreOfflineMessages: false,
auth: undefined as unknown as AuthenticationState,
markOnlineOnConnect: true,
syncFullHistory: false,
Expand Down
7 changes: 7 additions & 0 deletions src/Socket/messages-recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
retryRequestDelayMs,
maxMsgRetryCount,
getMessage,
ignoreOfflineMessages,
shouldIgnoreJid
} = config
const sock = makeMessagesSocket(config)
Expand Down Expand Up @@ -316,7 +317,7 @@

break
case 'membership_approval_mode':
const approvalMode: any = getBinaryNodeChild(child, 'group_join')

Check warning on line 320 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
if(approvalMode) {
msg.messageStubType = WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE
msg.messageStubParameters = [ approvalMode.attrs.state ]
Expand Down Expand Up @@ -693,7 +694,13 @@
}

const handleMessage = async(node: BinaryNode) => {
if(ignoreOfflineMessages && node.attrs.offline) {
logger.debug({ key: node.attrs.key }, 'ignored offline message')
await sendMessageAck(node)
return
}

if(shouldIgnoreJid(node.attrs.from!) && node.attrs.from! !== '@s.whatsapp.net') {

Check warning on line 703 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

This assertion is unnecessary since it does not change the type of the expression

Check warning on line 703 in src/Socket/messages-recv.ts

View workflow job for this annotation

GitHub Actions / check-lint

This assertion is unnecessary since it does not change the type of the expression
logger.debug({ key: node.attrs.key }, 'ignored message')
await sendMessageAck(node)
return
Expand Down
2 changes: 2 additions & 0 deletions src/Types/Socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
linkPreviewImageThumbnailWidth: number
/** Should Baileys ask the phone for full history, will be received async */
syncFullHistory: boolean
/** Ignore and do not decrypt received messages when offline, default false */
ignoreOfflineMessages: boolean
/** Should baileys fire init queries automatically, default true */
fireInitQueries: boolean
/**
Expand Down Expand Up @@ -119,5 +121,5 @@
makeSignalRepository: (auth: SignalAuthState) => SignalRepository

/** Socket passthrough */
socket?: any

Check warning on line 124 in src/Types/Socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
}
Loading