- Timestamp:
- 2015-05-22T01:06:19Z (9 years ago)
- Children:
- 2446e4c
- Parents:
- 433c90b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/wa.py
r433c90b rcb1b973 79 79 self.b.yow = self 80 80 self.cb.connected() 81 self.toLower(ListGroupsIqProtocolEntity()) 81 82 try: 82 83 self.toLower(PresenceProtocolEntity(name=self.b.setting("name"))) … … 104 105 status |= 1 # ONLINE 105 106 self.cb.buddy_status(pres.getFrom(), status, None, None) 107 try: 108 # Last online time becomes idle time which I guess is 109 # sane enough? 110 self.cb.buddy_times(pres.getFrom(), 0, int(pres.getLast())) 111 except ValueError: 112 # Could be "error" or, more likely, "deny" 113 pass 106 114 107 115 @ProtocolEntityCallback("message") … … 133 141 elif isinstance(entity, ListParticipantsResultIqProtocolEntity): 134 142 return self.b.chat_join_participants(entity) 143 elif isinstance(entity, ListGroupsResultIqProtocolEntity): 144 return self.onListGroupsResult(entity) 135 145 136 146 def onSyncResult(self, entity): 137 147 # TODO HERE AND ELSEWHERE: Thread idiocy happens when going 138 148 # 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. 139 150 ok = set(jid.lower() for jid in entity.inNumbers.values()) 140 151 for handle in self.b.contacts: … … 149 160 ", ".join(entity.invalidNumbers.keys())) 150 161 162 def onListGroupsResult(self, groups): 163 """Save group info for later if the user decides to join.""" 164 for g in groups.getGroups(): 165 jid = g.getId() 166 if "@" not in jid: 167 jid += "@g.us" 168 group = self.b.groups.setdefault(jid, {}) 169 group["info"] = g 170 151 171 @ProtocolEntityCallback("notification") 152 172 def onNotification(self, ent): 153 173 if isinstance(ent, StatusNotificationProtocolEntity): 154 174 return self.onStatusNotification(ent) 155 175 156 176 def onStatusNotification(self, status): 157 177 print "New status for %s: %s" % (status.getFrom(), status.status) 178 self.bee.buddy_status_msg(status.getFrom(), status.status) 179 180 @ProtocolEntityCallback("media") 181 def onMedia(self, med): 182 """Your PC better be MPC3 compliant!""" 183 print "YAY MEDIA! %r" % med 184 print med 158 185 159 186 #@ProtocolEntityCallback("chatstate") … … 264 291 print "New chat created with id: %d" % id 265 292 self.groups.setdefault(name, {}).update({"id": id, "name": name}) 266 self.groups_by_id[id] = self.groups[name] 293 group = self.groups[name] 294 self.groups_by_id[id] = group 295 296 gi = group.get("info", None) 297 if gi: 298 self.bee.chat_topic(id, gi.getSubjectOwner(), 299 gi.getSubject(), gi.getSubjectTime()) 300 301 # WA doesn't really have a concept of joined or not, just 302 # long-term membership. Let's just get a list of members and 303 # pretend we've "joined" then. 267 304 self.yow.Ship(ParticipantsGroupsIqProtocolEntity(name)) 268 269 for msg in self.groups[name].get("queue", []):270 self.cb.chat_msg(group["id"], msg.getParticipant(), msg.getBody(), 0, msg.getTimestamp())271 305 272 306 def chat_join_participants(self, entity): … … 276 310 if p != self.account["user"]: 277 311 self.bee.chat_add_buddy(id, p) 312 278 313 # Add the user themselves last to avoid a visible join flood. 279 314 self.bee.chat_add_buddy(id, self.account["user"]) 315 for msg in group.setdefault("queue", []): 316 self.cb.chat_msg(group["id"], msg.getParticipant(), msg.getBody(), 0, msg.getTimestamp()) 317 del group["queue"] 280 318 281 319 def chat_msg(self, id, text, flags): 282 320 msg = TextMessageProtocolEntity(text, to=self.groups_by_id[id]["name"]) 283 321 self.yow.Ship(msg) 322 323 def chat_leave(self, id): 324 # WA never really let us leave, so just disconnect id and jid. 325 group = self.groups_by_id[id] 326 del self.groups_by_id[id] 327 del group["id"] 284 328 285 329 def build_stack(self, account):
Note: See TracChangeset
for help on using the changeset viewer.