Mercurial > xib
comparison muc.py @ 170:11717d14e22f
created muc._send(), should have been done ages ago
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 30 Jan 2010 14:34:43 +0100 |
parents | 59401ac0f47a |
children | 2a81c480439a |
comparison
equal
deleted
inserted
replaced
169:271c35321497 | 170:11717d14e22f |
---|---|
39 | 39 |
40 def _join(self, callback=None): | 40 def _join(self, callback=None): |
41 self.callback = callback | 41 self.callback = callback |
42 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) | 42 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) |
43 s = xmpp.protocol.Presence(to=self.jid, status=self.status, payload=[xmpp.simplexml.Node(tag='x', attrs={'xmlns': 'http://jabber.org/protocol/muc'}, payload=[xmpp.simplexml.Node(tag='history', attrs={'maxchars': '0'})])]) | 43 s = xmpp.protocol.Presence(to=self.jid, status=self.status, payload=[xmpp.simplexml.Node(tag='x', attrs={'xmlns': 'http://jabber.org/protocol/muc'}, payload=[xmpp.simplexml.Node(tag='history', attrs={'maxchars': '0'})])]) |
44 self._send(s) | |
45 | |
46 | |
47 def _send(self, stanza): | |
44 try: | 48 try: |
45 self.xmpp_c.send(s) | 49 self.xmpp_c.send(stanza) |
46 except IOError, xmpp.Conflict: | 50 except IOError, xmpp.Conflict: |
47 self.xmpp_c.reconnectAndReauth() | 51 self.xmpp_c.reconnectAndReauth() |
48 for m in self.xmpp_c.mucs: | 52 for m in self.xmpp_c.mucs: |
49 m.rejoin() | 53 m.rejoin() |
50 self.xmpp_c.send(s) | 54 self.xmpp_c.send(stanza) |
51 | 55 |
52 | 56 |
53 def join(self, xmpp_c, nickname, status=None, callback=None): | 57 def join(self, xmpp_c, nickname, status=None, callback=None): |
54 """Join room on xmpp_c connection using nickname""" | 58 """Join room on xmpp_c connection using nickname""" |
55 self.jid = self.room_jid+'/'+nickname | 59 self.jid = self.room_jid+'/'+nickname |
107 | 111 |
108 def say(self, message): | 112 def say(self, message): |
109 """Say message in the room""" | 113 """Say message in the room""" |
110 self.xmpp_c.lock.acquire() | 114 self.xmpp_c.lock.acquire() |
111 s = xmpp.protocol.Message(to=self.room_jid, typ='groupchat', body=message) | 115 s = xmpp.protocol.Message(to=self.room_jid, typ='groupchat', body=message) |
112 try: | 116 self._send(s) |
113 self.xmpp_c.send(s) | |
114 except IOError, xmpp.Conflict: | |
115 self.xmpp_c.reconnectAndReauth() | |
116 for m in self.xmpp_c.mucs: | |
117 m.rejoin() | |
118 self.xmpp_c.send(s) | |
119 self.xmpp_c.lock.release() | 117 self.xmpp_c.lock.release() |
120 | 118 |
121 | 119 |
122 def sayTo(self, to, message): | 120 def sayTo(self, to, message): |
123 """Send a private message""" | 121 """Send a private message""" |
124 self.xmpp_c.lock.acquire() | 122 self.xmpp_c.lock.acquire() |
125 s = xmpp.protocol.Message(to=self.room_jid+'/'+to, typ='chat', body=message) | 123 s = xmpp.protocol.Message(to=self.room_jid+'/'+to, typ='chat', body=message) |
126 try: | 124 self._send(s) |
127 self.xmpp_c.send(s) | |
128 except IOError, xmpp.Conflict: | |
129 self.xmpp_c.reconnectAndReauth() | |
130 for m in self.xmpp_c.mucs: | |
131 m.rejoin() | |
132 self.xmpp_c.send(s) | |
133 self.xmpp_c.lock.release() | 125 self.xmpp_c.lock.release() |
134 | 126 |
135 | 127 |
136 def change_nick(self, nickname, status=None, callback=None): | 128 def change_nick(self, nickname, status=None, callback=None): |
137 """Change nickname""" | 129 """Change nickname""" |
138 self.jid = self.room_jid+'/'+nickname | 130 self.jid = self.room_jid+'/'+nickname |
139 self.callback = callback | 131 self.callback = callback |
140 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) | 132 self.xmpp_c.RegisterHandler('presence', self._xmpp_presence_handler) |
141 self.xmpp_c.lock.acquire() | 133 self.xmpp_c.lock.acquire() |
142 s = xmpp.protocol.Presence(to=self.jid, status=status) | 134 s = xmpp.protocol.Presence(to=self.jid, status=status) |
143 try: | 135 self._send(s) |
144 self.xmpp_c.send(s) | |
145 except IOError, xmpp.Conflict: | |
146 self.xmpp_c.reconnectAndReauth() | |
147 for m in self.xmpp_c.mucs: | |
148 m.rejoin() | |
149 self.xmpp_c.send(s) | |
150 self.xmpp_c.lock.release() | 136 self.xmpp_c.lock.release() |
151 | 137 |
152 | 138 |
153 def leave(self, message=''): | 139 def leave(self, message=''): |
154 """Leave the room""" | 140 """Leave the room""" |
155 self.xmpp_c.lock.acquire() | 141 self.xmpp_c.lock.acquire() |
156 s = xmpp.protocol.Presence(to=self.jid, typ='unavailable', status=message) | 142 s = xmpp.protocol.Presence(to=self.jid, typ='unavailable', status=message) |
157 try: | 143 self._send(s) |
158 self.xmpp_c.send(s) | |
159 except IOError, xmpp.Conflict: | |
160 self.xmpp_c.reconnectAndReauth() | |
161 for m in self.xmpp_c.mucs: | |
162 m.rejoin() | |
163 self.xmpp_c.send(s) | |
164 self.connected = False | 144 self.connected = False |
165 self.xmpp_c.lock.release() | 145 self.xmpp_c.lock.release() |
166 | 146 |
167 | 147 |
168 def rejoin(self, callback=None): | 148 def rejoin(self, callback=None): |