Changeset cb1b973


Ignore:
Timestamp:
2015-05-22T01:06:19Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
2446e4c
Parents:
433c90b
Message:

More group and status info handling, and proper handling of group backlog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/wa.py

    r433c90b rcb1b973  
    7979                self.b.yow = self
    8080                self.cb.connected()
     81                self.toLower(ListGroupsIqProtocolEntity())
    8182                try:
    8283                        self.toLower(PresenceProtocolEntity(name=self.b.setting("name")))
     
    104105                        status |= 1 # ONLINE
    105106                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
    106114       
    107115        @ProtocolEntityCallback("message")
     
    133141                elif isinstance(entity, ListParticipantsResultIqProtocolEntity):
    134142                        return self.b.chat_join_participants(entity)
     143                elif isinstance(entity, ListGroupsResultIqProtocolEntity):
     144                        return self.onListGroupsResult(entity)
    135145       
    136146        def onSyncResult(self, entity):
    137147                # TODO HERE AND ELSEWHERE: Thread idiocy happens when going
    138148                # 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.
    139150                ok = set(jid.lower() for jid in entity.inNumbers.values())
    140151                for handle in self.b.contacts:
     
    149160                                      ", ".join(entity.invalidNumbers.keys()))
    150161
     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
    151171        @ProtocolEntityCallback("notification")
    152172        def onNotification(self, ent):
    153173                if isinstance(ent, StatusNotificationProtocolEntity):
    154174                        return self.onStatusNotification(ent)
    155        
     175
    156176        def onStatusNotification(self, status):
    157177                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
    158185
    159186        #@ProtocolEntityCallback("chatstate")
     
    264291                print "New chat created with id: %d" % id
    265292                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.
    267304                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())
    271305
    272306        def chat_join_participants(self, entity):
     
    276310                        if p != self.account["user"]:
    277311                                self.bee.chat_add_buddy(id, p)
     312
    278313                # Add the user themselves last to avoid a visible join flood.
    279314                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"]
    280318       
    281319        def chat_msg(self, id, text, flags):
    282320                msg = TextMessageProtocolEntity(text, to=self.groups_by_id[id]["name"])
    283321                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"]
    284328
    285329        def build_stack(self, account):
Note: See TracChangeset for help on using the changeset viewer.