Skip to content
Open
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
27 changes: 21 additions & 6 deletions pkg/whatsmeow/service/whatsmeow.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,28 @@ func (mycli *MyClient) myEventHandler(rawEvt interface{}) {

postMap["data"] = dataMap

go schedulePresenceUpdates(mycli)

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)
// Respect the alwaysOnline instance flag. Previously the device was marked
// online unconditionally on every connect (and the periodic presence job was
// started), which kept the linked device permanently "available". WhatsApp then
// delivers messages to that active session and suppresses push notifications on
// the user's phone. When alwaysOnline is false we now send Unavailable instead.
var err error
if mycli.Instance.AlwaysOnline {
go schedulePresenceUpdates(mycli)

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)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Marked self as available", mycli.userID)
}
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Marked self as available", mycli.userID)
err = mycli.WAClient.SendPresence(context.Background(), types.PresenceUnavailable)
if err != nil {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Failed to send unavailable presence %v", mycli.userID, err)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogInfo("[%s] Marked self as unavailable (alwaysOnline=false)", mycli.userID)
}
}
Comment on lines +917 to 930

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Logging levels for successful presence updates are inconsistent and may be noisy.

In the AlwaysOnline branch, a successful SendPresence logs at Warn, while the alwaysOnline=false success logs at Info. Using Warn for an expected success will add noise and obscure real problems. Please use a non-warning level for the success case here, and keep both branches consistent unless there’s a strong reason not to.

Suggested change
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)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Marked self as available", mycli.userID)
}
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Marked self as available", mycli.userID)
err = mycli.WAClient.SendPresence(context.Background(), types.PresenceUnavailable)
if err != nil {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Failed to send unavailable presence %v", mycli.userID, err)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogInfo("[%s] Marked self as unavailable (alwaysOnline=false)", mycli.userID)
}
}
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)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogInfo("[%s] Marked self as available (alwaysOnline=true)", mycli.userID)
}
} else {
err = mycli.WAClient.SendPresence(context.Background(), types.PresenceUnavailable)
if err != nil {
mycli.loggerWrapper.GetLogger(mycli.userID).LogWarn("[%s] Failed to send unavailable presence %v", mycli.userID, err)
} else {
mycli.loggerWrapper.GetLogger(mycli.userID).LogInfo("[%s] Marked self as unavailable (alwaysOnline=false)", mycli.userID)
}
}


mycli.Instance.Connected = true
Expand Down