Mercurial > libervia-web
diff src/browser/libervia_main.py @ 716:3b91225b457a
server + browser side: blogging refactoring (draft), huge commit sorry:
/!\ everything is not working yet, group blog is not working for now
- adaptation to backend changes
- frontend commons part of blog have been moved to QuickFrontend
- (editors) button "WYSIWYG edition" renamed to "preview"
- (editors) Shift + [ENTER] is now used to send a text message, [ENTER] to finish a ligne normally
- (editors) fixed modifiers handling
- global simplification, resulting of the refactoring
- with backend refactoring, we are now using PEP again, XEP-0277 compatibility is restored \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Aug 2015 01:51:12 +0200 |
parents | 03e9fe91081c |
children | 5745b5e6586a |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Tue Jul 28 22:22:10 2015 +0200 +++ b/src/browser/libervia_main.py Sun Aug 16 01:51:12 2015 +0200 @@ -38,7 +38,7 @@ from sat.core.i18n import _ from pyjamas.ui.RootPanel import RootPanel -from pyjamas.ui.HTML import HTML +# from pyjamas.ui.HTML import HTML from pyjamas.ui.KeyboardListener import KEY_ESCAPE from pyjamas.Timer import Timer from pyjamas import Window, DOM @@ -69,7 +69,7 @@ unicode = str # FIXME: pyjamas workaround -MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories +# MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories # FIXME class SatWebFrontend(InputHistory, QuickApp): @@ -357,19 +357,25 @@ def profilePlugged(self, dummy): self._profile_plugged = True QuickApp.profilePlugged(self, C.PROF_KEY_NONE) + # XXX: as contact_list.update() is slow and it's called a lot of time + # during profile plugging, we prevent it before it's plugged + # and do all at once now + contact_list = self.contact_list + contact_list.update() - microblog_widget = self.displayWidget(blog.MicroblogPanel, ()) - self.setSelected(microblog_widget) + + blog_widget = self.displayWidget(blog.Blog, ()) + self.setSelected(blog_widget) # we fill the panels already here - for wid in self.widgets.getWidgets(blog.MicroblogPanel): - if wid.accept_all(): - self.bridge.getMassiveMblogs('ALL', (), None, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert) - else: - self.bridge.getMassiveMblogs('GROUP', list(wid.accepted_groups), None, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert) + # for wid in self.widgets.getWidgets(blog.MicroblogPanel): + # if wid.accept_all(): + # self.bridge.getMassiveMblogs('ALL', (), None, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert) + # else: + # self.bridge.getMassiveMblogs('GROUP', list(wid.accepted_groups), None, profile=C.PROF_KEY_NONE, callback=wid.massiveInsert) #we ask for our own microblogs: - self.loadOurMainEntries() + # self.loadOurMainEntries() def gotDefaultMUC(default_muc): self.default_muc = default_muc @@ -438,6 +444,7 @@ ui = xmlui.create(self, xml_data=data['xmlui']) ui.show() elif "public_blog" in data: + # FIXME: remove this, this is not generic ! # TODO: use the bare instead of node when all blogs can be retrieved node = jid.JID(data['public_blog']).node # FIXME: "/blog/{}" won't work with unicode nodes @@ -461,126 +468,94 @@ data = {} self.bridge.launchAction(callback_id, data, profile=profile, callback=self._actionCb, errback=self._actionEb) - def _ownBlogsFills(self, mblogs, mblog_panel=None): - """Put our own microblogs in cache, then fill the panels with them. + # def _ownBlogsFills(self, mblogs, mblog_panel=None): + # """Put our own microblogs in cache, then fill the panels with them. - @param mblogs (dict): dictionary mapping a publisher JID to blogs data. - @param mblog_panel (MicroblogPanel): the panel to fill, or all if None. - """ - cache = [] - for publisher in mblogs: - for mblog in mblogs[publisher][0]: - if 'content' not in mblog: - log.warning(u"No content found in microblog [%s]" % mblog) - continue - if 'groups' in mblog: - _groups = set(mblog['groups'].split() if mblog['groups'] else []) - else: - _groups = None - mblog_entry = blog.MicroblogItem(mblog) - cache.append((_groups, mblog_entry)) + # @param mblogs (dict): dictionary mapping a publisher JID to blogs data. + # @param mblog_panel (MicroblogPanel): the panel to fill, or all if None. + # """ + # cache = [] + # for publisher in mblogs: + # for mblog in mblogs[publisher][0]: + # if 'content' not in mblog: + # log.warning(u"No content found in microblog [%s]" % mblog) + # continue + # if 'groups' in mblog: + # _groups = set(mblog['groups'].split() if mblog['groups'] else []) + # else: + # _groups = None + # mblog_entry = blog.MicroblogItem(mblog) + # cache.append((_groups, mblog_entry)) - self.mblog_cache.extend(cache) - if len(self.mblog_cache) > MAX_MBLOG_CACHE: - del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)] + # self.mblog_cache.extend(cache) + # if len(self.mblog_cache) > MAX_MBLOG_CACHE: + # del self.mblog_cache[0:len(self.mblog_cache - MAX_MBLOG_CACHE)] - widget_list = [mblog_panel] if mblog_panel else self.widgets.getWidgets(blog.MicroblogPanel) + # widget_list = [mblog_panel] if mblog_panel else self.widgets.getWidgets(blog.MicroblogPanel) - for wid in widget_list: - self.fillMicroblogPanel(wid, cache) + # for wid in widget_list: + # self.fillMicroblogPanel(wid, cache) - # FIXME + # # FIXME - if self.initialised: - return - self.initialised = True # initialisation phase is finished here - for event_data in self.init_cache: # so we have to send all the cached events - self.personalEventHandler(*event_data) - del self.init_cache + # if self.initialised: + # return + # self.initialised = True # initialisation phase is finished here + # for event_data in self.init_cache: # so we have to send all the cached events + # self.personalEventHandler(*event_data) + # del self.init_cache - def loadOurMainEntries(self, index=0, mblog_panel=None): - """Load a page of our own blogs from the cache or ask them to the - backend. Then fill the panels with them. + # def loadOurMainEntries(self, index=0, mblog_panel=None): + # """Load a page of our own blogs from the cache or ask them to the + # backend. Then fill the panels with them. - @param index (int): starting index of the blog page to retrieve. - @param mblog_panel (MicroblogPanel): the panel to fill, or all if None. - """ - delta = index - self.next_rsm_index - if delta < 0: - assert mblog_panel is not None - self.fillMicroblogPanel(mblog_panel, self.mblog_cache[index:index + C.RSM_MAX_ITEMS]) - return + # @param index (int): starting index of the blog page to retrieve. + # @param mblog_panel (MicroblogPanel): the panel to fill, or all if None. + # """ + # delta = index - self.next_rsm_index + # if delta < 0: + # assert mblog_panel is not None + # self.fillMicroblogPanel(mblog_panel, self.mblog_cache[index:index + C.RSM_MAX_ITEMS]) + # return - def cb(result): - self._ownBlogsFills(result, mblog_panel) + # def cb(result): + # self._ownBlogsFills(result, mblog_panel) - rsm = {'max_': str(delta + C.RSM_MAX_ITEMS), 'index': str(self.next_rsm_index)} - self.bridge.getMassiveMblogs('JID', [unicode(self.whoami.bare)], rsm, callback=cb, profile=C.PROF_KEY_NONE) - self.next_rsm_index = index + C.RSM_MAX_ITEMS + # rsm = {'max_': str(delta + C.RSM_MAX_ITEMS), 'index': str(self.next_rsm_index)} + # self.bridge.getMassiveMblogs('JID', [unicode(self.whoami.bare)], rsm, callback=cb, profile=C.PROF_KEY_NONE) + # self.next_rsm_index = index + C.RSM_MAX_ITEMS ## Signals callbacks ## - def personalEventHandler(self, sender, event_type, data): - # FIXME: move some code from here to QuickApp - if not self.initialised: - self.init_cache.append((sender, event_type, data)) - return - sender = jid.JID(sender).bare - if event_type == "MICROBLOG": - if not 'content' in data: - log.warning("No content found in microblog data") - return - if 'groups' in data: - _groups = set(data['groups'].split() if data['groups'] else []) - else: - _groups = None - mblog_entry = blog.MicroblogItem(data) + # def personalEventHandler(self, sender, event_type, data): + # elif event_type == 'MICROBLOG_DELETE': + # for wid in self.widgets.getWidgets(blog.MicroblogPanel): + # wid.removeEntry(data['type'], data['id']) - for wid in self.widgets.getWidgets(blog.MicroblogPanel): - wid.addEntryIfAccepted(sender, _groups, mblog_entry) + # if sender == self.whoami.bare and data['type'] == 'main_item': + # for index in xrange(0, len(self.mblog_cache)): + # entry = self.mblog_cache[index] + # if entry[1].id == data['id']: + # self.mblog_cache.remove(entry) + # break + + # def fillMicroblogPanel(self, mblog_panel, mblogs): + # """Fill a microblog panel with entries in cache - if sender == self.whoami.bare: - found = False - for index in xrange(0, len(self.mblog_cache)): - entry = self.mblog_cache[index] - if entry[1].id == mblog_entry.id: - # replace existing entry - self.mblog_cache.remove(entry) - self.mblog_cache.insert(index, (_groups, mblog_entry)) - found = True - break - if not found: - 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)] - elif event_type == 'MICROBLOG_DELETE': - for wid in self.widgets.getWidgets(blog.MicroblogPanel): - wid.removeEntry(data['type'], data['id']) + # @param mblog_panel: MicroblogPanel instance + # """ + # #XXX: only our own entries are cached + # for cache_entry in mblogs: + # _groups, mblog_entry = cache_entry + # mblog_panel.addEntryIfAccepted(self.whoami.bare, *cache_entry) - if sender == self.whoami.bare and data['type'] == 'main_item': - for index in xrange(0, len(self.mblog_cache)): - entry = self.mblog_cache[index] - if entry[1].id == data['id']: - self.mblog_cache.remove(entry) - break - - def fillMicroblogPanel(self, mblog_panel, mblogs): - """Fill a microblog panel with entries in cache - - @param mblog_panel: MicroblogPanel instance - """ - #XXX: only our own entries are cached - for cache_entry in mblogs: - _groups, mblog_entry = cache_entry - mblog_panel.addEntryIfAccepted(self.whoami.bare, *cache_entry) - - def getEntityMBlog(self, entity): - # FIXME: call this after a contact has been added to roster - log.info(u"geting mblog for entity [%s]" % (entity,)) - for lib_wid in self.libervia_widgets: - if isinstance(lib_wid, blog.MicroblogPanel): - if lib_wid.isJidAccepted(entity): - self.bridge.call('getMassiveMblogs', lib_wid.massiveInsert, 'JID', [unicode(entity)]) + # def getEntityMBlog(self, entity): + # # FIXME: call this after a contact has been added to roster + # log.info(u"geting mblog for entity [%s]" % (entity,)) + # for lib_wid in self.libervia_widgets: + # if isinstance(lib_wid, blog.MicroblogPanel): + # if lib_wid.isJidAccepted(entity): + # self.bridge.call('getMassiveMblogs', lib_wid.massiveInsert, 'JID', [unicode(entity)]) def displayWidget(self, class_, target, dropped=False, new_tab=None, *args, **kwargs): """Get or create a LiberviaWidget and select it. When the user dropped