PS fixes; use correct type on public keys and hide invalid buddies

This commit is contained in:
Dan Williams 2007-04-10 10:59:35 -04:00
parent c9310c2220
commit 48cab08b33
4 changed files with 21 additions and 17 deletions

View File

@ -13,6 +13,7 @@ sugar_PYTHON = \
buddyiconcache.py \ buddyiconcache.py \
linklocal_plugin.py \ linklocal_plugin.py \
presenceservice.py \ presenceservice.py \
psutils.py \
server_plugin.py server_plugin.py
bin_SCRIPTS = sugar-presence-service bin_SCRIPTS = sugar-presence-service

View File

@ -170,7 +170,10 @@ class Buddy(DBusGObject):
props['owner'] = self.props.owner props['owner'] = self.props.owner
props['key'] = self.props.key props['key'] = self.props.key
props['color'] = self.props.color props['color'] = self.props.color
props['current-activity'] = self.props.current_activity if self.props.current_activity:
props['current-activity'] = self.props.current_activity
else:
props['current-activity'] = ""
return props return props
# methods # methods

View File

@ -89,8 +89,7 @@ class PresenceService(dbus.service.Object):
def _contact_online(self, tp, handle, props): def _contact_online(self, tp, handle, props):
new_buddy = False new_buddy = False
key = props['key'] buddy = self._buddies.get(props["key"])
buddy = self._buddies.get(key)
if not buddy: if not buddy:
# we don't know yet this buddy # we don't know yet this buddy
objid = self._get_next_object_id() objid = self._get_next_object_id()
@ -253,26 +252,33 @@ class PresenceService(dbus.service.Object):
def GetActivities(self): def GetActivities(self):
ret = [] ret = []
for act in self._activities.values(): for act in self._activities.values():
ret.append(act.object_path()) if act.props.valid:
ret.append(act.object_path())
return ret return ret
@dbus.service.method(_PRESENCE_INTERFACE, in_signature="s", out_signature="o") @dbus.service.method(_PRESENCE_INTERFACE, in_signature="s", out_signature="o")
def GetActivityById(self, actid): def GetActivityById(self, actid):
if self._activities.has_key(actid): if self._activities.has_key(actid):
return self._activities[actid].object_path() act = self._activities[actid]
if act.props.valid:
return act.object_path()
raise NotFoundError("The activity was not found.") raise NotFoundError("The activity was not found.")
@dbus.service.method(_PRESENCE_INTERFACE, out_signature="ao") @dbus.service.method(_PRESENCE_INTERFACE, out_signature="ao")
def GetBuddies(self): def GetBuddies(self):
ret = [] ret = []
for buddy in self._buddies.values(): for buddy in self._buddies.values():
ret.append(buddy.object_path()) if buddy.props.valid:
ret.append(buddy.object_path())
return ret return ret
@dbus.service.method(_PRESENCE_INTERFACE, in_signature="ay", out_signature="o") @dbus.service.method(_PRESENCE_INTERFACE, in_signature="ay", out_signature="o")
def GetBuddyByPublicKey(self, key): def GetBuddyByPublicKey(self, key):
key = psutils.bytes_to_string(key)
if self._buddies.has_key(key): if self._buddies.has_key(key):
return self._buddies[key].object_path() buddy = self._buddies[key]
if buddy.props.valid:
return buddy.object_path()
raise NotFoundError("The buddy was not found.") raise NotFoundError("The buddy was not found.")
@dbus.service.method(_PRESENCE_INTERFACE, out_signature="o") @dbus.service.method(_PRESENCE_INTERFACE, out_signature="o")

View File

@ -25,6 +25,7 @@ from buddyiconcache import BuddyIconCache
import logging import logging
import os import os
import hashlib import hashlib
import psutils
from telepathy.client import ConnectionManager, ManagerRegistry, Connection, Channel from telepathy.client import ConnectionManager, ManagerRegistry, Connection, Channel
from telepathy.interfaces import ( from telepathy.interfaces import (
@ -304,7 +305,7 @@ class ServerPlugin(gobject.GObject):
# Set our OLPC buddy properties # Set our OLPC buddy properties
props = {} props = {}
props['color'] = self._owner.props.color props['color'] = self._owner.props.color
props['key'] = self._owner.props.key props['key'] = dbus.ByteArray(self._owner.props.key)
try: try:
self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props) self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props)
except dbus.DBusException, e: except dbus.DBusException, e:
@ -405,15 +406,8 @@ class ServerPlugin(gobject.GObject):
if not props.has_key('key'): if not props.has_key('key'):
raise InvalidBuddyError("no key") raise InvalidBuddyError("no key")
# Convert from D-Bus array types to a standard python byte array # Convert key from dbus byte array to python string
key = "" props["key"] = psutils.bytes_to_string(props["key"])
for item in props["key"]:
try:
# int type
key = key + "%s" % chr(item)
except TypeError:
# string type
key = key + str(item)
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0] jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0]
nick = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0] nick = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0]