Changeset 5f8ad281


Ignore:
Timestamp:
2015-05-20T02:56:41Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
2b4402f
Parents:
63b017e
Message:

WA improvements: "Handle" all stanzas. Presence now seems to get through.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/wa.py

    r63b017e r5f8ad281  
    77
    88from yowsup.layers.auth                        import YowAuthenticationProtocolLayer
     9from yowsup.layers.protocol_acks               import YowAckProtocolLayer
     10from yowsup.layers.protocol_chatstate          import YowChatstateProtocolLayer
     11from yowsup.layers.protocol_contacts           import YowContactsIqProtocolLayer
     12from yowsup.layers.protocol_groups             import YowGroupsProtocolLayer
     13from yowsup.layers.protocol_ib                 import YowIbProtocolLayer
     14from yowsup.layers.protocol_iq                 import YowIqProtocolLayer
    915from yowsup.layers.protocol_messages           import YowMessagesProtocolLayer
     16from yowsup.layers.protocol_notifications      import YowNotificationsProtocolLayer
     17from yowsup.layers.protocol_presence           import YowPresenceProtocolLayer
     18from yowsup.layers.protocol_privacy            import YowPrivacyProtocolLayer
     19from yowsup.layers.protocol_profiles           import YowProfilesProtocolLayer
    1020from yowsup.layers.protocol_receipts           import YowReceiptProtocolLayer
    11 from yowsup.layers.protocol_acks               import YowAckProtocolLayer
    1221from yowsup.layers.network                     import YowNetworkLayer
    1322from yowsup.layers.coder                       import YowCoderLayer
     
    1827from yowsup import env
    1928
    20 from yowsup.layers.interface                           import YowInterfaceLayer, ProtocolEntityCallback
    21 from yowsup.layers.protocol_receipts.protocolentities    import *
     29from yowsup.layers.interface                             import YowInterfaceLayer, ProtocolEntityCallback
     30from yowsup.layers.protocol_acks.protocolentities        import *
     31from yowsup.layers.protocol_chatstate.protocolentities   import *
     32from yowsup.layers.protocol_contacts.protocolentities    import *
    2233from yowsup.layers.protocol_groups.protocolentities      import *
    23 from yowsup.layers.protocol_presence.protocolentities    import *
    24 from yowsup.layers.protocol_messages.protocolentities    import *
    25 from yowsup.layers.protocol_acks.protocolentities        import *
    2634from yowsup.layers.protocol_ib.protocolentities          import *
    2735from yowsup.layers.protocol_iq.protocolentities          import *
    28 from yowsup.layers.protocol_contacts.protocolentities    import *
    29 from yowsup.layers.protocol_chatstate.protocolentities   import *
     36from yowsup.layers.protocol_media.mediauploader import MediaUploader
     37from yowsup.layers.protocol_media.protocolentities       import *
     38from yowsup.layers.protocol_messages.protocolentities    import *
     39from yowsup.layers.protocol_notifications.protocolentities import *
     40from yowsup.layers.protocol_presence.protocolentities    import *
    3041from yowsup.layers.protocol_privacy.protocolentities     import *
    31 from yowsup.layers.protocol_media.protocolentities       import *
    32 from yowsup.layers.protocol_media.mediauploader import MediaUploader
    3342from yowsup.layers.protocol_profiles.protocolentities    import *
     43from yowsup.layers.protocol_receipts.protocolentities    import *
    3444from yowsup.layers.axolotl.protocolentities.iq_key_get import GetKeysIqProtocolEntity
    3545from yowsup.layers.axolotl import YowAxolotlLayer
     
    7686                self.cb.error(entity.getReason())
    7787                self.cb.logout(False)
     88
     89        def onEvent(self, event):
     90                print event
     91                if event.getName() == "disconnect":
     92                        self.getStack().execDetached(self.daemon.StopDaemon)
     93       
     94        @ProtocolEntityCallback("presence")
     95        def onPresence(self, pres):
     96                print pres
    7897       
    7998        @ProtocolEntityCallback("message")
     
    86105        @ProtocolEntityCallback("receipt")
    87106        def onReceipt(self, entity):
    88                 ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "delivery", entity.getFrom())
     107                print "ACK THE ACK!"
     108                ack = OutgoingAckProtocolEntity(entity.getId(), entity.getTag(),
     109                                                entity.getType(), entity.getFrom())
    89110                self.toLower(ack)
     111
     112        @ProtocolEntityCallback("chatstate")
     113        def onChatstate(self, entity):
     114                print(entity)
     115
    90116
    91117class YowsupDaemon(threading.Thread):
     
    118144                },
    119145        }
    120         ACCOUNT_FLAGS = 6 # HANDLE_DOMAINS + STATUS_MESSAGE
     146        AWAY_STATES = ["Available"]
     147        ACCOUNT_FLAGS = 14 # HANDLE_DOMAINS + STATUS_MESSAGE + LOCAL_CONTACTS
    121148        # TODO: LOCAL LIST CAUSES CRASH!
    122149        # TODO: HANDLE_DOMAIN in right place (add ... ... nick bug)
    123        
     150        # TODO? Allow set_away (for status msg) even if AWAY_STATES not set?
     151        #   and/or, see why with the current value set_away state is None.
     152
    124153        def login(self, account):
    125154                self.stack = self.build_stack(account)
     
    128157                self.daemon.start()
    129158                self.bee.log("Started yowsup thread")
     159               
     160                self.contacts = set()
    130161
    131162        def keepalive(self):
     
    142173        def add_buddy(self, handle, _group):
    143174                self.yow.Ship(SubscribePresenceProtocolEntity(handle))
     175                # Need to confirm additions. See if this can be done based on server ACKs.
     176                self.bee.add_buddy(handle, "")
    144177
    145178        def remove_buddy(self, handle, _group):
    146179                self.yow.Ship(UnsubscribePresenceProtocolEntity(handle))
    147180
    148         def set_away(_state, message):
     181        def set_away(self, _state, status):
    149182                # I think state is not supported?
    150                 print "Trying to set status to %r" % status
     183                print "Trying to set status to %r, %r" % (_state, status)
    151184                self.yow.Ship(SetStatusIqProtocolEntity(status))
    152185
     
    157190                layers = (
    158191                        BitlBeeLayer,
    159                         (YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer)
     192                       
     193                        (
     194                         YowAckProtocolLayer,
     195                         YowAuthenticationProtocolLayer,
     196                         YowIbProtocolLayer,
     197                         YowIqProtocolLayer,
     198                         YowMessagesProtocolLayer,
     199                         YowNotificationsProtocolLayer,
     200                         YowPresenceProtocolLayer,
     201                         YowReceiptProtocolLayer,
     202                        )
     203
    160204                ) + YOWSUP_CORE_LAYERS
    161205               
Note: See TracChangeset for help on using the changeset viewer.