Changeset b09ce17


Ignore:
Timestamp:
2015-05-21T03:43:06Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
433c90b
Parents:
2b4402f
Message:

Improvements: presence and minimal group support.

Presence depends on https://github.com/tgalal/yowsup/pull/796. :-(

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • protocols/rpc/rpc.c

    r2b4402f rb09ce17  
    714714        { "imcb_rename_buddy", imcb_rename_buddy, rpc_imcb_add_buddy, "ss" },
    715715        { "imcb_buddy_nick_hint", imcb_buddy_nick_hint, rpc_imcb_add_buddy, "ss" },
    716         { "imcb_buddy_status", imcb_buddy_status, rpc_imcb_buddy_status, "snss" },
     716        { "imcb_buddy_status", imcb_buddy_status, rpc_imcb_buddy_status, "siss" },
    717717        { "imcb_buddy_status_msg", imcb_buddy_status_msg, rpc_imcb_add_buddy, "ss" },
    718718        { "imcb_buddy_times", imcb_buddy_times, rpc_imcb_buddy_times, "sii" },
  • python/implugin.py

    r2b4402f rb09ce17  
    107107       
    108108        def setting(self, key):
     109                """Throws KeyError if the setting does not exist!"""
    109110                return self._settings_values[key]
    110111
  • python/wa.py

    r2b4402f rb09ce17  
    6262        def receive(self, entity):
    6363                print "Received: %r" % entity
    64                 print entity
     64                #print entity
    6565                super(BitlBeeLayer, self).receive(entity)
    6666
     
    6868                """Send an entity into Yowsup, but through the correct thread."""
    6969                print "Queueing: %s" % entity.getTag()
    70                 print entity
     70                #print entity
    7171                def doit():
    7272                        self.toLower(entity)
     
    7979                self.b.yow = self
    8080                self.cb.connected()
    81                 self.toLower(AvailablePresenceProtocolEntity())
     81                try:
     82                        self.toLower(PresenceProtocolEntity(name=self.b.setting("name")))
     83                except KeyError:
     84                        pass
     85                # Should send the contact list now, but BitlBee hasn't given
     86                # it yet. See set_away() and send_initial_contacts() below.
    8287       
    8388        @ProtocolEntityCallback("failure")
     
    8994
    9095        def onEvent(self, event):
    91                 print event
     96                print "Received event: %s name %s" % (event, event.getName())
    9297                if event.getName() == "disconnect":
    9398                        self.getStack().execDetached(self.daemon.StopDaemon)
     
    96101        def onPresence(self, pres):
    97102                status = 8 # MOBILE
    98                 online = isinstance(pres, AvailablePresenceProtocolEntity)
    99                 if online:
    100                         status += 1 # ONLINE
    101                 imcb_buddy_status(pres.getFrom(), status, None, None)
     103                if pres.getType() != "unavailable":
     104                        status |= 1 # ONLINE
     105                self.cb.buddy_status(pres.getFrom(), status, None, None)
    102106       
    103107        @ProtocolEntityCallback("message")
    104108        def onMessage(self, msg):
    105                 self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp())
    106 
    107109                receipt = OutgoingReceiptProtocolEntity(msg.getId(), msg.getFrom())
    108110                self.toLower(receipt)
     111
     112                if msg.getParticipant():
     113                        group = self.b.groups.get(msg.getFrom(), None)
     114                        if not group:
     115                                self.cb.log("Warning: Activity in room %s" % msg.getFrom())
     116                                return
     117                        self.cb.chat_msg(group["id"], msg.getParticipant(), msg.getBody(), 0, msg.getTimestamp())
     118                else:
     119                        self.cb.buddy_msg(msg.getFrom(), msg.getBody(), 0, msg.getTimestamp())
    109120
    110121        @ProtocolEntityCallback("receipt")
     
    141152                print "New status for %s: %s" % (status.getFrom(), status.status)
    142153
    143         @ProtocolEntityCallback("chatstate")
    144         def onChatstate(self, entity):
    145                 print(entity)
     154        #@ProtocolEntityCallback("chatstate")
     155        #def onChatstate(self, entity):
     156        #       print(entity)
    146157
    147158
     
    176187                },
    177188        }
    178         AWAY_STATES = ["Available"]
     189        AWAY_STATES = ["Away"]
    179190        ACCOUNT_FLAGS = 14 # HANDLE_DOMAINS + STATUS_MESSAGE + LOCAL_CONTACTS
    180191        # TODO: LOCAL LIST CAUSES CRASH!
     
    192203                self.logging_in = True
    193204                self.contacts = set()
     205                self.groups = {}
     206                self.groups_by_id = {}
    194207
    195208        def keepalive(self):
    196                 self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net"))
     209                # Too noisy while debugging
     210                pass
     211                #self.yow.Ship(PingIqProtocolEntity(to="s.whatsapp.net"))
    197212
    198213        def logout(self):
     
    216231                self.yow.Ship(UnsubscribePresenceProtocolEntity(handle))
    217232
    218         def set_away(self, _state, status):
     233        def set_away(self, state, status):
    219234                # When our first status is set, we've finalised login.
    220235                # Which means sync the full contact list now.
     
    223238                        self.send_initial_contacts()
    224239               
    225                 # I think state is not supported?
    226                 print "Trying to set status to %r, %r" % (_state, status)
    227                 self.yow.Ship(SetStatusIqProtocolEntity(status))
     240                print "Trying to set status to %r, %r" % (state, status)
     241                if state:
     242                        # Only one option offered so None = available, not None = away.
     243                        self.yow.Ship(AvailablePresenceProtocolEntity())
     244                else:
     245                        self.yow.Ship(UnavailablePresenceProtocolEntity())
     246                if status:
     247                        self.yow.Ship(SetStatusIqProtocolEntity(status))
    228248
    229249        def send_initial_contacts(self):
     
    236256                self.yow.Ship(PresenceProtocolEntity(name=value))
    237257
     258        def chat_join(self, id, name, _nick, _password, settings):
     259                print "New chat created with id: %d" % id
     260                self.groups[name] = {"id": id, "name": name}
     261                self.groups_by_id[id] = self.groups[name]
     262                self.bee.chat_add_buddy(id, self.account["user"])
     263       
     264        def chat_msg(self, id, text, flags):
     265                msg = TextMessageProtocolEntity(text, to=self.groups_by_id[id]["name"])
     266                self.yow.Ship(msg)
     267
    238268        def build_stack(self, account):
     269                self.account = account
    239270                creds = (account["user"].split("@")[0], account["pass"])
    240271
Note: See TracChangeset for help on using the changeset viewer.