Changeset a852b2b
- Timestamp:
- 2015-05-25T05:30:26Z (10 years ago)
- Children:
- f16c64d
- Parents:
- 8c3637b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/wa.py
r8c3637b ra852b2b 78 78 self.cb = self.b.bee 79 79 self.b.yow = self 80 self.cb.connected() 80 81 self.cb.log("Authenticated, syncing contact list") 82 83 # We're done once this set is empty. 84 self.todo = set(["contacts", "groups"]) 85 86 # Supposedly WA can also do national-style phone numbers without 87 # a + prefix BTW (relative to I guess the user's country?). I 88 # don't want to support this at least for now. 89 numbers = [("+" + x.split("@")[0]) for x in self.cb.get_local_contacts()] 90 self.toLower(GetSyncIqProtocolEntity(numbers)) 81 91 self.toLower(ListGroupsIqProtocolEntity()) 92 82 93 try: 83 94 self.toLower(PresenceProtocolEntity(name=self.b.setting("name"))) 84 95 except KeyError: 85 96 pass 86 # Should send the contact list now, but BitlBee hasn't given 87 # it yet. See set_away() and send_initial_contacts() below. 97 98 def check_connected(self, done): 99 if self.todo is None: 100 return 101 self.todo.remove(done) 102 if not self.todo: 103 self.todo = None 104 self.cb.connected() 88 105 89 106 @ProtocolEntityCallback("failure") … … 101 118 @ProtocolEntityCallback("presence") 102 119 def onPresence(self, pres): 120 if pres.getFrom() == self.b.account["user"]: 121 # WA returns our own presence. Meh. 122 return 123 103 124 status = 8 # MOBILE 104 125 if pres.getType() != "unavailable": 105 126 status |= 1 # ONLINE 106 127 self.cb.buddy_status(pres.getFrom(), status, None, None) 128 107 129 try: 108 130 # Last online time becomes idle time which I guess is … … 137 159 def onIq(self, entity): 138 160 if isinstance(entity, ResultSyncIqProtocolEntity): 139 print "XXX SYNC RESULT RECEIVED!"140 161 return self.onSyncResult(entity) 141 162 elif isinstance(entity, ListParticipantsResultIqProtocolEntity): … … 147 168 # TODO HERE AND ELSEWHERE: Thread idiocy happens when going 148 169 # from here to the IMPlugin. Check how bjsonrpc lets me solve that. 149 # ALSO TODO: See why this one doesn't seem to be called for adds later. 150 ok = set(jid.lower() for jid in entity.inNumbers.values()) 151 for handle in self.b.contacts: 152 if handle.lower() in ok: 153 self.toLower(SubscribePresenceProtocolEntity(handle)) 154 self.cb.add_buddy(handle, "") 170 for num, jid in entity.inNumbers.iteritems(): 171 self.toLower(SubscribePresenceProtocolEntity(jid)) 172 self.cb.add_buddy(jid, "") 155 173 if entity.outNumbers: 156 174 self.cb.error("Not on WhatsApp: %s" % … … 159 177 self.cb.error("Invalid numbers: %s" % 160 178 ", ".join(entity.invalidNumbers.keys())) 179 180 self.check_connected("contacts") 161 181 162 182 def onListGroupsResult(self, groups): … … 169 189 group["info"] = g 170 190 191 self.check_connected("groups") 192 171 193 @ProtocolEntityCallback("notification") 172 194 def onNotification(self, ent): … … 213 235 SETTINGS = { 214 236 "cc": { 237 # Country code. Seems to be required for registration only. 215 238 "type": "int", 216 239 }, … … 233 256 self.bee.log("Started yowsup thread") 234 257 235 self.logging_in = True236 self.contacts = set()237 258 self.groups = {} 238 259 self.groups_by_id = {} … … 252 273 253 274 def add_buddy(self, handle, _group): 254 if self.logging_in: 255 # Need to batch up the initial adds. This is a "little" ugly. 256 self.contacts.add(handle) 257 else: 258 self.yow.Ship(GetSyncIqProtocolEntity( 259 ["+" + handle.split("@")[0]], mode=GetSyncIqProtocolEntity.MODE_DELTA)) 260 self.yow.Ship(SubscribePresenceProtocolEntity(handle)) 275 self.yow.Ship(GetSyncIqProtocolEntity( 276 ["+" + handle.split("@")[0]], mode=GetSyncIqProtocolEntity.MODE_DELTA)) 261 277 262 278 def remove_buddy(self, handle, _group): … … 264 280 265 281 def set_away(self, state, status): 266 # When our first status is set, we've finalised login.267 # Which means sync the full contact list now.268 if self.logging_in:269 self.logging_in = False270 self.send_initial_contacts()271 272 282 print "Trying to set status to %r, %r" % (state, status) 273 283 if state: … … 278 288 if status: 279 289 self.yow.Ship(SetStatusIqProtocolEntity(status)) 280 281 def send_initial_contacts(self):282 if not self.contacts:283 return284 numbers = [("+" + x.split("@")[0]) for x in self.contacts]285 self.yow.Ship(GetSyncIqProtocolEntity(numbers))286 290 287 291 def set_set_name(self, _key, value):
Note: See TracChangeset
for help on using the changeset viewer.