comparison libervia.py @ 139:b6658f3ac8a0

browser side: own microblogs print - our microblogs are gotten on startup and put in cache - FillMicroblogPanel add our own microblogs from cache in a new panel
author Goffi <goffi@goffi.org>
date Tue, 30 Oct 2012 00:52:30 +0100
parents 008fa8d36602
children a5e9aa1f9c0c
comparison
equal deleted inserted replaced
138:008fa8d36602 139:b6658f3ac8a0
115 self.panel = panels.MainPanel(self) 115 self.panel = panels.MainPanel(self)
116 self.discuss_panel = self.panel.discuss_panel 116 self.discuss_panel = self.panel.discuss_panel
117 self.tab_panel = self.panel.tab_panel 117 self.tab_panel = self.panel.tab_panel
118 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets 118 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets
119 self.room_list = set() #set of rooms 119 self.room_list = set() #set of rooms
120 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel 120 self.mblog_cache = [] #used to keep our own blog entries in memory, to show them in new mblog panel
121 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file) 121 self.avatars_cache = {} #keep track of jid's avatar hash (key=jid, value=file)
122 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) 122 #self.discuss_panel.addWidget(panels.EmptyPanel(self))
123 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) 123 self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
124 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) 124 #self.discuss_panel.addWidget(panels.EmptyPanel(self))
125 self._register_box = None 125 self._register_box = None
259 elif name == 'newContact': 259 elif name == 'newContact':
260 self._newContactCb(*args) 260 self._newContactCb(*args)
261 elif name == 'entityDataUpdated': 261 elif name == 'entityDataUpdated':
262 self._entityDataUpdatedCb(*args) 262 self._entityDataUpdatedCb(*args)
263 263
264 def _ownBlogsFills(self, mblogs):
265 #put our own microblogs in cache, then fill all panels with them
266 for publisher in mblogs:
267 for mblog in mblogs[publisher]:
268 if not mblog.has_key('content'):
269 print ("WARNING: No content found in microblog [%s]", mblog)
270 continue
271 if mblog.has_key('groups'):
272 _groups = set(mblog['groups'].split() if mblog['groups'] else [])
273 else:
274 _groups=None
275 mblog_entry = MicroblogItem(mblog)
276 self.mblog_cache.append((_groups, mblog_entry))
277
278 if len(self.mblog_cache) > MAX_MBLOG_CACHE:
279 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)]
280 for lib_wid in self.libervia_widgets:
281 if isinstance(lib_wid, panels.MicroblogPanel):
282 self.FillMicroblogPanel(lib_wid)
283
264 def _getProfileJidCB(self, jid): 284 def _getProfileJidCB(self, jid):
265 self.whoami = JID(jid) 285 self.whoami = JID(jid)
266 #we can now ask our status 286 #we can now ask our status
267 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) 287 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb)
268 #the rooms where we are 288 #the rooms where we are
274 if isinstance(lib_wid, panels.MicroblogPanel): 294 if isinstance(lib_wid, panels.MicroblogPanel):
275 if lib_wid.accept_all(): 295 if lib_wid.accept_all():
276 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) 296 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10)
277 else: 297 else:
278 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) 298 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10)
279 #FIXME: we currently get all post and filter after for each widget, need to be optimised 299
280 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'JID', [jid], 10) 300 #we ask for our own microblogs:
301 self.bridge.call('getMassiveLastMblogs', self._ownBlogsFills, 'JID', [self.whoami.bare], 10)
281 302
282 ## Signals callbacks ## 303 ## Signals callbacks ##
283 304
284 def _personalEventCb(self, sender, event_type, data): 305 def _personalEventCb(self, sender, event_type, data):
285 if event_type == "MICROBLOG": 306 if event_type == "MICROBLOG":
294 315
295 for lib_wid in self.libervia_widgets: 316 for lib_wid in self.libervia_widgets:
296 if isinstance(lib_wid, panels.MicroblogPanel): 317 if isinstance(lib_wid, panels.MicroblogPanel):
297 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) 318 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry)
298 319
299 self.mblog_cache.append((sender, _groups, mblog_entry)) 320 if sender == self.whoami.bare:
300 if len(self.mblog_cache) > MAX_MBLOG_CACHE: 321 self.mblog_cache.append((_groups, mblog_entry))
301 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] 322 if len(self.mblog_cache) > MAX_MBLOG_CACHE:
323 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)]
302 324
303 def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry): 325 def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry):
304 """Check if an entry can go in MicroblogPanel and add to it 326 """Check if an entry can go in MicroblogPanel and add to it
305 @param mblog_panel: MicroblogPanel instance 327 @param mblog_panel: MicroblogPanel instance
306 @param sender: jid of the entry sender 328 @param sender: jid of the entry sender
308 @param mblog_entry: MicroblogItem instance""" 330 @param mblog_entry: MicroblogItem instance"""
309 if mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \ 331 if mblog_panel.isJidAccepted(sender) or (_groups == None and self.whoami and sender == self.whoami.bare) \
310 or (_groups and _groups.intersection(mblog_panel.accepted_groups)): 332 or (_groups and _groups.intersection(mblog_panel.accepted_groups)):
311 mblog_panel.addEntry(mblog_entry) 333 mblog_panel.addEntry(mblog_entry)
312 334
313 def FillMicroblogPanel(self, mblog_entry): 335 def FillMicroblogPanel(self, mblog_panel):
314 """Fill a microblog panel with entries in cache 336 """Fill a microblog panel with entries in cache
315 @param mblog_panel: MicroblogPanel instance 337 @param mblog_panel: MicroblogPanel instance
316 """ 338 """
339 #XXX: only our own entries are cached
317 for cache_entry in self.mblog_cache: 340 for cache_entry in self.mblog_cache:
318 self.addBlogEntry(mblog_entry, *cache_entry) 341 _groups, mblog_entry = cache_entry
342 self.addBlogEntry(mblog_panel, self.whoami.bare, *cache_entry)
319 343
320 def _newMessageCb(self, from_jid, msg, msg_type, to_jid): 344 def _newMessageCb(self, from_jid, msg, msg_type, to_jid):
321 _from = JID(from_jid) 345 _from = JID(from_jid)
322 _to = JID(to_jid) 346 _to = JID(to_jid)
323 showed = False 347 showed = False