Repository navigation
fix(whatsmeow): pulse companion activity without staying online - #213
Open
diego-anselmo wants to merge 2 commits into
Open
diego-anselmo wants to merge 2 commits into
diego-anselmo wants to merge 2 commits into
Conversation
WhatsApp drops an inactive linked device after 30 days. develop currently marks every session available and keeps the hourly job that ends on available, which also suppresses phone push. When alwaysOnline is false, record a short available blip and return to unavailable, then repeat inside the inactivity window.
Reviewer's GuideThe PR changes WhatsApp presence handling to honor alwaysOnline: enabled sessions retain continuous availability, while other sessions periodically emit a short available/unavailable pulse to record companion activity without suppressing phone push notifications. Sequence diagram for alwaysOnline presence handlingsequenceDiagram
participant Client as MyClient
participant WA as WhatsAppClient
participant Scheduler as PresenceScheduler
Client->>Client: myEventHandler(Connected)
alt Instance.AlwaysOnline
Client->>Scheduler: schedulePresenceUpdates(MyClient)
Client->>WA: SendPresence(PresenceAvailable)
Scheduler->>WA: SendPresence(PresenceAvailable)
else alwaysOnline disabled
Client->>Scheduler: scheduleCompanionActivityPulse(MyClient)
Client->>WA: SendPresence(PresenceAvailable)
Client->>WA: SendPresence(PresenceUnavailable)
loop approximately every 20 hours
Scheduler->>WA: SendPresence(PresenceAvailable)
Scheduler->>WA: SendPresence(PresenceUnavailable)
end
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pkg/whatsmeow/service/whatsmeow.go" line_range="865-867" />
<code_context>
+ if mycli.WAClient == nil || !mycli.WAClient.IsLoggedIn() {
+ return
+ }
+ if err := mycli.WAClient.SendPresence(context.Background(), types.PresenceUnavailable); err != nil {
+ logger.LogWarn("[%s] Failed to restore unavailable presence: %v", mycli.userID, err)
+ return
+ }
+ logger.LogInfo("[%s] Companion activity pulsed; presence restored to unavailable", mycli.userID)
</code_context>
<issue_to_address>
**Phone push notifications stay suppressed**
When sending available succeeds but the subsequent unavailable send fails, `pulseCompanionActivity` logs the error and returns without retrying or otherwise clearing the available state, so the companion remains available and the phone suppresses push notifications.
Retry the unavailable update or otherwise ensure the available state is cleared after the restore send fails.
</issue_to_address>
### Comment 2
<location path="pkg/whatsmeow/service/whatsmeow.go" line_range="951" />
<code_context>
- err := mycli.WAClient.SendPresence(context.Background(), types.PresenceAvailable)
- if err != nil {
- mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Failed to send available presence %v", mycli.userID, err)
+ if mycli.Instance != nil && mycli.Instance.AlwaysOnline {
+ go schedulePresenceUpdates(mycli)
+ err := mycli.WAClient.SendPresence(context.Background(), types.PresenceAvailable)
</code_context>
<issue_to_address>
**Updated presence mode is ignored**
When the advanced `alwaysOnline` setting changes while the session is connected, `UpdateInstanceAdvancedSettings` replaces `mycli.Instance` without reconciling the running presence workers, so the old mode continues: switching to `true` can leave unavailable pulses running, while switching to `false` can leave the hourly worker running. Users see the wrong presence behavior until reconnect.
Reconcile the presence workers and current presence when `alwaysOnline` changes on a connected client.
Also at `pkg/whatsmeow/service/whatsmeow.go:952`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: pkg/whatsmeow/service/whatsmeow.go:867, pkg/whatsmeow/service/whatsmeow.go:951
Retry the unavailable restore so a failed send does not leave the companion online. Stop the previous worker when the flag changes or the client is disconnected, without reading killChannel.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
WhatsApp disconnects a linked device after 30 days of inactivity. The phone app also drops companions if it stays unused for about 14 days. That countdown is not cleared by reconnecting or by generating a new QR code.
developcurrently marks every connected session available and startsschedulePresenceUpdates, which ends on available. That keeps the companion looking in use, but it also suppresses push notifications on the phone. The released 0.7.2 path does the opposite whenalwaysOnlineis false: it only sends unavailable, so the companion can look idle for the whole uptime.This change respects
alwaysOnline:true: keep the current available presence and the hourly job.false(the model default): send a short available blip, return to unavailable, and repeat about every 20 hours while the session stays logged in.The blip does not replace opening WhatsApp on the phone. It only records companion activity without leaving the device online.
The new goroutine does not read
killChannel. That channel already has a receiver inStartClient; a second receiver would drop the shutdown signal.Related Issue
No existing issue. Observed on linked devices that stay connected and still show "this device will be logged out in X days".
Type of Change
Testing
Not run against a live WhatsApp session: a presence pulse must not be tested by logging out a production device.
Checklist
Additional Notes
Base is
develop, per the maintainer note on earlier PRs.alwaysOnline=truekeeps today's develop behavior.Summary by Sourcery
Keep linked WhatsApp companions active without leaving them continuously online when
alwaysOnlineis disabled.Bug Fixes:
alwaysOnlineis disabled so linked devices remain active without suppressing phone push notifications.Enhancements:
alwaysOnlinesettings, including cleanly stopping and restarting presence workers during reconnects and configuration changes.