Changeset d832164 for python/wa.py
- Timestamp:
- 2015-06-17T22:46:40Z (9 years ago)
- Children:
- b75671d
- Parents:
- c82a88d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/wa.py
rc82a88d rd832164 101 101 102 102 # We're done once this set is empty. 103 self.todo = set(["contacts", "groups" ])103 self.todo = set(["contacts", "groups", "ping"]) 104 104 105 105 # Supposedly WA can also do national-style phone numbers without … … 109 109 self.toLower(GetSyncIqProtocolEntity(numbers)) 110 110 self.toLower(ListGroupsIqProtocolEntity()) 111 self.b.keepalive() 111 112 112 113 try: … … 205 206 elif isinstance(entity, ListGroupsResultIqProtocolEntity): 206 207 return self.onListGroupsResult(entity) 208 elif "ping" in self.todo: # Pong has no type, sigh. 209 if "contacts" in self.todo: 210 # Shitty Whatsapp rejected the sync request, and 211 # annoying Yowsup doesn't inform on error responses. 212 # So instead, if we received no response to it but 213 # did get our ping back, declare failure. 214 self.onSyncResultFail() 215 self.check_connected("ping") 207 216 208 217 def onSyncResult(self, entity): … … 219 228 ", ".join(entity.invalidNumbers)) 220 229 221 # Disabled since yowsup won't give us the result... 222 if entity.inNumbers and False: 223 self.toLower(GetStatusIqProtocolEntity(entity.inNumbers.values())) 224 self.todo.add("statuses") 225 230 #self.getStatuses(entity.inNumbers.values()) 231 self.check_connected("contacts") 232 233 def onSyncResultFail(self): 234 # Whatsapp rate-limits sync stanzas, so in case of failure 235 # just assume all contacts are valid. 236 for jid in self.cb.get_local_contacts(): 237 self.toLower(SubscribePresenceProtocolEntity(jid)) 238 self.cb.add_buddy(jid, "") 239 #self.getStatuses? 226 240 self.check_connected("contacts") 227 241 … … 241 255 242 256 self.check_connected("groups") 257 258 def getStatuses(self, contacts): 259 return # Disabled since yowsup won't give us the result... 260 self.toLower(GetStatusIqProtocolEntity(contacts)) 261 self.todo.add("statuses") 243 262 244 263 @ProtocolEntityCallback("notification") … … 307 326 ACCOUNT_FLAGS = 14 # HANDLE_DOMAINS + STATUS_MESSAGE + LOCAL_CONTACTS 308 327 # TODO: HANDLE_DOMAIN in right place (add ... ... nick bug) 328 PING_INTERVAL = 299 # seconds 309 329 310 330 def login(self, account): … … 318 338 self.groups_by_id = {} 319 339 340 self.next_ping = None 341 320 342 def keepalive(self): 321 # Too noisy while debugging 322 # WTF yowsup is SPAWNING A THREAD just for this. Figure out 323 # how to kill that nonsense. 324 pass 325 #self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net")) 343 if self.next_ping and (time.time() < self.next_ping): 344 return 345 self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net")) 346 self.next_ping = time.time() + self.PING_INTERVAL 326 347 327 348 def logout(self):
Note: See TracChangeset
for help on using the changeset viewer.