Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_app.py @ 1461:9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
- adaptation to backend modifications
- moved common blogging parts from Libervia to quick frontend
- QuickApp use a MB_HANDLE class variable to indicated if blogging is managed by the frontend (and avoid waste of resources if not)
- comments are now managed inside parent entry, as a result a tree of comments is now possible
- Entry.level indicate where in the tree we are (-1 mean parent QuickBlog, 0 mean main item, more means comment)
- items + comments are requested in 1 shot, and RTDeferred are used to avoid blocking while waiting for them
- in QuickBlog, id2entries allow to get Entry from it's item id, and node2entries allow to get Entry(ies) hosting a comments node
- QuickBlog.new_message_target tell where a new message will be sent by default
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Aug 2015 01:00:54 +0200 |
parents | 6ce18c4e5708 |
children | 731fbed0b9cf |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Sun Aug 16 00:41:58 2015 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Sun Aug 16 01:00:54 2015 +0200 @@ -27,6 +27,7 @@ from sat_frontends.tools import jid from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend import quick_menus +from sat_frontends.quick_frontend import quick_blog from sat_frontends.quick_frontend import quick_chat, quick_games from sat_frontends.quick_frontend.constants import Const as C @@ -196,6 +197,7 @@ class QuickApp(object): """This class contain the main methods needed for the frontend""" + MB_HANDLE = True # Set to false if the frontend doesn't manage microblog def __init__(self, create_bridge, check_options=None): """Create a frontend application @@ -254,7 +256,7 @@ self.registerSignal("roomUserChangedNick", iface="plugin") self.registerSignal("roomNewSubject", iface="plugin") self.registerSignal("chatStateReceived", iface="plugin") - self.registerSignal("personalEvent", iface="plugin") + self.registerSignal("psEvent", iface="plugin") # FIXME: do it dynamically quick_games.Tarot.registerSignals(self) @@ -607,15 +609,42 @@ contact_list.setCache(from_jid, 'chat_state', to_display) widget.update(from_jid) - def personalEventHandler(self, sender, event_type, data, profile): - """Called when a PEP event is received. + def psEventHandler(self, category, service_s, node, event_type, data, profile): + """Called when a PubSub event is received. - @param sender (jid.JID): event sender - @param event_type (unicode): event type, e.g. 'MICROBLOG' or 'MICROBLOG_DELETE' + @param category(unicode): event category (e.g. "PEP", "MICROBLOG") + @param service_s (unicode): pubsub service + @param node (unicode): pubsub node + @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE) @param data (dict): event data """ - # FIXME move some code from Libervia to here and put the magic strings to constants - pass + service_s = jid.JID(service_s) + + if category == C.PS_MICROBLOG and self.MB_HANDLE: + if event_type == C.PS_PUBLISH: + 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 + + for wid in self.widgets.getWidgets(quick_blog.QuickBlog): + wid.addEntryIfAccepted(service_s, node, data, _groups, profile) + + try: + comments_node, comments_service = data['comments_node'], data['comments_service'] + except KeyError: + pass + else: + self.bridge.mbGetLast(comments_service, comments_node, C.NO_LIMIT, {"subscribe":C.BOOL_TRUE}, profile=profile) + elif event_type == C.PS_RETRACT: + for wid in self.widgets.getWidgets(quick_blog.QuickBlog): + wid.deleteEntryIfPresent(service_s, node, data['id'], profile) + pass + else: + log.warning("Unmanaged PubSub event type {}".format(event_type)) def _subscribe_cb(self, answer, data): entity, profile = data