comparison src/plugins/plugin_xep_0249.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 2daf7b4c6756
children 200cd707a46d
comparison
equal deleted inserted replaced
1962:a45235d8dc93 1963:a2bc5089c2eb
123 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE): 123 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
124 """Accept the invitation to join a MUC. 124 """Accept the invitation to join a MUC.
125 125
126 @param room (jid.JID): JID of the room 126 @param room (jid.JID): JID of the room
127 """ 127 """
128 profile = self.host.memory.getProfileName(profile_key) 128 client = self.host.getClient(profile_key)
129 if not profile: 129 log.info(_(u'Invitation accepted for room %(room)s [%(profile)s]') % {'room': room_jid.userhost(), 'profile': client.profile})
130 log.error(_("Profile doesn't exists !")) 130 d = self.host.plugins["XEP-0045"].join(client, room_jid, client.jid.user, {})
131 return
132 log.info(_(u'Invitation accepted for room %(room)s [%(profile)s]') % {'room': room_jid.userhost(), 'profile': profile})
133 _jid, xmlstream = self.host.getJidNStream(profile)
134 d = self.host.plugins["XEP-0045"].join(room_jid, _jid.user, {}, profile)
135 return d 131 return d
136 132
137 def onInvitation(self, message, profile): 133 def onInvitation(self, message, profile):
138 """ 134 """
139 called when an invitation is received 135 called when an invitation is received
163 self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_jid_s, 'room': room_jid_s}, _("MUC invitation"), "INFO", profile) 159 self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_jid_s, 'room': room_jid_s}, _("MUC invitation"), "INFO", profile)
164 else: # leave the default value here 160 else: # leave the default value here
165 data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_jid_s, 'room': room_jid_s}, "title": _("MUC invitation")} 161 data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_jid_s, 'room': room_jid_s}, "title": _("MUC invitation")}
166 self.host.askConfirmation(room_jid_s, "YES/NO", data, accept_cb, profile) 162 self.host.askConfirmation(room_jid_s, "YES/NO", data, accept_cb, profile)
167 163
168 def cmd_invite(self, mess_data, profile): 164 def cmd_invite(self, client, mess_data):
169 """invite someone in the room 165 """invite someone in the room
170 166
171 @command (group): JID 167 @command (group): JID
172 - JID: the JID of the person to invite 168 - JID: the JID of the person to invite
173 """ 169 """
174 contact_jid_s = mess_data["unparsed"].strip() 170 contact_jid_s = mess_data["unparsed"].strip()
175 my_host = self.host.profiles[profile].jid.host 171 my_host = client.jid.host
176 try: 172 try:
177 contact_jid = jid.JID(contact_jid_s) 173 contact_jid = jid.JID(contact_jid_s)
178 except (RuntimeError, jid.InvalidFormat, AttributeError): 174 except (RuntimeError, jid.InvalidFormat, AttributeError):
179 feedback = _(u"You must provide a valid JID to invite, like in '/invite contact@{host}'").format(host=my_host) 175 feedback = _(u"You must provide a valid JID to invite, like in '/invite contact@{host}'").format(host=my_host)
180 self.host.plugins[C.TEXT_CMDS].feedBack(feedback, mess_data, profile) 176 self.host.plugins[C.TEXT_CMDS].feedBack(client, feedback, mess_data)
181 return False 177 return False
182 if not contact_jid.user: 178 if not contact_jid.user:
183 contact_jid.user, contact_jid.host = contact_jid.host, my_host 179 contact_jid.user, contact_jid.host = contact_jid.host, my_host
184 self.invite(contact_jid, mess_data["to"], {}, profile) 180 self.invite(contact_jid, mess_data["to"], {}, client.profile)
185 return False 181 return False
186 182
187 183
188 class XEP_0249_handler(XMPPHandler): 184 class XEP_0249_handler(XMPPHandler):
189 implements(iwokkel.IDisco) 185 implements(iwokkel.IDisco)