changeset 14:9bf8ed012adc

- Group microblog management, first draft - Bad connexion issue fixed
author Goffi <goffi@goffi.org>
date Thu, 07 Apr 2011 22:27:36 +0200
parents 0110d4e1d816
children 78bfc398926b
files libervia.py libervia.tac
diffstat 2 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libervia.py	Thu Mar 31 00:01:16 2011 +0200
+++ b/libervia.py	Thu Apr 07 22:27:36 2011 +0200
@@ -76,7 +76,7 @@
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/json_api",
-                        ["getContacts", "sendMblog"])
+                        ["getContacts", "sendMblog", "getMblogNodes"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self):
@@ -329,7 +329,6 @@
         self.bridge.call('getContacts', self._getContactsCB)
         self.bridge_signals.call('getSignals', self._getSignalsCB)
 
-
     def _getContactsCB(self, contacts_data):
         for contact in contacts_data:
             jid, attributes, groups = contact
--- a/libervia.tac	Thu Mar 31 00:01:16 2011 +0200
+++ b/libervia.tac	Thu Apr 07 22:27:36 2011 +0200
@@ -32,7 +32,7 @@
 from txjsonrpc.web import jsonrpc
 from txjsonrpc import jsonrpclib
 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
-
+import re
 from server_side.blog import MicroBlog
 
 TIMEOUT = 120 #Session's time out, after that the user will be disconnected
@@ -63,11 +63,18 @@
     def jsonrpc_sendMblog(self, raw_text):
         """Parse raw_text of the microblog box, and send message consequently"""
         profile = self.session.sat_profile
-        if raw_text.startswith('@@: '):
-            #This text if for the public microblog
-            text = raw_text[4:]
-            if text:
+        match = re.match(r'@(.+?): *(.*$)', raw_text)
+        if match:
+            recip = match.group(1)
+            text = match.group(2)
+            if recip == '@' and text:
+                #This text if for the public microblog
+                print "Sending message to everybody"
                 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile)
+            else:
+                return self.sat_host.bridge.sendGroupBlog([recip], text, profile)
+
+
 
 class Register(jsonrpc.JSONRPC):
     """This class manage the registration procedure with SàT
@@ -86,6 +93,11 @@
         else:
             return None
 
+    def _fillMblogNodes(self, result, session):
+        """Fill the microblog nodes association for this session"""
+        print "Filling session for %s with %s" % (session.sat_profile, result)
+        session.sat_mblog_nodes = dict(result)
+
     def render(self, request):
         """
         Render method with some hacks:
@@ -138,7 +150,7 @@
             return "ALREADY WAITING"
         
         if self.sat_host.bridge.isConnected(_login):
-            return self._logged(_login, request)
+            return self._logged(_login, request, finish=False)
 
         self.profiles_waiting[_login] = request
         self.sat_host.bridge.connect(_login) 
@@ -151,13 +163,20 @@
         except KeyError:
             pass
 
-    def _logged(self, login, request):
+    def _logged(self, profile, request, finish=True):
         """Set everything when a user just logged
         and return "LOGGED" to the requester"""
-        self.__cleanWaiting(login)
+        self.__cleanWaiting(profile)
         _session = request.getSession()
-        _session.sat_profile = login
-        return 'LOGGED'
+        _session.sat_profile = profile
+        d = defer.Deferred()
+        self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback)
+        d.addCallback(self._fillMblogNodes, _session)
+        if finish:
+            request.write('LOGGED')
+            request.finish()
+        else:
+            return "LOGGED"
 
     def _logginError(self, login, request, error_type):
         """Something went wrong during loggin, return an error"""