summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sunshine/channel/contact_list.py80
-rw-r--r--sunshine/channel/group.py2
-rw-r--r--sunshine/channel/text.py4
3 files changed, 67 insertions, 19 deletions
diff --git a/sunshine/channel/contact_list.py b/sunshine/channel/contact_list.py
index 4d3f0f5..d23777f 100644
--- a/sunshine/channel/contact_list.py
+++ b/sunshine/channel/contact_list.py
@@ -101,22 +101,21 @@ def SunshineContactListChannelFactory(connection, manager, handle, props):
props[telepathy.CHANNEL_INTERFACE + '.TargetHandleType'],
props[telepathy.CHANNEL_INTERFACE + '.TargetHandle'])
- if handle.get_name() == 'subscribe':
+ if handle.get_name() == 'stored':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'subscribe':
channel_class = SunshineSubscribeListChannel
- #hacky & tricky
-# elif handle.get_name() == 'publish':
-# channel_class = SunshineSubscribeListChannel
-
-# elif handle.get_name() == 'publish':
-# channel_class = ButterflyPublishListChannel
-# elif handle.get_name() == 'hide':
-# channel_class = ButterflyHideListChannel
-# elif handle.get_name() == 'allow':
-# channel_class = ButterflyAllowListChannel
-# elif handle.get_name() == 'deny':
-# channel_class = ButterflyDenyListChannel
+ elif handle.get_name() == 'publish':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'hide':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'allow':
+ raise telepathy.errors.NotImplemented
+ elif handle.get_name() == 'deny':
+ raise telepathy.errors.NotImplemented
else:
- raise TypeError("Unknown list type : " + handle.get_name())
+ logger.error("Unknown list type : " + handle.get_name())
+ raise telepathy.errors.InvalidHandle
return channel_class(connection, manager, props)
@@ -128,7 +127,7 @@ class SunshineListChannel(
def __init__(self, connection, manager, props, object_path=None):
self._conn_ref = weakref.ref(connection)
- telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props, object_path=None)
+ telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props, object_path=object_path)
SunshineChannel.__init__(self, connection, props)
telepathy.server.ChannelInterfaceGroup.__init__(self)
self._populate(connection)
@@ -173,13 +172,19 @@ class SunshineSubscribeListChannel(SunshineListChannel):
supposed to receive presence notification."""
def __init__(self, connection, manager, props):
- SunshineListChannel.__init__(self, connection, manager, props)
+ SunshineListChannel.__init__(self, connection, manager, props,
+ object_path='RosterChannel/List/subscribe')
self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD |
telepathy.CHANNEL_GROUP_FLAG_CAN_REMOVE, 0)
def AddMembers(self, contacts, message):
logger.info("Subscribe - AddMembers called")
for h in contacts:
+ self._add(h, message)
+
+
+ """
+ for h in contacts:
handle = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, h)
contact_xml = ET.Element("Contact")
ET.SubElement(contact_xml, "Guid").text = str(handle.name)
@@ -203,16 +208,59 @@ class SunshineSubscribeListChannel(SunshineListChannel):
self._conn_ref().contactAdded(handle)
logger.info("Contact added.")
self._conn_ref().exportContactsFile()
+ """
def RemoveMembers(self, contacts, message):
for h in contacts:
+ self._remove(h)
+
+ """
+ for h in contacts:
handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
contact = handle.contact
self._conn_ref().gadu_client.removeContact(contact, notify=True)
self.MembersChanged('', (), [handle], (), (), 0,
telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
self._conn_ref().exportContactsFile()
+ """
def _filter_contact(self, contact):
return (True, False, False)
+ def _add(self, handle_id, message):
+ handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id)
+ if handle.contact is not None:
+ return True
+
+ contact_xml = ET.Element("Contact")
+ ET.SubElement(contact_xml, "Guid").text = str(handle.name)
+ ET.SubElement(contact_xml, "GGNumber").text = str(handle.name)
+ ET.SubElement(contact_xml, "ShowName").text = str(handle.name)
+ ET.SubElement(contact_xml, "Groups")
+ c = GaduContact.from_xml(contact_xml)
+ self._conn_ref().gadu_client.addContact( c )
+ self._conn_ref().gadu_client.notifyAboutContact( c )
+ logger.info("Adding contact: %s" % (handle.name))
+ self.MembersChanged('', [handle], (), (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED)
+
+ #alias and group settings for new contacts are bit tricky
+ #try to set alias
+ handle.contact.ShowName = self._conn_ref().get_contact_alias(handle.id)
+ #and group
+ if self._conn_ref().pending_contacts_to_group.has_key(handle.name):
+ logger.info("Trying to add temporary group.")
+ handle.contact.updateGroups(self._conn_ref().pending_contacts_to_group[handle.name])
+ self._conn_ref().contactAdded(handle)
+ logger.info("Contact added.")
+ self._conn_ref().exportContactsFile()
+
+ def _remove(self, handle_id):
+ handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h)
+ contact = handle.contact
+ self._conn_ref().gadu_client.removeContact(contact, notify=True)
+ self.MembersChanged('', (), [handle], (), (), 0,
+ telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+ self._conn_ref().exportContactsFile()
+
+
diff --git a/sunshine/channel/group.py b/sunshine/channel/group.py
index 9c9fc20..ced603a 100644
--- a/sunshine/channel/group.py
+++ b/sunshine/channel/group.py
@@ -39,7 +39,7 @@ logger = logging.getLogger('Sunshine.GroupChannel')
class SunshineGroupChannel(SunshineListChannel):
- def __init__(self, connection, manager, props, object_path):
+ def __init__(self, connection, manager, props, object_path=None):
self.__pending_add = []
self.__pending_remove = []
self.conn = connection
diff --git a/sunshine/channel/text.py b/sunshine/channel/text.py
index 76a61b5..e21159f 100644
--- a/sunshine/channel/text.py
+++ b/sunshine/channel/text.py
@@ -41,7 +41,7 @@ class SunshineTextChannel(SunshineChannel,
telepathy.server.ChannelInterfaceChatState,
ChannelInterfaceMessages):
- def __init__(self, conn, manager, conversation, props, object_path):
+ def __init__(self, conn, manager, conversation, props, object_path=None):
_, surpress_handler, handle = manager._get_type_requested_handle(props)
self._recv_id = 0
self._conn_ref = weakref.ref(conn)
@@ -50,7 +50,7 @@ class SunshineTextChannel(SunshineChannel,
self._pending_messages2 = {}
self.handle = handle
- telepathy.server.ChannelTypeText.__init__(self, conn, manager, props, object_path)
+ telepathy.server.ChannelTypeText.__init__(self, conn, manager, props, object_path=object_path)
SunshineChannel.__init__(self, conn, props)
telepathy.server.ChannelInterfaceChatState.__init__(self)
ChannelInterfaceMessages.__init__(self)