Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0249.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | 75f3b3b430ff |
children | 291eb8216f6e |
comparison
equal
deleted
inserted
replaced
992:f51a1895275c | 993:301b342c697a |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from logging import debug, info, warning, error | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | |
23 from twisted.words.xish import domish | 24 from twisted.words.xish import domish |
24 from twisted.internet import protocol, defer | 25 from twisted.words.protocols.jabber import jid |
25 from twisted.words.protocols.jabber import client, jid, xmlstream | |
26 | 26 |
27 from zope.interface import implements | 27 from zope.interface import implements |
28 | 28 |
29 from wokkel import disco, iwokkel, data_form | 29 from wokkel import disco, iwokkel |
30 | 30 |
31 | 31 |
32 try: | 32 try: |
33 from twisted.words.protocols.xmlstream import XMPPHandler | 33 from twisted.words.protocols.xmlstream import XMPPHandler |
34 except ImportError: | 34 except ImportError: |
74 (value, 'selected="true"' if value == AUTOJOIN_VALUES[0] else '') \ | 74 (value, 'selected="true"' if value == AUTOJOIN_VALUES[0] else '') \ |
75 for value in AUTOJOIN_VALUES]) | 75 for value in AUTOJOIN_VALUES]) |
76 } | 76 } |
77 | 77 |
78 def __init__(self, host): | 78 def __init__(self, host): |
79 info(_("Plugin XEP_0249 initialization")) | 79 log.info(_("Plugin XEP_0249 initialization")) |
80 self.host = host | 80 self.host = host |
81 host.memory.updateParams(self.params) | 81 host.memory.updateParams(self.params) |
82 host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite) | 82 host.bridge.addMethod("inviteMUC", ".plugin", in_sign='sssa{ss}s', out_sign='', method=self._invite) |
83 | 83 |
84 def getHandler(self, profile): | 84 def getHandler(self, profile): |
92 @options: attribute with extra info (reason, password) as in #XEP-0249 | 92 @options: attribute with extra info (reason, password) as in #XEP-0249 |
93 @profile_key: %(doc_profile_key)s | 93 @profile_key: %(doc_profile_key)s |
94 """ | 94 """ |
95 profile = self.host.memory.getProfileName(profile_key) | 95 profile = self.host.memory.getProfileName(profile_key) |
96 if not profile: | 96 if not profile: |
97 error(_("Profile doesn't exists !")) | 97 log.error(_("Profile doesn't exists !")) |
98 return | 98 return |
99 message = domish.Element((None, 'message')) | 99 message = domish.Element((None, 'message')) |
100 message["to"] = target.full() | 100 message["to"] = target.full() |
101 x_elt = message.addElement('x', NS_DIRECT_MUC_INVITATION) | 101 x_elt = message.addElement('x', NS_DIRECT_MUC_INVITATION) |
102 x_elt['jid'] = room.userhost() | 102 x_elt['jid'] = room.userhost() |
120 Accept the invitation to join a MUC | 120 Accept the invitation to join a MUC |
121 @param room: room jid as string | 121 @param room: room jid as string |
122 """ | 122 """ |
123 profile = self.host.memory.getProfileName(profile_key) | 123 profile = self.host.memory.getProfileName(profile_key) |
124 if not profile: | 124 if not profile: |
125 error(_("Profile doesn't exists !")) | 125 log.error(_("Profile doesn't exists !")) |
126 return | 126 return |
127 info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) | 127 log.info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) |
128 _jid, xmlstream = self.host.getJidNStream(profile) | 128 _jid, xmlstream = self.host.getJidNStream(profile) |
129 d = self.host.plugins["XEP-0045"].join(jid.JID(room), _jid.user, {}, profile) | 129 d = self.host.plugins["XEP-0045"].join(jid.JID(room), _jid.user, {}, profile) |
130 return d | |
130 | 131 |
131 def onInvitation(self, message, profile): | 132 def onInvitation(self, message, profile): |
132 """ | 133 """ |
133 called when an invitation is received | 134 called when an invitation is received |
134 @param message: message element | 135 @param message: message element |
135 @profile: %(doc_profile)s | 136 @profile: %(doc_profile)s |
136 """ | 137 """ |
137 try: | 138 try: |
138 room = message.firstChildElement()['jid'] | 139 room = message.firstChildElement()['jid'] |
139 info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) | 140 log.info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile}) |
140 except: | 141 except: |
141 error(_('Error while parsing invitation')) | 142 log.error(_('Error while parsing invitation')) |
142 return | 143 return |
143 from_ = message["from"] | 144 from_ = message["from"] |
144 if room in self.host.plugins["XEP-0045"].clients[profile].joined_rooms: | 145 if room in self.host.plugins["XEP-0045"].clients[profile].joined_rooms: |
145 info(_("Invitation silently discarded because user is already in the room.")) | 146 log.info(_("Invitation silently discarded because user is already in the room.")) |
146 return | 147 return |
147 autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile) | 148 autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile) |
148 | 149 |
149 def accept_cb(conf_id, accepted, data, profile): | 150 def accept_cb(conf_id, accepted, data, profile): |
150 if conf_id == room and accepted: | 151 if conf_id == room and accepted: |