Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
131:ddfcc4cb6cee | 132:30d8e328559b |
---|---|
26 from pyjamas.Timer import Timer | 26 from pyjamas.Timer import Timer |
27 from pyjamas import Window, DOM | 27 from pyjamas import Window, DOM |
28 from pyjamas.JSONService import JSONProxy | 28 from pyjamas.JSONService import JSONProxy |
29 from browser_side.register import RegisterBox | 29 from browser_side.register import RegisterBox |
30 from browser_side.contact import ContactPanel | 30 from browser_side.contact import ContactPanel |
31 from browser_side.panels import WidgetsPanel | 31 from browser_side.panels import WidgetsPanel, MicroblogItem |
32 from browser_side import panels, dialog | 32 from browser_side import panels, dialog |
33 from browser_side.jid import JID | 33 from browser_side.jid import JID |
34 from browser_side.tools import html_sanitize | 34 from browser_side.tools import html_sanitize |
35 | 35 |
36 MAX_MBLOG_CACHE = 500 #Max microblog entries kept in memories | 36 MAX_MBLOG_CACHE = 500 #Max microblog entries kept in memories |
46 if cb: | 46 if cb: |
47 self.cb[id] = cb | 47 self.cb[id] = cb |
48 | 48 |
49 def onRemoteResponse(self, response, request_info): | 49 def onRemoteResponse(self, response, request_info): |
50 if self.cb.has_key(request_info.id): | 50 if self.cb.has_key(request_info.id): |
51 self.cb[request_info.id](response) | 51 _cb = self.cb[request_info.id] |
52 if isinstance(_cb, tuple): | |
53 #we have arguments attached to the callback | |
54 #we send them after the answer | |
55 callback, args = _cb | |
56 callback(response, *args) | |
57 else: | |
58 #No additional argument, we call directly the callback | |
59 _cb(response) | |
52 del self.cb[request_info.id] | 60 del self.cb[request_info.id] |
53 | 61 |
54 def onRemoteError(self, code, errobj, request_info): | 62 def onRemoteError(self, code, errobj, request_info): |
55 """def dump(obj): | 63 """def dump(obj): |
56 print "\n\nDUMPING %s\n\n" % obj | 64 print "\n\nDUMPING %s\n\n" % obj |
68 | 76 |
69 class RegisterCall(LiberviaJsonProxy): | 77 class RegisterCall(LiberviaJsonProxy): |
70 def __init__(self): | 78 def __init__(self): |
71 LiberviaJsonProxy.__init__(self, "/register_api", | 79 LiberviaJsonProxy.__init__(self, "/register_api", |
72 ["isRegistered","isConnected","connect"]) | 80 ["isRegistered","isConnected","connect"]) |
73 self.handler=self | |
74 self.cb={} | |
75 | 81 |
76 class BridgeCall(LiberviaJsonProxy): | 82 class BridgeCall(LiberviaJsonProxy): |
77 def __init__(self): | 83 def __init__(self): |
78 LiberviaJsonProxy.__init__(self, "/json_api", | 84 LiberviaJsonProxy.__init__(self, "/json_api", |
79 ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", | 85 ["getContacts", "addContact", "sendMessage", "sendMblog", "getLastMblogs", "getMassiveLastMblogs", "getProfileJid", "getHistory", "getPresenceStatus", |
80 "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", | 86 "joinMUC", "getRoomsJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", |
81 "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"]) | 87 "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCardCache"]) |
82 | 88 |
83 class BridgeSignals(LiberviaJsonProxy): | 89 class BridgeSignals(LiberviaJsonProxy): |
84 def __init__(self, host): | 90 def __init__(self, host): |
93 Window.alert('You are not allowed to connect to server') | 99 Window.alert('You are not allowed to connect to server') |
94 else: | 100 else: |
95 def _timerCb(): | 101 def _timerCb(): |
96 self.host.bridge_signals.call('getSignals', self.host._getSignalsCB) | 102 self.host.bridge_signals.call('getSignals', self.host._getSignalsCB) |
97 Timer(notify=_timerCb).schedule(5000) #we wait 5 s and try again | 103 Timer(notify=_timerCb).schedule(5000) #we wait 5 s and try again |
98 | |
99 class MicroblogEntry(): | |
100 def __init__(self, data): | |
101 self.id = data['id'] | |
102 self.content = data['content'] | |
103 self.author = data['author'] | |
104 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here | |
105 | |
106 | 104 |
107 class SatWebFrontend: | 105 class SatWebFrontend: |
108 def onModuleLoad(self): | 106 def onModuleLoad(self): |
109 self.whoami = None | 107 self.whoami = None |
110 self.bridge = BridgeCall() | 108 self.bridge = BridgeCall() |
119 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets | 117 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets |
120 self.room_list = set() #set of rooms | 118 self.room_list = set() #set of rooms |
121 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel | 119 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel |
122 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) | 120 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) |
123 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) | 121 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) |
124 self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True)) | 122 mblog_panel = panels.MicroblogPanel(self, []) |
123 self.bridge.call('getMassiveLastMblogs', mblog_panel.massiveInsert, 'ALL', [], 10) | |
124 self.discuss_panel.addWidget(mblog_panel) | |
125 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) | 125 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) |
126 self._register_box = None | 126 self._register_box = None |
127 RootPanel().add(self.panel) | 127 RootPanel().add(self.panel) |
128 DOM.addEventPreview(self) | 128 DOM.addEventPreview(self) |
129 self.resize() | 129 self.resize() |
280 return | 280 return |
281 if data.has_key('groups'): | 281 if data.has_key('groups'): |
282 _groups = set(data['groups'].split() if data['groups'] else []) | 282 _groups = set(data['groups'].split() if data['groups'] else []) |
283 else: | 283 else: |
284 _groups=None | 284 _groups=None |
285 mblog_entry = MicroblogEntry(data) | 285 mblog_entry = MicroblogItem(data) |
286 | 286 |
287 for lib_wid in self.libervia_widgets: | 287 for lib_wid in self.libervia_widgets: |
288 if isinstance(lib_wid, panels.MicroblogPanel): | 288 if isinstance(lib_wid, panels.MicroblogPanel): |
289 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) | 289 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) |
290 | 290 |
295 def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry): | 295 def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry): |
296 """Check if an entry can go in MicroblogPanel and add to it | 296 """Check if an entry can go in MicroblogPanel and add to it |
297 @param mblog_panel: MicroblogPanel instance | 297 @param mblog_panel: MicroblogPanel instance |
298 @param sender: jid of the entry sender | 298 @param sender: jid of the entry sender |
299 @param _groups: groups which can receive this entry | 299 @param _groups: groups which can receive this entry |
300 @param mblog_entry: MicroblogEntry instance""" | 300 @param mblog_entry: MicroblogItem instance""" |
301 if mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \ | 301 if mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \ |
302 or (_groups and _groups.intersection(mblog_panel.accepted_groups)): | 302 or (_groups and _groups.intersection(mblog_panel.accepted_groups)): |
303 mblog_panel.addEntry(mblog_entry) | 303 mblog_panel.addEntry(mblog_entry) |
304 | 304 |
305 def FillMicroblogPanel(self, mblog_entry): | 305 def FillMicroblogPanel(self, mblog_entry): |