From ab6d08c430bb8a8b7532d7539e47de496599cfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sat, 17 Jul 2010 17:33:48 -0300 Subject: [PATCH] Implement pending contact signal Currently there is no way to get notified if we got invited by some other user on the network. This patch implements a new signal, contact-pending, that might be used to get notified of pending contacts. This is really useful for things like automatic bots which should auto-accept this contacts, or IM desktop clients, which popup a dialog when somebody invites us. --- papyon/client.py | 1 + papyon/event/address_book.py | 3 +++ papyon/service/AddressBook/address_book.py | 14 +++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/papyon/client.py b/papyon/client.py index d91781b..b5904e1 100644 --- a/papyon/client.py +++ b/papyon/client.py @@ -465,6 +465,7 @@ class Client(EventsDispatcher): self.address_book.connect(name, event, name) connect_signal("contact-added") + connect_signal("contact-pending") connect_signal("contact-deleted") connect_signal("contact-blocked") connect_signal("contact-unblocked") diff --git a/papyon/event/address_book.py b/papyon/event/address_book.py index 7ff3555..a7e4eba 100644 --- a/papyon/event/address_book.py +++ b/papyon/event/address_book.py @@ -31,6 +31,9 @@ class AddressBookEventInterface(BaseEventInterface): def on_addressbook_contact_added(self, contact): pass + def on_addressbook_contact_pending(self, contact): + pass + def on_addressbook_contact_deleted(self, contact): pass diff --git a/papyon/service/AddressBook/address_book.py b/papyon/service/AddressBook/address_book.py index 241f7dd..e32e111 100644 --- a/papyon/service/AddressBook/address_book.py +++ b/papyon/service/AddressBook/address_book.py @@ -139,6 +139,10 @@ class AddressBook(gobject.GObject): gobject.TYPE_NONE, (object,)), + "contact-pending" : (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + (object,)), + "contact-deleted" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (object,)), @@ -265,10 +269,14 @@ class AddressBook(gobject.GObject): contact = profile.Contact(None, network_id, account, account) return contact - def check_pending_invitations(self): + def check_pending_invitations(self, done_cb=None, failed_cb=None): + def callback(memberships): + self.__update_memberships(memberships) + self.__common_callback('contact-pending', done_cb, + self.contacts.search_by_memberships(Membership.PENDING)) cp = scenario.CheckPendingInviteScenario(self._sharing, - (self.__update_memberships,), - (self.__common_errback, None)) + (callback,), + (self.__common_errback, failed_cb)) cp() def accept_contact_invitation(self, pending_contact, add_to_contact_list=True, -- 1.7.0.4