from __future__ import nested_scopes
+import twistfix
+twistfix.main()
+
# Sibling imports
from twisted.protocols.basic import LineReceiver
from twisted.web.http import HTTPClient
Used to represent a MSNObject. This can be currently only be an avatar.
@ivar creator: The userHandle of the creator of this picture.
- @ivar imageData: The PNG image data (only for our own avatar)
+ @ivar imageDataFunc: A function to return the PNG image data (only for our own avatar)
@ivar type: Always set to 3, for avatar.
@ivar size: The size of the image.
@ivar location: The filename of the image.
if s:
self.parse(s)
- def setData(self, creator, imageData):
+ def setData(self, creator, imageDataFunc):
""" Set the creator and imageData for this object """
+ imageData = imageDataFunc()
self.creator = creator
- self.imageData = imageData
+ self.imageDataFunc = imageDataFunc
self.size = len(imageData)
self.type = 3
self.location = "TMP" + str(random.randint(1000,9999))
def setNull(self):
self.creator = ""
- self.imageData = ""
+ self.imageDataFunc = lambda: None
self.size = 0
self.type = 0
self.location = ""
return (personal,)
return d.addCallback(_cb)
- def changeAvatar(self, imageData, push):
+ def changeAvatar(self, imageDataFunc, push):
"""
Used to change the avatar that other users see.
- @param imageData: the PNG image data to set as the avatar
+ @param imageDataFunc: a function to return the PNG image data to set as the avatar
@param push : whether to push the update to the server
(it will otherwise be sent with the next
changeStatus())
The callback argument will be the same as for changeStatus.
"""
- if self.msnobj and imageData == self.msnobj.imageData: return
- if imageData:
- self.msnobj.setData(self.factory.userHandle, imageData)
+ checkMsnobj = MSNObject()
+ checkMsnobj.setData(self.factory.userHandle, imageDataFunc)
+ if self.msnobj and self.msnobj.sha1d == checkMsnobj.sha1d:
+ return # Avatar hasn't changed
+ if imageDataFunc:
+ # We need to keep the same MSNObject instance, as it is
+ # passed on to SwitchboardClient objects
+ self.msnobj.setData(self.factory.userHandle, imageDataFunc)
else:
self.msnobj.setNull()
- if push: return self.changeStatus(self.factory.status) # Push to server
+ if push:
+ return self.changeStatus(self.factory.status) # Push to server
def requestSwitchboardServer(self):
# Check that we have an avatar to send
if self.msnobj:
slpLink = SLPLink_AvatarSend(remoteUser=slpMessage.fro, switchboard=self, filesize=self.msnobj.size, sessionID=slpMessage.sessionID, sessionGuid=slpMessage.sessionGuid)
- slpLink.write(self.msnobj.imageData)
+ slpLink.write(self.msnobj.imageDataFunc())
slpLink.close()
else:
# They shouldn't have sent a request if we have