Mercurial > libervia-backend
comparison sat.tac @ 63:0db25931b60d
SàT: multi-profiles: somes fixes in core
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 29 Jan 2010 14:17:15 +1100 |
parents | 93cb45a7420f |
children | d46f849664aa |
comparison
equal
deleted
inserted
replaced
62:93cb45a7420f | 63:0db25931b60d |
---|---|
411 if isinstance(plugin[1], XMPPHandler): | 411 if isinstance(plugin[1], XMPPHandler): |
412 plugin[1].setHandlerParent(current) | 412 plugin[1].setHandlerParent(current) |
413 | 413 |
414 current.startService() | 414 current.startService() |
415 | 415 |
416 def disconnect(self): | 416 def disconnect(self, profile_key='@DEFAULT@'): |
417 """disconnect from jabber server""" | 417 """disconnect from jabber server""" |
418 if (not self.isConnected()): | 418 if (not self.isConnected(profile_key)): |
419 info("not connected !") | 419 info("not connected !") |
420 return | 420 return |
421 profile = self.memory.getProfileName(profile_key) | |
421 info("Disconnecting...") | 422 info("Disconnecting...") |
422 self.xmppclient.stopService() | 423 self.profiles[profile].stopService() |
423 | 424 |
424 def startService(self): | 425 def startService(self): |
425 info("Salut à toi ô mon frère !") | 426 info("Salut à toi ô mon frère !") |
426 self.connect() | 427 self.connect() |
427 | 428 |
509 deferred = iq.send(target) | 510 deferred = iq.send(target) |
510 return (iq['id'], deferred) | 511 return (iq['id'], deferred) |
511 | 512 |
512 ## Client management ## | 513 ## Client management ## |
513 | 514 |
514 def setParam(self, name, value, category): | 515 def setParam(self, name, value, category, profile_key='@DEFAULT@'): |
515 """set wanted paramater and notice observers""" | 516 """set wanted paramater and notice observers""" |
516 info ("setting param: %s=%s in category %s", name, value, category) | 517 info ("setting param: %s=%s in category %s", name, value, category) |
517 self.memory.setParam(name, value, category) | 518 self.memory.setParam(name, value, category, profile_key) |
518 | 519 |
519 def isConnected(self, profile_key='@DEFAULT@'): | 520 def isConnected(self, profile_key='@DEFAULT@'): |
520 """Return connection status of profile | 521 """Return connection status of profile |
521 @param profile_key: key_word or profile name to determine profile name | 522 @param profile_key: key_word or profile name to determine profile name |
522 @return True if connected | 523 @return True if connected |
566 self.profiles[profile].xmlstream.send(message) | 567 self.profiles[profile].xmlstream.send(message) |
567 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg)) | 568 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg)) |
568 self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it | 569 self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it |
569 | 570 |
570 | 571 |
571 def setPresence(self, to="", show="", priority = 0, statuses={}): | 572 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'): |
572 """Send our presence information""" | 573 """Send our presence information""" |
574 profile = self.memory.getProfileName(profile_key) | |
575 assert(profile) | |
573 to_jid = jid.JID(to) if to else None | 576 to_jid = jid.JID(to) if to else None |
574 self.presence.available(to_jid, show, statuses, priority) | 577 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
575 | 578 |
576 def subscription(self, type, raw_jid): | 579 def subscription(self, type, raw_jid, profile_key='@DEFAULT@'): |
577 """Called to manage subscription""" | 580 """Called to manage subscription""" |
581 profile = self.memory.getProfileName(profile_key) | |
582 assert(profile) | |
578 to_jid = jid.JID(raw_jid) | 583 to_jid = jid.JID(raw_jid) |
579 debug ('subsciption request [%s] for %s', type, to_jid.full()) | 584 debug ('subsciption request [%s] for %s', type, to_jid.full()) |
580 if type=="subscribe": | 585 if type=="subscribe": |
581 self.presence.subscribe(to_jid) | 586 self.profiles[profile].presence.subscribe(to_jid) |
582 elif type=="subscribed": | 587 elif type=="subscribed": |
583 self.presence.subscribed(to_jid) | 588 self.profiles[profile].subscribed(to_jid) |
584 contact = self.memory.getContact(to_jid) | 589 contact = self.memory.getContact(to_jid) |
585 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence | 590 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence |
586 debug('sending automatic "to" subscription request') | 591 debug('sending automatic "to" subscription request') |
587 self.subscription('subscribe', to_jid.userhost()) | 592 self.subscription('subscribe', to_jid.userhost()) |
588 elif type=="unsubscribe": | 593 elif type=="unsubscribe": |
589 self.presence.unsubscribe(to_jid) | 594 self.profiles[profile].presence.unsubscribe(to_jid) |
590 elif type=="unsubscribed": | 595 elif type=="unsubscribed": |
591 self.presence.unsubscribed(to_jid) | 596 self.profiles[profile].presence.unsubscribed(to_jid) |
592 | 597 |
593 | 598 |
594 def addContact(self, to): | 599 def addContact(self, to, profile_key='@DEFAULT@'): |
595 """Add a contact in roster list""" | 600 """Add a contact in roster list""" |
601 profile = self.memory.getProfileName(profile_key) | |
602 assert(profile) | |
596 to_jid=jid.JID(to) | 603 to_jid=jid.JID(to) |
597 self.roster.addItem(to_jid) | 604 self.profiles[profile].roster.addItem(to_jid) |
598 self.presence.subscribe(to_jid) | 605 self.profiles[profile].presence.subscribe(to_jid) |
599 | 606 |
600 def delContact(self, to): | 607 def delContact(self, to, profile_key='@DEFAULT@'): |
601 """Remove contact from roster list""" | 608 """Remove contact from roster list""" |
609 profile = self.memory.getProfileName(profile_key) | |
610 assert(profile) | |
602 to_jid=jid.JID(to) | 611 to_jid=jid.JID(to) |
603 self.roster.removeItem(to_jid) | 612 self.profiles[profile].roster.removeItem(to_jid) |
604 self.presence.unsubscribe(to_jid) | 613 self.profiles[profile].presence.unsubscribe(to_jid) |
605 self.bridge.contactDeleted(to) | 614 self.profiles[profile].bridge.contactDeleted(to) |
606 | 615 |
607 | 616 |
608 ## callbacks ## | 617 ## callbacks ## |
609 | 618 |
610 def serverDisco(self, disco): | 619 def serverDisco(self, disco): |