Esempio n. 1
0
    def share(cls, para):
        uid = para['uid']
        share_type = int(para['type'])

        share_gift = cls(uid)

        if not share_gift.hasFlag(share_type):
            return Error.INVALID_PARAM

        now = int(time.time())

        key = '%s:%s' % (uid, now)

        data = {
                'uid': uid,
                'time': now,
                'type': share_type,
                }

        item_type = cls.getIndexItemType()
        item_type(key).setAll(data)
        Redis().expire(key, cls.TTL)

        frd_list = Social.getFriendsUID(uid)

        for f in frd_list:
            box = cls(f)
            box.addKey(key)

            Notice(f).push({'type':Notice.TYPE_SHAREGIFT})

            n = box.size()
            if n > cls.MAX_SIZE:
                box.remove(n - cls.MAX_SIZE)

        # clear
        share_gift.clearFlag(share_type)

        return {}