Ejemplo n.º 1
0
    def handle_icon_push(self, user, request):
        """ This is called when is received. Save the icon image. """

        validator = {'icon': str,
                     'iconid': str,
                     'version': lambda i: is_unsigned_int('version', i)
                    }
        if not validate(validator, request):
            return None

        icon = request['icon']
        iconid = request['iconid']

        if iconid == 'user':
            if user.get('faceversion') != request['version']:
                # This is an outdated version of the icon..
                return None
            if icon == '':
                # if we got an empty string, user removed the icon
                # giving None to save_face removes the picture
                delete_face(user)
            elif not save_face(user, icon):
                warning('Could not save face for %s: %d bytes\n' % (user.tag(), len(icon)))
                return None
            user.set('myfaceversion', request['version'])
            self.announce_user_change(user, what=(PROFILE_ICON_CHANGED, None))

        elif iconid.startswith('c:'):
            cname = iconid[2:]
            if cname == DEFAULT_COMMUNITY_NAME:
                return None
            com = self.get_ordinary_community(cname)
            if com == None:
                return None
            if com.get('iconversion') != request['version']:
                # This is an outdated version of the icon..
                return None
            if com.get('iconlocked'):
                return None
            if icon == '':
                delete_community_icon(com)
            elif not save_community_icon(com, icon):
                warning('Failed to update community icon: %s\n' % cname)
                return None
            com.set('myiconversion', request['version'])
            self.announce_community_change(com)
        return None
Ejemplo n.º 2
0
    def set_my_face(self, face_fname):
        """ Set new profile picture for given user. Should be myself! """

        if not face_fname:
            delete_face(self.myself)
        else:
            face = read_file_contents(face_fname)
            if face == None:
                warning('Can not set user face from %s\n' % face_fname)
                return False
            if not save_face(self.myself, face):
                warning('Could not save user face from %s\n' % face_fname)
                return False

        if self.myself.get('faceversion') == None:
            self.myself.set('faceversion', 0)
        else:
            self.myself.set('faceversion', self.myself.get('faceversion') + 1)

        self.announce_user_change(self.myself, allowme=True)
        return True