import handle
-USER_ALIAS_ACCOUNT = "account"
-USER_ALIAS_CALLBACK = "callback"
-
-USER_ALIAS = USER_ALIAS_ACCOUNT
-
-
_moduleLogger = logging.getLogger('aliasing')
class AliasingMixin(telepathy.server.ConnectionInterfaceAliasing):
+ USER_ALIAS_ACCOUNT = "account"
+ USER_ALIAS_CALLBACK = "callback"
+
def __init__(self):
telepathy.server.ConnectionInterfaceAliasing.__init__(self)
"""
raise NotImplementedError("Abstract property called")
+ @property
+ def userAliasType(self):
+ """
+ @abstract
+ """
+ raise NotImplementedError("Abstract property called")
+
def handle(self, handleType, handleId):
"""
@abstract
@gtk_toolbox.log_exception(_moduleLogger)
def SetAliases(self, aliases):
_moduleLogger.debug("Called SetAliases")
- if USER_ALIAS == USER_ALIAS_ACCOUNT:
+ if self.userAliasType == self.USER_ALIAS_ACCOUNT:
raise telepathy.errors.PermissionDenied("No user customizable aliases")
- elif USER_ALIAS != USER_ALIAS_CALLBACK:
- raise RuntimeError("Invalid alias type: %r" % USER_ALIAS)
+ elif self.userAliasType != self.USER_ALIAS_CALLBACK:
+ raise RuntimeError("Invalid alias type: %r" % self.userAliasType)
# first validate that no other handle types are included
userHandleAndAlias = None
def _get_alias(self, handleId):
h = self.handle(telepathy.HANDLE_TYPE_CONTACT, handleId)
if isinstance(h, handle.ConnectionHandle):
- if USER_ALIAS == USER_ALIAS_CALLBACK:
+ if self.userAliasType == self.USER_ALIAS_CALLBACK:
aliasNumber = self.session.backend.get_callback_number()
- elif USER_ALIAS == USER_ALIAS_ACCOUNT:
+ elif self.userAliasType == self.USER_ALIAS_ACCOUNT:
aliasNumber = self.session.backend.get_account_number()
else:
- raise RuntimeError("Invalid alias type: %r" % USER_ALIAS)
+ raise RuntimeError("Invalid alias type: %r" % self.userAliasType)
userAlias = make_pretty(aliasNumber)
return userAlias
else:
def username(self):
return self._credentials[0]
+ @property
+ def userAliasType(self):
+ return self.USER_ALIAS_ACCOUNT
+
def handle(self, handleType, handleId):
self.check_handle(handleType, handleId)
return self._handles[handleType, handleId]
handles = []
for name in names:
- name = name.encode('utf-8')
+ requestedHandleName = name.encode('utf-8')
if handleType == telepathy.HANDLE_TYPE_CONTACT:
- _moduleLogger.info("RequestHandles Contact: %s" % name)
- h = self._create_contact_handle(name)
+ _moduleLogger.info("RequestHandles Contact: %s" % requestedHandleName)
+ requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
+ requestedHandleName
+ )
+ h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
elif handleType == telepathy.HANDLE_TYPE_LIST:
# Support only server side (immutable) lists
- _moduleLogger.info("RequestHandles List: %s" % name)
- h = handle.create_handle(self, 'list', name)
+ _moduleLogger.info("RequestHandles List: %s" % requestedHandleName)
+ h = handle.create_handle(self, 'list', requestedHandleName)
else:
raise telepathy.errors.NotAvailable('Handle type unsupported %d' % handleType)
handles.append(h.id)
self.add_client_handle(h, sender)
return handles
- def _create_contact_handle(self, requestedHandleName):
- requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
- requestedHandleName
- )
- h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
- return h
+ def _generate_props(self, channelType, handle, suppressHandler, initiatorHandle=None):
+ targetHandle = 0 if handle is None else handle.get_id()
+ targetHandleType = telepathy.HANDLE_TYPE_NONE if handle is None else handle.get_type()
+ props = {
+ telepathy.CHANNEL_INTERFACE + '.ChannelType': channelType,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandle': targetHandle,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandleType': targetHandleType,
+ telepathy.CHANNEL_INTERFACE + '.Requested': suppressHandler
+ }
+
+ if initiatorHandle is not None:
+ props[telepathy.CHANNEL_INTERFACE + '.InitiatorHandle'] = initiatorHandle.id
+
+ return props
@gobject_utils.async
@gtk_toolbox.log_exception(_moduleLogger)