changeset 28:258dfaa1035f

browser side: - roomJoined signal added and open a new tab - name refactoring - connected contact are saved - launchTarotGame method used
author Goffi <goffi@goffi.org>
date Sat, 07 May 2011 23:58:57 +0200
parents d89982865c57
children 8152f019d334
files browser_side/contact.py libervia.py
diffstat 2 files changed, 47 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/contact.py	Sat May 07 23:54:21 2011 +0200
+++ b/browser_side/contact.py	Sat May 07 23:58:57 2011 +0200
@@ -119,6 +119,7 @@
         SimplePanel.__init__(self)
         self.host = host
         self.groups={}
+        self.connected = {} #jid connected as key and their status
 
         self.vPanel = VerticalPanel()
         _title = ContactTitleLabel('Contacts')
@@ -144,10 +145,27 @@
             if not self.groups.has_key(group):
                 self.groups[group] = set()
                 self._groupList.add(group)
-                self.host.uniBox.addKey("@%s: " % group)
+                self.host.uni_box.addKey("@%s: " % group)
             self.groups[group].add(jid)
         self._contactList.add(jid)
 
+    def setConnected(self, jid, resource, availability, priority, statuses):
+        """Set connection status"""
+        if availability=='unavailable':
+            if self.connected.has_key(jid):
+                if self.connected[jid].has_key(resource):
+                    del self.connected[jid][resource]
+                if not self.connected[jid]:
+                    del self.connected[jid]
+        else: 
+            if not self.connected.has_key(jid):
+                self.connected[jid] = {}
+            self.connected[jid][resource] = (availability, priority, statuses)
+
+    def getConnected(self):
+        """return a list of all jid  (bare jid) connected"""
+        return self.connected.keys()
+
     def isContactInGroup(self, group, contact_jid):
        """Test if the contact_jid is in the group
        @param group: string of single group, or list of string
--- a/libervia.py	Sat May 07 23:54:21 2011 +0200
+++ b/libervia.py	Sat May 07 23:58:57 2011 +0200
@@ -70,7 +70,7 @@
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/json_api",
-                        ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus"])
+                        ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", "launchTarotGame"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self):
@@ -79,6 +79,7 @@
 
 
 class UniBox(AutoCompleteTextBox):
+    """This text box is used as a main typing point, for message, microblog, etc"""
 
     def __init__(self, host):
         AutoCompleteTextBox.__init__(self)
@@ -141,7 +142,7 @@
                 type = "STATUS"
             else:
                 target = txt[1:_end] #only one target group is managed for the moment
-                if not target in self.host.contactPanel.getGroups():
+                if not target in self.host.contact_panel.getGroups():
                     target = None
         elif self.host.selected == None:
             type = "STATUS"
@@ -189,10 +190,10 @@
         self.bridge = BridgeCall()
         self.bridge_signals = BridgeSignals()
         self.selected = None
-        self.uniBox = UniBox(self)
-        self.uniBox.addKey("@@: ")
-        self.statusPanel = StatusPanel(self)
-        self.contactPanel = ContactPanel(self)
+        self.uni_box = UniBox(self)
+        self.uni_box.addKey("@@: ")
+        self.status_panel = StatusPanel(self)
+        self.contact_panel = ContactPanel(self)
         self.panel = MainPanel(self)
         self.discuss_panel = self.panel.discuss_panel
         self.tab_panel = self.panel.tab_panel 
@@ -240,7 +241,7 @@
     def _getContactsCB(self, contacts_data):
         for contact in contacts_data:
             jid, attributes, groups = contact
-            self.contactPanel.addContact(jid, attributes, groups)
+            self.contact_panel.addContact(jid, attributes, groups)
 
     def _getSignalsCB(self, signal_data):
         bridge_signals = BridgeSignals()
@@ -253,6 +254,8 @@
             self._newMessageCb(*args)
         elif name == 'presenceUpdate':
             self._presenceUpdateCb(*args)
+        elif name == 'roomJoined':
+            self._roomJoinedCb(*args)
 
     def _getProfileJidCB(self, jid):
         self.whoami = JID(jid)
@@ -288,17 +291,27 @@
 
     def _presenceUpdateCb(self, entity, show, priority, statuses):
         _entity = JID(entity)
-        #XXX: QnD way to only get our status
+        #XXX: QnD way to get our status
         if self.whoami and self.whoami.bare == _entity.bare and statuses:
-            self.statusPanel.changeStatus(statuses.values()[0])
+            self.status_panel.changeStatus(statuses.values()[0])
+        if not self.whoami or self.whoami.bare != _entity.bare: 
+            self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses)
+
+    def _roomJoinedCb(self, room_id, room_service, room_nicks, user_nick, profile):
+        print "roomJoined"
+        print room_id
+        _target = JID("%s@%s" % (room_id,room_service))
+        if room_id.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :)
+            self.tab_panel.add(ChatPanel(self, _target), "Tarot")
+        else:
+            self.tab_panel.add(ChatPanel(self, _target), str(_target)) 
+
             
     def _getPresenceStatusCB(self, presence_data):
-        #XXX we are only interested in our own presence so far
-        if self.whoami and presence_data.has_key(self.whoami.bare):
-            myjid = self.whoami.bare
-            if presence_data[myjid]:
-                args = presence_data[myjid].values()[0]
-                self._presenceUpdateCb(myjid, *args)
+        for entity in presence_data:
+            for resource in presence_data[entity]:
+                args = presence_data[entity][resource]
+                self._presenceUpdateCb("%s/%s" % (entity, resource), *args)
 
 if __name__ == '__main__':
     pyjd.setup("http://localhost:8080/libervia.html")