# Path: tphangups/text_channel.py
# class HangupsTextChannel(telepathy.server.ChannelTypeText,
#         telepathy.server.ChannelInterfaceChatState):
# 
#     #TODO probably pass the conversation object from Hangups client
#     def __init__(self, conn, manager, props, object_path=None):
#         telepathy.server.ChannelTypeText.__init__(self, conn, manager, props,
#                     object_path=object_path)
# 
#         self._implement_property_get(telepathy.CHANNEL_INTERFACE_MESSAGES, {
#             'SupportedContentTypes': lambda: ["text/plain"] ,
#             'MessagePartSupportFlags': lambda: 0,
#             'DeliveryReportingSupport': lambda: telepathy.DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES,
#             'PendingMessages': lambda: dbus.Array(self._pending_messages.values(), signature='aa{sv}')
#             })
# 
#         self._add_immutables({
#             'SupportedContentTypes': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'MessagePartSupportFlags': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'DeliveryReportingSupport': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             })
# 
#     @dbus.service.method(telepathy.CHANNEL_TYPE_TEXT, in_signature='us', out_signature='',
#                          async_callbacks=('_success', '_error'))
#     def Send(self, message_type, text, _success, _error):
#         print ("NEW MESSAGE " + text)
#         self.Received(15, 34234234, 2, 0 , 0, "Hello!")


import telepathy
import dbus
import hangups
import asyncio #maybe want to use gobject event loop? depends on python+dbus
from .text_channel import HangupsTextChannel
from os.path import expanduser
        all_handles = []
        for (handle_type, handle) in self._handles.keys():
            if handle_type == telepathy.HANDLE_TYPE_CONTACT:
                all_handles.append(handle)
        return self.GetContactAttributes(all_handles, interfaces, hold)


    # from Aliasing
    def GetAliasFlags(self):
        return 0

    def GetAliases(self, handles):
        self.check_connected()
        ret = dbus.Dictionary(signature='us')
        for handle_id in handles:
            handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id)
            user = self._user_list.get_user(handle.name)
            ret[handle_id] = user.full_name
        return ret

class HangupsChannelManager(telepathy.server.ChannelManager):
    def __init__(self, connection, protocol):
        self._connection = connection
        self._protocol = protocol
        telepathy.server.ChannelManager.__init__(self, connection)
        self.set_requestable_channel_classes(protocol.requestable_channels)
        self.implement_channel_classes(telepathy.CHANNEL_TYPE_TEXT, self._get_text_channel)

    def _get_text_channel(self, props):
        print ("Making new text channel")

# Path: tphangups/text_channel.py
# class HangupsTextChannel(telepathy.server.ChannelTypeText,
#         telepathy.server.ChannelInterfaceChatState):
# 
#     #TODO probably pass the conversation object from Hangups client
#     def __init__(self, conn, manager, props, object_path=None):
#         telepathy.server.ChannelTypeText.__init__(self, conn, manager, props,
#                     object_path=object_path)
# 
#         self._implement_property_get(telepathy.CHANNEL_INTERFACE_MESSAGES, {
#             'SupportedContentTypes': lambda: ["text/plain"] ,
#             'MessagePartSupportFlags': lambda: 0,
#             'DeliveryReportingSupport': lambda: telepathy.DELIVERY_REPORTING_SUPPORT_FLAG_RECEIVE_FAILURES,
#             'PendingMessages': lambda: dbus.Array(self._pending_messages.values(), signature='aa{sv}')
#             })
# 
#         self._add_immutables({
#             'SupportedContentTypes': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'MessagePartSupportFlags': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             'DeliveryReportingSupport': telepathy.CHANNEL_INTERFACE_MESSAGES,
#             })
# 
#     @dbus.service.method(telepathy.CHANNEL_TYPE_TEXT, in_signature='us', out_signature='',
#                          async_callbacks=('_success', '_error'))
#     def Send(self, message_type, text, _success, _error):
#         print ("NEW MESSAGE " + text)
#         self.Received(15, 34234234, 2, 0 , 0, "Hello!")


# Path: tphangups/connection.py
import telepathy
import dbus
import hangups
import asyncio #maybe want to use gobject event loop? depends on python+dbus
from .text_channel import HangupsTextChannel
from os.path import expanduser

        all_handles = []
        for (handle_type, handle) in self._handles.keys():
            if handle_type == telepathy.HANDLE_TYPE_CONTACT:
                all_handles.append(handle)
        return self.GetContactAttributes(all_handles, interfaces, hold)


    # from Aliasing
    def GetAliasFlags(self):
        return 0

    def GetAliases(self, handles):
        self.check_connected()
        ret = dbus.Dictionary(signature='us')
        for handle_id in handles:
            handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id)
            user = self._user_list.get_user(handle.name)
            ret[handle_id] = user.full_name
        return ret

class HangupsChannelManager(telepathy.server.ChannelManager):
    def __init__(self, connection, protocol):
        self._connection = connection
        self._protocol = protocol
        telepathy.server.ChannelManager.__init__(self, connection)
        self.set_requestable_channel_classes(protocol.requestable_channels)
        self.implement_channel_classes(telepathy.CHANNEL_TYPE_TEXT, self._get_text_channel)

    def _get_text_channel(self, props):
        print ("Making new text channel")

        return HangupsTextChannel(self._connection, self._protocol, props)