comparison 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
comparison
equal deleted inserted replaced
1460:c7fd121a6180 1461:9fce331ba0fd
25 from sat.tools import trigger 25 from sat.tools import trigger
26 26
27 from sat_frontends.tools import jid 27 from sat_frontends.tools import jid
28 from sat_frontends.quick_frontend import quick_widgets 28 from sat_frontends.quick_frontend import quick_widgets
29 from sat_frontends.quick_frontend import quick_menus 29 from sat_frontends.quick_frontend import quick_menus
30 from sat_frontends.quick_frontend import quick_blog
30 from sat_frontends.quick_frontend import quick_chat, quick_games 31 from sat_frontends.quick_frontend import quick_chat, quick_games
31 from sat_frontends.quick_frontend.constants import Const as C 32 from sat_frontends.quick_frontend.constants import Const as C
32 33
33 import sys 34 import sys
34 from collections import OrderedDict 35 from collections import OrderedDict
194 return self._profiles.keys()[0] 195 return self._profiles.keys()[0]
195 196
196 197
197 class QuickApp(object): 198 class QuickApp(object):
198 """This class contain the main methods needed for the frontend""" 199 """This class contain the main methods needed for the frontend"""
200 MB_HANDLE = True # Set to false if the frontend doesn't manage microblog
199 201
200 def __init__(self, create_bridge, check_options=None): 202 def __init__(self, create_bridge, check_options=None):
201 """Create a frontend application 203 """Create a frontend application
202 204
203 @param create_bridge: method to use to create the Bridge 205 @param create_bridge: method to use to create the Bridge
252 self.registerSignal("roomUserJoined", iface="plugin") 254 self.registerSignal("roomUserJoined", iface="plugin")
253 self.registerSignal("roomUserLeft", iface="plugin") 255 self.registerSignal("roomUserLeft", iface="plugin")
254 self.registerSignal("roomUserChangedNick", iface="plugin") 256 self.registerSignal("roomUserChangedNick", iface="plugin")
255 self.registerSignal("roomNewSubject", iface="plugin") 257 self.registerSignal("roomNewSubject", iface="plugin")
256 self.registerSignal("chatStateReceived", iface="plugin") 258 self.registerSignal("chatStateReceived", iface="plugin")
257 self.registerSignal("personalEvent", iface="plugin") 259 self.registerSignal("psEvent", iface="plugin")
258 260
259 # FIXME: do it dynamically 261 # FIXME: do it dynamically
260 quick_games.Tarot.registerSignals(self) 262 quick_games.Tarot.registerSignals(self)
261 quick_games.Quiz.registerSignals(self) 263 quick_games.Quiz.registerSignals(self)
262 quick_games.Radiocol.registerSignals(self) 264 quick_games.Radiocol.registerSignals(self)
605 widget.update(occupant) 607 widget.update(occupant)
606 elif from_jid.bare == widget.target.bare: # roster contact or MUC occupant 608 elif from_jid.bare == widget.target.bare: # roster contact or MUC occupant
607 contact_list.setCache(from_jid, 'chat_state', to_display) 609 contact_list.setCache(from_jid, 'chat_state', to_display)
608 widget.update(from_jid) 610 widget.update(from_jid)
609 611
610 def personalEventHandler(self, sender, event_type, data, profile): 612 def psEventHandler(self, category, service_s, node, event_type, data, profile):
611 """Called when a PEP event is received. 613 """Called when a PubSub event is received.
612 614
613 @param sender (jid.JID): event sender 615 @param category(unicode): event category (e.g. "PEP", "MICROBLOG")
614 @param event_type (unicode): event type, e.g. 'MICROBLOG' or 'MICROBLOG_DELETE' 616 @param service_s (unicode): pubsub service
617 @param node (unicode): pubsub node
618 @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE)
615 @param data (dict): event data 619 @param data (dict): event data
616 """ 620 """
617 # FIXME move some code from Libervia to here and put the magic strings to constants 621 service_s = jid.JID(service_s)
618 pass 622
623 if category == C.PS_MICROBLOG and self.MB_HANDLE:
624 if event_type == C.PS_PUBLISH:
625 if not 'content' in data:
626 log.warning("No content found in microblog data")
627 return
628 if 'groups' in data:
629 _groups = set(data['groups'].split() if data['groups'] else [])
630 else:
631 _groups = None
632
633 for wid in self.widgets.getWidgets(quick_blog.QuickBlog):
634 wid.addEntryIfAccepted(service_s, node, data, _groups, profile)
635
636 try:
637 comments_node, comments_service = data['comments_node'], data['comments_service']
638 except KeyError:
639 pass
640 else:
641 self.bridge.mbGetLast(comments_service, comments_node, C.NO_LIMIT, {"subscribe":C.BOOL_TRUE}, profile=profile)
642 elif event_type == C.PS_RETRACT:
643 for wid in self.widgets.getWidgets(quick_blog.QuickBlog):
644 wid.deleteEntryIfPresent(service_s, node, data['id'], profile)
645 pass
646 else:
647 log.warning("Unmanaged PubSub event type {}".format(event_type))
619 648
620 def _subscribe_cb(self, answer, data): 649 def _subscribe_cb(self, answer, data):
621 entity, profile = data 650 entity, profile = data
622 type_ = "subscribed" if answer else "unsubscribed" 651 type_ = "subscribed" if answer else "unsubscribed"
623 self.bridge.subscription(type_, unicode(entity.bare), profile_key=profile) 652 self.bridge.subscription(type_, unicode(entity.bare), profile_key=profile)