comparison src/core/xmpp.py @ 346:ca3a041fed30

core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
author Goffi <goffi@goffi.org>
date Sat, 28 May 2011 20:28:21 +0200
parents 9eebdc655b8b
children ea3e1b82dd79
comparison
equal deleted inserted replaced
345:e6047415868d 346:ca3a041fed30
137 #def addItem(self, to): 137 #def addItem(self, to):
138 #"""Add a contact to roster list""" 138 #"""Add a contact to roster list"""
139 #xmppim.RosterClientProtocol.addItem(self, to) 139 #xmppim.RosterClientProtocol.addItem(self, to)
140 #TODO: check IQ result""" 140 #TODO: check IQ result"""
141 141
142 def updateItem(self, roster_item):
143 """
144 Update an item of the contact list.
145
146 @param roster_item: item to update
147 """
148 iq = compat.IQ(self.xmlstream, 'set')
149 iq.addElement((xmppim.NS_ROSTER, 'query'))
150 item = iq.query.addElement('item')
151 item['jid'] = roster_item.jid.userhost()
152 if roster_item.name:
153 item['name'] = roster_item.name
154 for group in roster_item.groups:
155 item.addElement('group', content=group)
156 return iq.send()
157
142 def onRosterSet(self, item): 158 def onRosterSet(self, item):
143 """Called when a new/update roster item is received""" 159 """Called when a new/update roster item is received"""
144 #TODO: send a signal to frontends 160 #TODO: send a signal to frontends
145 item_attr = {'to': str(item.subscriptionTo), 161 item_attr = {'to': str(item.subscriptionTo),
146 'from': str(item.subscriptionFrom), 162 'from': str(item.subscriptionFrom),
204 def available(self, entity=None, show=None, statuses=None, priority=0): 220 def available(self, entity=None, show=None, statuses=None, priority=0):
205 if statuses and statuses.has_key('default'): 221 if statuses and statuses.has_key('default'):
206 statuses[None] = statuses['default'] 222 statuses[None] = statuses['default']
207 del statuses['default'] 223 del statuses['default']
208 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) 224 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority)
209 225
226 def subscribed(self, entity):
227 xmppim.PresenceClientProtocol.subscribed(self, entity)
228 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
229 contact = self.host.memory.getContact(entity, self.parent.profile)
230 if not contact or contact[0]['to'] == 'False': #we automatically subscribe to 'to' presence
231 debug(_('sending automatic "from" subscription request'))
232 self.subscribe(entity)
233
234 def unsubscribed(self, entity):
235 xmppim.PresenceClientProtocol.unsubscribed(self, entity)
236 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
237
210 def subscribedReceived(self, entity): 238 def subscribedReceived(self, entity):
211 debug (_("subscription approved for [%s]") % entity.userhost()) 239 debug (_("subscription approved for [%s]") % entity.userhost())
212 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
213 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile) 240 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile)
214 241
215 def unsubscribedReceived(self, entity): 242 def unsubscribedReceived(self, entity):
216 debug (_("unsubscription confirmed for [%s]") % entity.userhost()) 243 debug (_("unsubscription confirmed for [%s]") % entity.userhost())
217 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
218 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile) 244 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile)
219 245
220 def subscribeReceived(self, entity): 246 def subscribeReceived(self, entity):
221 debug (_("subscription request for [%s]") % entity.userhost()) 247 debug (_("subscription request from [%s]") % entity.userhost())
222 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) 248 contact = self.host.memory.getContact(entity, self.parent.profile)
223 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile) 249 if contact and contact[0]['to'] == 'True':
250 #We automatically accept subscription if we are already subscribed to contact presence
251 debug(_('sending automatic subscription acceptance'))
252 self.subscribed(entity)
253 else:
254 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile)
255 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile)
224 256
225 def unsubscribeReceived(self, entity): 257 def unsubscribeReceived(self, entity):
226 debug (_("unsubscription asked for [%s]") % entity.userhost()) 258 debug (_("unsubscription asked for [%s]") % entity.userhost())
227 self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile) 259 contact = self.host.memory.getContact(entity, self.parent.profile)
260 if contact and contact[0]['from'] == 'True': #we automatically remove contact
261 debug(_('automatic contact deletion'))
262 self.host.delContact(entity.userhost(), self.parent.profile)
228 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile) 263 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile)
229 264
230 class SatDiscoProtocol(disco.DiscoClientProtocol): 265 class SatDiscoProtocol(disco.DiscoClientProtocol):
231 def __init__(self, host): 266 def __init__(self, host):
232 disco.DiscoClientProtocol.__init__(self) 267 disco.DiscoClientProtocol.__init__(self)