Don't update presence status if not needed
Status messages are sent with every presence update by some XMPP clients, which would previously result in corresponding changes being made on the WhatsApp side, where no effective change in status has been made since. This commit implements naive caching for presence status in order to avoid most double-sets, but which however will clear across restarts.
This commit is contained in:
parent
f2b4997473
commit
1275ef55d1
|
@ -100,7 +100,7 @@ func (s *Session) Login() error {
|
|||
select {
|
||||
case <-timer.C:
|
||||
if presence == PresenceAvailable {
|
||||
s.GetContacts(false)
|
||||
_, _ = s.GetContacts(false)
|
||||
timer, timerStopped = newTimer(presenceRefreshInterval), false
|
||||
} else {
|
||||
timerStopped = true
|
||||
|
@ -112,7 +112,7 @@ func (s *Session) Login() error {
|
|||
}
|
||||
return
|
||||
} else if timerStopped && p == PresenceAvailable {
|
||||
s.GetContacts(false)
|
||||
_, _ = s.GetContacts(false)
|
||||
timer, timerStopped = newTimer(presenceRefreshInterval), false
|
||||
}
|
||||
presence = p
|
||||
|
|
|
@ -77,6 +77,7 @@ class Session(BaseSession[str, Recipient]):
|
|||
self.whatsapp.SetEventHandler(self._handle_event)
|
||||
self._connected = self.xmpp.loop.create_future()
|
||||
self.user_phone: Optional[str] = None
|
||||
self._presence_status: str = ""
|
||||
self._lock = Lock()
|
||||
|
||||
async def login(self):
|
||||
|
@ -318,9 +319,14 @@ class Session(BaseSession[str, Recipient]):
|
|||
if merged_resource["show"] in ["chat", ""]
|
||||
else whatsapp.PresenceUnavailable
|
||||
)
|
||||
self.whatsapp.SendPresence(
|
||||
presence, merged_resource["status"] if merged_resource["status"] else ""
|
||||
status = (
|
||||
merged_resource["status"]
|
||||
if self._presence_status != merged_resource["status"]
|
||||
else ""
|
||||
)
|
||||
if status:
|
||||
self._presence_status = status
|
||||
self.whatsapp.SendPresence(presence, status)
|
||||
|
||||
async def on_active(self, c: Recipient, thread=None):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue