Esempio n. 1
0
class LogicApplyFriend(object):
    def __init__(self):
        self.friend = Friend()
        self.im_friend = IMFriend()
        self.record_meet = RecordMeet()

    def apply_friend(self, user_id, friend_user_id, apply_id):
        """
        申请好友(只有见过面的人可以申请好友)
        只要不是好友/黑名单,就可以申请好友
        :param user_id: 用户ID
        :param friend_user_id: 另一用户ID
        :return:
        """
        if self.record_meet.is_met(apply_id):
            user_id = int(user_id)
            friend_user_id = int(friend_user_id)
            if self.friend.is_friend_or_black(user_id, friend_user_id):
                return Result.result_failed("you have been friends or blacks!")
            else:
                if self.friend.has_valid_apply(user_id, friend_user_id):
                    return Result.result_failed("you have a valid apply!")
                elif self.friend.has_valid_apply(friend_user_id, user_id):
                    apply = self.friend.get_apply_by_user_and_friend(
                        friend_user_id, user_id)
                    return self.friend.add_friend(friend_user_id, user_id,
                                                  apply.id)
                else:
                    friend = self.friend.get_friend_by_user_and_friend(
                        friend_user_id, user_id)
                    if not friend:
                        success = self.friend.add_apply(
                            user_id, friend_user_id)
                        if success:
                            self.im_friend.apply_friend(
                                user_id, friend_user_id, "")
                            log_string = "%d apply %d to be friend" % (
                                user_id, friend_user_id)
                            OHHOLog.print_log(log_string)
                            return Result.result_success()
                        else:
                            return Result.result_failed()
                    else:
                        self.friend.add_friend(user_id, friend_user_id,
                                               friend.apply_id)
                        return Result.result_success(
                            "add friend successfully!")
        else:
            return Result.result_failed("you are not met!")
Esempio n. 2
0
class LogicRefuseFriend(object):
    def __init__(self):
        # self.meet = Meet()
        self.friend = Friend()
        self.im_friend = IMFriend()

    def refuse_friend(self, user_id, friend_user_id):
        """
        拒绝添加好友
        用户已经申请,并且你们不是朋友/黑名单关系,可以拒绝
        :param user_id: 用户ID
        :param friend_user_id: 另一用户ID
        :return:
        """
        if self.friend.has_valid_apply(friend_user_id, user_id):
            apply = self.friend.get_apply_by_user_and_friend(
                friend_user_id, user_id)
            if apply:
                success = self.friend.add_refuse(apply.id, user_id)
                if success:
                    log_string = "%d refuse %d to be friend" % (user_id,
                                                                friend_user_id)
                    OHHOLog.print_log(log_string)
                    self.im_friend.refuse_friend(user_id, friend_user_id, "")
                    return Result.result_success()
                else:
                    return Result.result_failed()
            else:
                return Result.result_failed("no valid friend apply!")
        else:
            return Result.result_failed("no valid friend apply!")