comparison src/plugins/plugin_xep_0249.py @ 1358:bf3f669a6052 frontends_multi_profiles

plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:35:21 +0100
parents 291eb8216f6e
children 876c9fbd0b3d
comparison
equal deleted inserted replaced
1357:f296a54af386 1358:bf3f669a6052
118 @param profile_key: %(doc_profile_key)s 118 @param profile_key: %(doc_profile_key)s
119 """ 119 """
120 #TODO: check parameters validity 120 #TODO: check parameters validity
121 self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key) 121 self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key)
122 122
123 def _accept(self, room, profile_key=C.PROF_KEY_NONE): 123 def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
124 """ 124 """Accept the invitation to join a MUC.
125 Accept the invitation to join a MUC 125
126 @param room: room jid as string 126 @param room (jid.JID): JID of the room
127 """ 127 """
128 profile = self.host.memory.getProfileName(profile_key) 128 profile = self.host.memory.getProfileName(profile_key)
129 if not profile: 129 if not profile:
130 log.error(_("Profile doesn't exists !")) 130 log.error(_("Profile doesn't exists !"))
131 return 131 return
132 log.info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) 132 log.info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room_jid.userhost(), 'profile': profile})
133 _jid, xmlstream = self.host.getJidNStream(profile) 133 _jid, xmlstream = self.host.getJidNStream(profile)
134 d = self.host.plugins["XEP-0045"].join(jid.JID(room), _jid.user, {}, profile) 134 d = self.host.plugins["XEP-0045"].join(room_jid, _jid.user, {}, profile)
135 return d 135 return d
136 136
137 def onInvitation(self, message, profile): 137 def onInvitation(self, message, profile):
138 """ 138 """
139 called when an invitation is received 139 called when an invitation is received
140 @param message: message element 140 @param message: message element
141 @profile: %(doc_profile)s 141 @profile: %(doc_profile)s
142 """ 142 """
143 try: 143 try:
144 room = message.firstChildElement()['jid'] 144 room_jid_s = message.firstChildElement()['jid']
145 log.info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) 145 log.info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room_jid_s, 'profile': profile})
146 except: 146 except:
147 log.error(_('Error while parsing invitation')) 147 log.error(_('Error while parsing invitation'))
148 return 148 return
149 from_ = message["from"] 149 from_jid_s = message["from"]
150 if room in self.host.plugins["XEP-0045"].clients[profile].joined_rooms: 150 room_jid = jid.JID(room_jid_s)
151 if room_jid in self.host.plugins["XEP-0045"].clients[profile].joined_rooms:
151 log.info(_("Invitation silently discarded because user is already in the room.")) 152 log.info(_("Invitation silently discarded because user is already in the room."))
152 return 153 return
153 autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile) 154 autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile)
154 155
155 def accept_cb(conf_id, accepted, data, profile): 156 def accept_cb(conf_id, accepted, data, profile):
156 if conf_id == room and accepted: 157 if conf_id == room_jid_s and accepted:
157 self._accept(room, profile) 158 self._accept(room_jid, profile)
158 159
159 if autojoin == "always": 160 if autojoin == "always":
160 self._accept(room, profile) 161 self._accept(room_jid, profile)
161 elif autojoin == "never": 162 elif autojoin == "never":
162 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_, 'room': room}, _("MUC invitation"), "INFO", profile) 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)
163 else: # leave the default value here 164 else: # leave the default value here
164 data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_, 'room': room}, "title": _("MUC invitation")} 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")}
165 self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile) 166 self.host.askConfirmation(room_jid_s, "YES/NO", data, accept_cb, profile)
166 167
167 def cmd_invite(self, mess_data, profile): 168 def cmd_invite(self, mess_data, profile):
168 """invite someone in the room 169 """invite someone in the room
169 170
170 @command (group): (JID) 171 @command (group): (JID)