[Telepathy] Some SimplePresence problems.

Krzysztof Klinikowski kkszysiu at gmail.com
Sat Jul 4 03:57:46 PDT 2009


Hello.
Im writting new CM to Tlen.pl network. It basing generally on
telepathy-butterfly CM. Code from butterfly looks like:

   # SimplePresence

   def GetPresences(self, contacts):
       return self.get_simple_presences(contacts)

   def SetPresence(self, status, message):
       if status == ButterflyPresenceMapping.OFFLINE:
           self.Disconnect()

       try:
           presence = ButterflyPresenceMapping.to_papyon[status]
       except KeyError:
           raise telepathy.errors.InvalidArgument
       message = message.encode("utf-8")

       logger.info("Setting Presence to '%s'" % presence)
       logger.info("Setting Personal message to '%s'" % message)

       if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
           self._initial_presence = presence
           self._initial_personal_message = message
       else:
           self.msn_client.profile.personal_message = message
           self.msn_client.profile.presence = presence

   def get_simple_presences(self, contacts):
       presences = {}
       for handle_id in contacts:
           handle = self.handle(telepathy.HANDLE_TYPE_CONTACT,
handle_id)
           try:
               contact = handle.contact
           except AttributeError:
               contact = handle.profile

           if contact is not None:
               presence =
ButterflyPresenceMapping.to_telepathy[contact.presence]
               personal_message = unicode(contact.personal_message,
"utf-8")
           else:
               presence = ButterflyPresenceMapping.OFFLINE
               personal_message = u""

           presence_type =
ButterflyPresenceMapping.to_presence_type[presence]

           presences[handle] = (presence_type, presence,
personal_message)
       return presences

   def get_statuses(self):
       # you get one of these for each status
       # {name:(Type, May_Set_On_Self, Can_Have_Message}
       return {
           ButterflyPresenceMapping.ONLINE:(
               telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
               True, True),
           ButterflyPresenceMapping.AWAY:(
               telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
               True, True),
           ButterflyPresenceMapping.BUSY:(
               telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
               True, True),
           ButterflyPresenceMapping.IDLE:(
               telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
               True, True),
           ButterflyPresenceMapping.BRB:(
               telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
               True, True),
           ButterflyPresenceMapping.PHONE:(
               telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
               True, True),
           ButterflyPresenceMapping.LUNCH:(
               telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
               True, True),
           ButterflyPresenceMapping.INVISIBLE:(
               telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
               True, False),
           ButterflyPresenceMapping.OFFLINE:(
               telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
               True, False)
       }

thats my code:

   def GetPresences(self, contacts):
       """Returns the presence of the given contacts.

       Arguments:
       contacts -- iterable of contacts whose presence is requested

       Returns:
       presences -- complex list of structs containing the presences

       Exceptions:
       org.freedesktop.Telepathy.Error.Disconnected
       org.freedesktop.Telepathy.Error.InvalidArgument
       org.freedesktop.Telepathy.Error.InvalidHandle
       org.freedesktop.Telepathy.Error.NetworkError
       org.freedesktop.Telepathy.Error.NotAvailable
       """
       presences = {}
       for handle_id in contacts:
           self.check_handle (tp.constants.HANDLE_TYPE_CONTACT,
handle_id)

           handle_obj = self._handles[tp.constants.HANDLE_TYPE_CONTACT,
                                      handle_id]
           presences[handle_id] = handle_obj.get_simple_presence()

       return presences

   def SetPresence(self, status, message):
       if status == 'unavailable':
           self.Disconnect()

       try:
           presence = status
       except KeyError:
           raise telepathy.errors.InvalidArgument
       message = message.encode("utf-8")

       print ("Presence Status is '%s'" % status)
       print ("Setting Presence to '%s'" % presence)
       print ("Setting Personal message to '%s'" % message)

       #if self._status != telepathy.CONNECTION_STATUS_CONNECTED:
       #    self._initial_presence = presence
       #    self._initial_personal_message = message
       #else:
       #    pass
           #self.msn_client.profile.personal_message = message
           #self.msn_client.profile.presence = presence

   def get_statuses(self):
       # you get one of these for each status
       # {name:(Type, May_Set_On_Self, Can_Have_Message}
       print 'get_statuses
'+str(telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE)
       return {
           'available':(
               telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
               True, True),
           'chat':(
               telepathy.CONNECTION_PRESENCE_TYPE_AVAILABLE,
               True, True),
           'dnd':(
               telepathy.CONNECTION_PRESENCE_TYPE_BUSY,
               True, True),
           'away':(
               telepathy.CONNECTION_PRESENCE_TYPE_AWAY,
               True, True),
           'xa':(
               telepathy.CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY,
               True, True),
           'invisible':(
               telepathy.CONNECTION_PRESENCE_TYPE_HIDDEN,
               True, True),
           'unavailable':(
               telepathy.CONNECTION_PRESENCE_TYPE_OFFLINE,
               True, True)
       }

and heres my CM:
http://github.com/kkszysiu/telepathy-tlen/tree/master
Everyone can run it because it have defind parameters for Tlen.pl
network.
I see statuses like "chat" etc in telepathy-inspector but all types
for that statuses = 0. Just look:
http://files.getdropbox.com/u/161361/telepathy/zrzut_ekranu-1.png

If you have some time then look at it, please. And sorry for my
English. Im still learning it.

Best regards, Krzysiek.



More information about the telepathy mailing list