# HG changeset patch # User Goffi # Date 1351554750 -3600 # Node ID b6658f3ac8a0fbe5769badd6598da19f8394c902 # Parent 008fa8d3660267470cfdd7cbfd42006d810c5a43 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 diff -r 008fa8d36602 -r b6658f3ac8a0 browser_side/panels.py --- a/browser_side/panels.py Sun Oct 28 18:24:18 2012 +0100 +++ b/browser_side/panels.py Tue Oct 30 00:52:30 2012 +0100 @@ -99,7 +99,7 @@ if item_type=="GROUP": _new_panel = MicroblogPanel(self.host, [item]) _new_panel.setAcceptedGroup(item) - #self.host.FillMicroblogPanel(_new_panel) #XXX: cache is temporarly deactivated, need to be reworked + self.host.FillMicroblogPanel(_new_panel) self.host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'GROUP', [item], 10) elif item_type=="CONTACT": _contact = JID(item) @@ -108,7 +108,7 @@ _new_panel.historyPrint() elif item_type=="CONTACT_TITLE": _new_panel = MicroblogPanel(self.host, []) - #self.host.FillMicroblogPanel(_new_panel) #XXX: cache is temporarly deactivated, need to be reworked + self.host.FillMicroblogPanel(_new_panel) self.host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) else: return False diff -r 008fa8d36602 -r b6658f3ac8a0 libervia.py --- a/libervia.py Sun Oct 28 18:24:18 2012 +0100 +++ b/libervia.py Tue Oct 30 00:52:30 2012 +0100 @@ -117,7 +117,7 @@ self.tab_panel = self.panel.tab_panel self.libervia_widgets = set() #keep track of all actives LiberviaWidgets self.room_list = set() #set of rooms - self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel + self.mblog_cache = [] #used to keep our own 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, [])) @@ -261,6 +261,26 @@ elif name == 'entityDataUpdated': self._entityDataUpdatedCb(*args) + def _ownBlogsFills(self, mblogs): + #put our own microblogs in cache, then fill all panels with them + for publisher in mblogs: + for mblog in mblogs[publisher]: + if not mblog.has_key('content'): + print ("WARNING: No content found in microblog [%s]", mblog) + continue + if mblog.has_key('groups'): + _groups = set(mblog['groups'].split() if mblog['groups'] else []) + else: + _groups=None + mblog_entry = MicroblogItem(mblog) + self.mblog_cache.append((_groups, mblog_entry)) + + if len(self.mblog_cache) > MAX_MBLOG_CACHE: + del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid, panels.MicroblogPanel): + self.FillMicroblogPanel(lib_wid) + def _getProfileJidCB(self, jid): self.whoami = JID(jid) #we can now ask our status @@ -276,8 +296,9 @@ self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'ALL', [], 10) else: self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'GROUP', lib_wid.accepted_groups, 10) - #FIXME: we currently get all post and filter after for each widget, need to be optimised - self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'JID', [jid], 10) + + #we ask for our own microblogs: + self.bridge.call('getMassiveLastMblogs', self._ownBlogsFills, 'JID', [self.whoami.bare], 10) ## Signals callbacks ## @@ -296,9 +317,10 @@ if isinstance(lib_wid, panels.MicroblogPanel): self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) - self.mblog_cache.append((sender, _groups, mblog_entry)) - if len(self.mblog_cache) > MAX_MBLOG_CACHE: - del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] + if sender == self.whoami.bare: + self.mblog_cache.append((_groups, mblog_entry)) + if len(self.mblog_cache) > MAX_MBLOG_CACHE: + del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] def addBlogEntry(self, mblog_panel, sender, _groups, mblog_entry): """Check if an entry can go in MicroblogPanel and add to it @@ -310,12 +332,14 @@ or (_groups and _groups.intersection(mblog_panel.accepted_groups)): mblog_panel.addEntry(mblog_entry) - def FillMicroblogPanel(self, mblog_entry): + def FillMicroblogPanel(self, mblog_panel): """Fill a microblog panel with entries in cache @param mblog_panel: MicroblogPanel instance """ + #XXX: only our own entries are cached for cache_entry in self.mblog_cache: - self.addBlogEntry(mblog_entry, *cache_entry) + _groups, mblog_entry = cache_entry + self.addBlogEntry(mblog_panel, self.whoami.bare, *cache_entry) def _newMessageCb(self, from_jid, msg, msg_type, to_jid): _from = JID(from_jid)