Changeset 31e2b09


Ignore:
Timestamp:
2015-06-23T00:15:19Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
9076a1c
Parents:
15c3a6b
Message:

Get participants list through local yowsup change, and add ping timeouts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/wa.py

    r15c3a6b r31e2b09  
    199199                if isinstance(entity, ResultSyncIqProtocolEntity):
    200200                        return self.onSyncResult(entity)
    201                 elif isinstance(entity, ListParticipantsResultIqProtocolEntity):
    202                         return self.b.chat_join_participants(entity)
    203201                elif isinstance(entity, ListGroupsResultIqProtocolEntity):
    204202                        return self.onListGroupsResult(entity)
    205                 elif "ping" in self.todo: # Pong has no type, sigh.
    206                         if "contacts" in self.todo:
    207                                 # Shitty Whatsapp rejected the sync request, and
    208                                 # annoying Yowsup doesn't inform on error responses.
    209                                 # So instead, if we received no response to it but
    210                                 # did get our ping back, declare failure.
    211                                 self.onSyncResultFail()
    212                         if "groups" in self.todo:
    213                                 # Well fuck this. Just reject ALL the things!
    214                                 # Maybe I don't need this one then.
    215                                 self.check_connected("groups")
    216                         self.check_connected("ping")
     203                elif type(entity) == IqProtocolEntity:  # Pong has no type, sigh.
     204                        self.b.last_pong = time.time()
     205                        if self.todo:
     206                                return self.onLoginPong()
    217207       
    218208        def onSyncResult(self, entity):
     
    248238                                jid += "@g.us"
    249239                        group = self.b.groups[jid]
     240                        try:
     241                                group["participants"] = g.getParticipants().keys()
     242                        except AttributeError:
     243                                # Depends on a change I made to yowsup that may
     244                                # or may not get merged..
     245                                group["participants"] = []
    250246                       
    251247                        # Save it. We're going to mix ListGroups elements and
     
    256252
    257253                self.check_connected("groups")
     254
     255        def onLoginPong(self):
     256                if "contacts" in self.todo:
     257                        # Shitty Whatsapp rejected the sync request, and
     258                        # annoying Yowsup doesn't inform on error responses.
     259                        # So instead, if we received no response to it but
     260                        # did get our ping back, declare failure.
     261                        self.onSyncResultFail()
     262                if "groups" in self.todo:
     263                        # Well fuck this. Just reject ALL the things!
     264                        # Maybe I don't need this one then.
     265                        self.check_connected("groups")
     266                self.check_connected("ping")
    258267
    259268        def getStatuses(self, contacts):
     
    328337        # TODO: HANDLE_DOMAIN in right place (add ... ... nick bug)
    329338        PING_INTERVAL = 299 # seconds
     339        PING_TIMEOUT = 360 # seconds
    330340
    331341        def login(self, account):
     
    340350
    341351                self.next_ping = None
     352                self.last_pong = time.time()
    342353
    343354        def keepalive(self):
     355                if (time.time() - self.last_pong) > self.PING_TIMEOUT:
     356                        self.error("Ping timeout")
     357                        self.logout(True)
     358                        return
    344359                if self.next_ping and (time.time() < self.next_ping):
    345360                        return
     
    394409               
    395410                # So for now do without a participant list..
    396                 #self.chat_join_participants(None)
     411                self.chat_join_participants(group)
    397412                self.chat_send_backlog(group)
    398413
    399         def chat_join_participants(self, entity):
    400                 """
    401                 group = self.groups[entity.getFrom()]
    402                 id = group["id"]
    403                 for p in entity.getParticipants():
     414        def chat_join_participants(self, group):
     415                for p in group.get("participants", []):
    404416                        if p != self.account["user"]:
    405                                 self.bee.chat_add_buddy(id, p)
    406                 """
     417                                self.bee.chat_add_buddy(group["id"], p)
    407418
    408419        def chat_send_backlog(self, group):
Note: See TracChangeset for help on using the changeset viewer.