diff libervia.py @ 132:30d8e328559b

server & browser side: microblogging refactoring first draft - use of new getLastGroupBlogs and getMassiveLastGroupBlogs methods - microblgos browser's cache is temporarily deactivated - last 10 microblogs for everybody are requested on new meta microblog widget
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2012 00:25:38 +0200
parents ddfcc4cb6cee
children ee7b4aecdc67
line wrap: on
line diff
--- a/libervia.py	Tue Mar 06 09:09:15 2012 +0100
+++ b/libervia.py	Mon Apr 02 00:25:38 2012 +0200
@@ -28,7 +28,7 @@
 from pyjamas.JSONService import JSONProxy
 from browser_side.register import RegisterBox
 from browser_side.contact import ContactPanel
-from browser_side.panels import WidgetsPanel
+from browser_side.panels import WidgetsPanel, MicroblogItem
 from browser_side import panels, dialog
 from browser_side.jid import JID
 from browser_side.tools import html_sanitize
@@ -48,7 +48,15 @@
 
     def onRemoteResponse(self, response, request_info):
         if self.cb.has_key(request_info.id):
-            self.cb[request_info.id](response)
+            _cb = self.cb[request_info.id]
+            if isinstance(_cb, tuple):
+                #we have arguments attached to the callback
+                #we send them after the answer
+                callback, args = _cb
+                callback(response, *args)
+            else:
+                #No additional argument, we call directly the callback
+                _cb(response)
             del self.cb[request_info.id]
         
     def onRemoteError(self, code, errobj, request_info):
@@ -70,13 +78,11 @@
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/register_api",
                         ["isRegistered","isConnected","connect"])
-        self.handler=self
-        self.cb={}
 
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/json_api",
-                        ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus",
+                        ["getContacts", "addContact", "sendMessage", "sendMblog", "getLastMblogs", "getMassiveLastMblogs", "getProfileJid", "getHistory", "getPresenceStatus",
                          "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed",
                          "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"])
 
@@ -96,14 +102,6 @@
                 self.host.bridge_signals.call('getSignals', self.host._getSignalsCB)
             Timer(notify=_timerCb).schedule(5000) #we wait 5 s and try again
 
-class MicroblogEntry():
-    def __init__(self, data):
-        self.id = data['id']
-        self.content = data['content']
-        self.author = data['author']
-        self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here
-        
-
 class SatWebFrontend:
     def onModuleLoad(self):
         self.whoami = None
@@ -121,7 +119,9 @@
         self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel
         self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file)
         #self.discuss_panel.addWidget(panels.EmptyPanel(self))
-        self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True))
+        mblog_panel = panels.MicroblogPanel(self, [])
+        self.bridge.call('getMassiveLastMblogs', mblog_panel.massiveInsert, 'ALL', [], 10)
+        self.discuss_panel.addWidget(mblog_panel)
         #self.discuss_panel.addWidget(panels.EmptyPanel(self))
         self._register_box = None
         RootPanel().add(self.panel)
@@ -282,7 +282,7 @@
                 _groups = set(data['groups'].split() if data['groups'] else [])
             else:
                 _groups=None
-            mblog_entry = MicroblogEntry(data)
+            mblog_entry = MicroblogItem(data)
             
             for lib_wid in self.libervia_widgets:
                 if isinstance(lib_wid, panels.MicroblogPanel):
@@ -297,7 +297,7 @@
         @param mblog_panel: MicroblogPanel instance
         @param sender: jid of the entry sender
         @param _groups: groups which can receive this entry
-        @param mblog_entry: MicroblogEntry instance"""
+        @param mblog_entry: MicroblogItem instance"""
         if mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \
            or (_groups and _groups.intersection(mblog_panel.accepted_groups)):
             mblog_panel.addEntry(mblog_entry)