comparison src/core/sat_main.py @ 1963:a2bc5089c2eb

backend, frontends: message refactoring (huge commit): /!\ several features are temporarily disabled, like notifications in frontends next step in refactoring, with the following changes: - jp: updated jp message to follow changes in backend/bridge - jp: added --lang, --subject, --subject_lang, and --type options to jp message + fixed unicode handling for jid - quick_frontend (QuickApp, QuickChat): - follow backend changes - refactored chat, message are now handled in OrderedDict and uid are kept so they can be updated - Message and Occupant classes handle metadata, so frontend just have to display them - Primitivus (Chat): - follow backend/QuickFrontend changes - info & standard messages are handled in the same MessageWidget class - improved/simplified handling of messages, removed update() method - user joined/left messages are merged when next to each other - a separator is shown when message is received while widget is out of focus, so user can quickly see the new messages - affiliation/role are shown (in a basic way for now) in occupants panel - removed "/me" messages handling, as it will be done by a backend plugin - message language is displayed when available (only one language per message for now) - fixed :history and :search commands - core (constants): new constants for messages type, XML namespace, entity type - core: *Message methods renamed to follow new code sytle (e.g. sendMessageToBridge => messageSendToBridge) - core (messages handling): fixed handling of language - core (messages handling): mes_data['from'] and ['to'] are now jid.JID - core (core.xmpp): reorganised message methods, added getNick() method to client.roster - plugin text commands: fixed plugin and adapted to new messages behaviour. client is now used in arguments instead of profile - plugins: added information for cancellation reason in CancelError calls - plugin XEP-0045: various improvments, but this plugin still need work: - trigger is used to avoid message already handled by the plugin to be handled a second time - changed the way to handle history, the last message from DB is checked and we request only messages since this one, in seconds (thanks Poezio folks :)) - subject reception is waited before sending the roomJoined signal, this way we are sure that everything including history is ready - cmd_* method now follow the new convention with client instead of profile - roomUserJoined and roomUserLeft messages are removed, the events are now handled with info message with a "ROOM_USER_JOINED" info subtype - probably other forgotten stuffs :p
author Goffi <goffi@goffi.org>
date Mon, 20 Jun 2016 18:41:53 +0200
parents 633b5c21aefd
children 19b9d3f8a6c7
comparison
equal deleted inserted replaced
1962:a45235d8dc93 1963:a2bc5089c2eb
93 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA) 93 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA)
94 self.bridge.register("asyncGetParamsValuesFromCategory", self.memory.asyncGetParamsValuesFromCategory) 94 self.bridge.register("asyncGetParamsValuesFromCategory", self.memory.asyncGetParamsValuesFromCategory)
95 self.bridge.register("getParamsUI", self.memory.getParamsUI) 95 self.bridge.register("getParamsUI", self.memory.getParamsUI)
96 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) 96 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
97 self.bridge.register("paramsRegisterApp", self.memory.paramsRegisterApp) 97 self.bridge.register("paramsRegisterApp", self.memory.paramsRegisterApp)
98 self.bridge.register("historyGet", self.memory.historyGet) 98 self.bridge.register("historyGet", self.memory._historyGet)
99 self.bridge.register("setPresence", self._setPresence) 99 self.bridge.register("setPresence", self._setPresence)
100 self.bridge.register("subscription", self.subscription) 100 self.bridge.register("subscription", self.subscription)
101 self.bridge.register("addContact", self._addContact) 101 self.bridge.register("addContact", self._addContact)
102 self.bridge.register("updateContact", self._updateContact) 102 self.bridge.register("updateContact", self._updateContact)
103 self.bridge.register("delContact", self._delContact) 103 self.bridge.register("delContact", self._delContact)
551 # by a plugin to avoid id on purpose 551 # by a plugin to avoid id on purpose
552 message_elt['id'] = data['uid'] 552 message_elt['id'] = data['uid']
553 for lang, subject in data["subject"].iteritems(): 553 for lang, subject in data["subject"].iteritems():
554 subject_elt = message_elt.addElement("subject", content=subject) 554 subject_elt = message_elt.addElement("subject", content=subject)
555 if lang: 555 if lang:
556 subject_elt['xml:lang'] = lang 556 subject_elt[(C.NS_XML, 'lang')] = lang
557 for lang, message in data["message"].iteritems(): 557 for lang, message in data["message"].iteritems():
558 body_elt = message_elt.addElement("body", content=message) 558 body_elt = message_elt.addElement("body", content=message)
559 if lang: 559 if lang:
560 body_elt['xml:lang'] = lang 560 body_elt[(C.NS_XML, 'lang')] = lang
561 try: 561 try:
562 thread = data['extra']['thread'] 562 thread = data['extra']['thread']
563 except KeyError: 563 except KeyError:
564 if 'thread_parent' in data['extra']: 564 if 'thread_parent' in data['extra']:
565 raise exceptions.InternalError(u"thread_parent found while there is not associated thread") 565 raise exceptions.InternalError(u"thread_parent found while there is not associated thread")
644 644
645 log.debug(_(u"Sending message (type {type}, to {to})").format(type=data["type"], to=to_jid.full())) 645 log.debug(_(u"Sending message (type {type}, to {to})").format(type=data["type"], to=to_jid.full()))
646 646
647 pre_xml_treatments.addCallback(lambda dummy: self.generateMessageXML(data)) 647 pre_xml_treatments.addCallback(lambda dummy: self.generateMessageXML(data))
648 pre_xml_treatments.chainDeferred(post_xml_treatments) 648 pre_xml_treatments.chainDeferred(post_xml_treatments)
649 post_xml_treatments.addCallback(self._sendMessageToStream, client) 649 post_xml_treatments.addCallback(self.messageSendToStream, client)
650 if send_only: 650 if send_only:
651 log.debug(_("Triggers, storage and echo have been inhibited by the 'send_only' parameter")) 651 log.debug(_("Triggers, storage and echo have been inhibited by the 'send_only' parameter"))
652 else: 652 else:
653 post_xml_treatments.addCallback(self._storeMessage, client) 653 post_xml_treatments.addCallback(self.messageAddToHistory, client)
654 post_xml_treatments.addCallback(self.sendMessageToBridge, client) 654 post_xml_treatments.addCallback(self.messageSendToBridge, client)
655 post_xml_treatments.addErrback(self._cancelErrorTrap) 655 post_xml_treatments.addErrback(self._cancelErrorTrap)
656 pre_xml_treatments.callback(data) 656 pre_xml_treatments.callback(data)
657 return pre_xml_treatments 657 return pre_xml_treatments
658 658
659 def _cancelErrorTrap(failure): 659 def _cancelErrorTrap(self, failure):
660 """A message sending can be cancelled by a plugin treatment""" 660 """A message sending can be cancelled by a plugin treatment"""
661 failure.trap(exceptions.CancelError) 661 failure.trap(exceptions.CancelError)
662 662
663 def _sendMessageToStream(self, data, client): 663 def messageSendToStream(self, data, client):
664 """Actualy send the message to the server 664 """Actualy send the message to the server
665 665
666 @param data: message data dictionnary 666 @param data: message data dictionnary
667 @param client: profile's client 667 @param client: profile's client
668 """ 668 """
669 client.xmlstream.send(data['xml']) 669 client.xmlstream.send(data['xml'])
670 return data 670 return data
671 671
672 def _storeMessage(self, data, client): 672 def messageAddToHistory(self, data, client):
673 """Store message into database (for local history) 673 """Store message into database (for local history)
674 674
675 @param data: message data dictionnary 675 @param data: message data dictionnary
676 @param client: profile's client 676 @param client: profile's client
677 """ 677 """
678 if data["type"] != C.MESS_TYPE_GROUPCHAT: 678 if data["type"] != C.MESS_TYPE_GROUPCHAT:
679 # we don't add groupchat message to history, as we get them back 679 # we don't add groupchat message to history, as we get them back
680 # and they will be added then 680 # and they will be added then
681 if data['message']: # we need a message to save something 681 if data['message'] or data['subject']: # we need a message to store
682 self.memory.addToHistory(client, data) 682 self.memory.addToHistory(client, data)
683 else: 683 else:
684 log.warning(u"No message found") # empty body should be managed by plugins before this point 684 log.warning(u"No message found") # empty body should be managed by plugins before this point
685 return data 685 return data
686 686
687 def sendMessageToBridge(self, data, client): 687 def messageSendToBridge(self, data, client):
688 """Send message to bridge, so frontends can display it 688 """Send message to bridge, so frontends can display it
689 689
690 @param data: message data dictionnary 690 @param data: message data dictionnary
691 @param client: profile's client 691 @param client: profile's client
692 """ 692 """
693 if data["type"] != C.MESS_TYPE_GROUPCHAT: 693 if data["type"] != C.MESS_TYPE_GROUPCHAT:
694 # we don't send groupchat message to bridge, as we get them back 694 # we don't send groupchat message to bridge, as we get them back
695 # and they will be added the 695 # and they will be added the
696 if data['message']: # we need a message to send something 696 if data['message'] or data['subject']: # we need a message to send something
697 # We send back the message, so all frontends are aware of it 697 # We send back the message, so all frontends are aware of it
698 self.bridge.messageNew(data['uid'], data['timestamp'], data['from'].full(), data['to'].full(), data['message'], data['subject'], data['type'], data['extra'], profile=client.profile) 698 self.bridge.messageNew(data['uid'], data['timestamp'], data['from'].full(), data['to'].full(), data['message'], data['subject'], data['type'], data['extra'], profile=client.profile)
699 else: 699 else:
700 log.warning(_("No message found")) 700 log.warning(_("No message found"))
701 return data 701 return data
1037 1037
1038 #Menus management 1038 #Menus management
1039 1039
1040 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, help_string="", type_=C.MENU_GLOBAL): 1040 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, help_string="", type_=C.MENU_GLOBAL):
1041 """register a new menu for frontends 1041 """register a new menu for frontends
1042
1042 @param path: path to go to the menu (category/subcategory/.../item), must be an iterable (e.g.: ("File", "Open")) 1043 @param path: path to go to the menu (category/subcategory/.../item), must be an iterable (e.g.: ("File", "Open"))
1043 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open"))) 1044 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open")))
1044 @param callback: method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback] 1045 @param callback: method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback]
1045 @param security_limit: %(doc_security_limit)s 1046 @param security_limit: %(doc_security_limit)s
1046 /!\ security_limit MUST be added to data in launchCallback if used #TODO 1047 /!\ security_limit MUST be added to data in launchCallback if used #TODO