Beispiel #1
0
 private static boolean hasHotFriendRight(int uid) {
   User user = null;
   try {
     user = SnsAdapterFactory.getUserAdapter().get(uid);
     threadLocalUser.set(user);
     return user.isStarUser();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
Beispiel #2
0
  /**
   * 发送好友申请接口
   *
   * <p>步骤: <br>
   * Step1:取相关的两个id的User对象<br>
   * Step2:判断spammer<br>
   * Step3:判断是否超过好友申请数限制<br>
   * Step4:隐私判断<br>
   * Step5:内容过antispam<br>
   * Step6:调用BuddyCore服务 addApply rpc method <br>
   * Step7:异步发webpager, email<br>
   *
   * @param friendApply
   * @return
   */
  @Override
  public FriendApplyResult addFriendApply(FriendApply friendApply) {
    // friend apply logic start...
    FriendApplyResult friendApplyResult = new FriendApplyResult();
    friendApplyResult.applicant = friendApply.applicant;
    friendApplyResult.accepter = friendApply.accepter;
    User applicantUser = null;
    User accepterUser = null;
    try {
      applicantUser = SnsAdapterFactory.getUserAdapter().get(friendApply.applicant);
      accepterUser = SnsAdapterFactory.getUserAdapter().get(friendApply.accepter);
    } catch (Exception e) {
      // TODO: Logger 一下
    }

    if (applicantUser == null || accepterUser == null) {
      friendApplyResult.result = Constants.NO_USER;
      return friendApplyResult;
    }

    /** 判断spammer开始 */
    if (applicantUser.getUserDangerInfo().isNotAcceptBuddyApplication()
        || accepterUser.getUserDangerInfo().isNotAcceptBuddyApplication()) {
      friendApplyResult.result = Constants.FAKE;
      return friendApplyResult;
    }

    if (applicantUser.getUserState().isApplySpammer()
        || accepterUser.getUserState().isApplySpammer()) {
      friendApplyResult.result = Constants.FAKE;
      return friendApplyResult;
    }
    /** 判断spammer结束 */

    /** 当天发送好友申请好限制 开始 */
    int todayAddApplyCount = 0;
    try {
      todayAddApplyCount =
          BuddyCountAdapter.getInstance()
              .get(applicantUser.getId(), Operation.AddFriendApply.value());
    } catch (Exception e) {
      // TODO: Logger 一下
    }
    if (todayAddApplyCount > TODAY_ADD_APPLY_MAX) {
      friendApplyResult.result = Constants.OPERATION_FULL;
      return friendApplyResult;
    }
    /** 当天发送好友申请好限制 结束 */

    /** 隐私判断 开始 */
    UserConfigInfo applicantUserConfig = null;
    UserConfigInfo accepterUserConfig = null;
    try {
      applicantUserConfig =
          SnsAdapterFactory.getUserConfigInfoAdapter().getUserConfig(friendApply.applicant);
      accepterUserConfig =
          SnsAdapterFactory.getUserConfigInfoAdapter().getUserConfig(friendApply.accepter);
    } catch (Exception e) {
      // TODO: Logger 一下
    }
    if (applicantUserConfig == null || accepterUserConfig == null) {
      friendApplyResult.result = Constants.INVALID_USER;
      return friendApplyResult;
    }

    Permission permission =
        PermissionFactory.getInstance().getPermissionByModule(Module.MODULE_REQUESTFRIEND);

    Status guester =
        new Status(
            applicantUser.getId(),
            applicantUser.getId(),
            applicantUser.getStage(),
            applicantUser.getUniv(),
            applicantUser.getAuth(),
            applicantUser.getStatus(),
            applicantUserConfig.getRequestFriendConfig());

    Status owner =
        new Status(
            accepterUser.getId(),
            accepterUser.getId(),
            accepterUser.getStage(),
            accepterUser.getUniv(),
            accepterUser.getAuth(),
            accepterUser.getStatus(),
            accepterUserConfig.getRequestFriendConfig());

    int path = RelationExpImpl.getInstance().getRelationPath(guester, owner);
    guester.setFromToPath(path);
    // 由于隐私系统需要,所以只能调用user服务的过期方法!!!
    guester.setSelected(applicantUser.getSelected());
    Ret ret = permission.hasInsert(guester, owner);
    if (!ret.hasRight()) {
      friendApplyResult.result = Constants.OPERATION_PROHIBITION;
      return friendApplyResult;
    }
    /** 隐私判断 结束 */

    // 处理一下content长度
    String why = friendApply.content;
    if (why != null) {
      why = (why.length() < 45) ? why : "";
      friendApply.content = why;
    } else {
      friendApply.content = "";
    }

    // 处理一下是否包含url
    if (Security.haveURL(friendApply.content)) {
      friendApplyResult.result = Constants.INVALID_CONTENT;
      return friendApplyResult;
    }

    /** antispam 开始 */
    CheckResult cr =
        AntiSpamAdapter.getInstance()
            .checkAndFilter(
                applicantUser.getId(), CheckType.FRIEND_APPLICATION_TYPE, friendApply.content, "");
    int m_type = cr.getFlag();
    switch (m_type) {
      case CheckResult.CONTENT_NEED_AUDIT:
        friendApply.content = cr.getSafePureContent();
        break;
      case CheckResult.SAFE:
        friendApply.content = cr.getSafePureContent();
        break;
      case CheckResult.SYSTEM_ERROR:
        friendApply.content = cr.getSafePureContent();
        break;
      case CheckResult.PROHIBITED:
        friendApply.content = cr.getSafePureContent();
        friendApplyResult.result = Constants.FAKE;
        return friendApplyResult;
      default:
        break;
    }
    /** antispam 结束 */

    // 条件都走过了,下面可以真正发了
    /** 调用BuddyCore服务 开始 */
    BuddyApplyWithInfo buddyApply =
        new BuddyApplyWithInfo(friendApply.applicant, friendApply.accepter);
    buddyApply.setTime(new Date(friendApply.timestamp));
    buddyApply.setStatFrom(friendApply.from);
    buddyApply.setGroupName("");
    buddyApply.setWhy(friendApply.content);
    try {
      AdapterFactory.getBuddyCoreAdapter().addApply(buddyApply, buddyApply.getStatFrom());
      friendApplyResult.result = Constants.SUCCESS_ADD_FRIEND_APPLY;
    } catch (Exception e) {
      // TODO: Logger 一下
    }
    /** 调用BuddyCore服务 结束 */

    /** 千万别忘记了当天发好友申请数加1 */
    try {
      BuddyCountAdapter.getInstance()
          .inc(applicantUser.getId(), Operation.AddFriendApply.value(), 1);
    } catch (Exception e) {
      // TODO: Logger 一下
    }

    // 异步发信通知
    threadPool.execute(new AddFriendApplyMessage(applicantUser, accepterUser, friendApply));

    return friendApplyResult;
  }
Beispiel #3
0
  /**
   * 接受好友申请接口 <br>
   * 步骤: <br>
   * Step1:取相关的两个id的User对象<br>
   * Step2:判断spammer<br>
   * Step3:判断双方的好友数<br>
   * Step4:调用BuddyCore服务 addFriend rpc method <br>
   * Step5:异步发通知,email<br>
   *
   * @param friendApply
   * @return
   */
  @Override
  public FriendApplyResult acceptFriendApply(FriendApply friendApply) {
    FriendApplyResult friendApplyResult = new FriendApplyResult();
    friendApplyResult.applicant = friendApply.applicant;
    friendApplyResult.accepter = friendApply.accepter;
    User applicantUser = null;
    User accepterUser = null;
    try {
      applicantUser = SnsAdapterFactory.getUserAdapter().get(friendApply.applicant);
      accepterUser = SnsAdapterFactory.getUserAdapter().get(friendApply.accepter);
    } catch (Exception e) {
      // TODO: Logger 一下
    }

    if (applicantUser == null || accepterUser == null) {
      friendApplyResult.result = Constants.NO_USER;
      return friendApplyResult;
    }

    /** 判断spammer开始 */
    if (applicantUser.getUserDangerInfo().isNotAcceptBuddyApplication()
        || accepterUser.getUserDangerInfo().isNotAcceptBuddyApplication()) {
      friendApplyResult.result = Constants.FAKE;
      // 删除此条好友申请
      BuddyApply buddyApply = new BuddyApply(applicantUser.getId(), accepterUser.getId());
      try {
        SnsAdapterFactory.getBuddyCoreAdapter().denyApply(buddyApply);
      } catch (Exception e) {
        // TODO: Logger 一下
      }

      return friendApplyResult;
    }
    /** 判断spammer结束 */

    /** 判断双方的好友数 开始 */
    boolean applicantReachFlag = reachMaxFriendCount(applicantUser);
    if (!applicantReachFlag) {
      friendApplyResult.result = Constants.APPLICANT_FRIEND_LIST_FULL;
      return friendApplyResult;
    }
    boolean recipientReachFlag = reachMaxFriendCount(accepterUser);
    if (!recipientReachFlag) {
      friendApplyResult.result = Constants.ACCEPTER_FRIEND_LIST_FULL;
      return friendApplyResult;
    }
    /** 判断双方的好友数 结束 */

    /** 调用BuddyCore服务 开始 */
    try {
      BuddyApply buddyApply = new BuddyApply(applicantUser.getId(), accepterUser.getId());
      SnsAdapterFactory.getBuddyCoreAdapter().acceptApply(buddyApply);
      friendApplyResult.result = Constants.SUCCESS_ACCEPT_FRIEND_APPLY;
    } catch (Exception e) {
      // TODO: Logger 一下
    }
    /** 调用BuddyCore服务 结束 */

    // 异步发通知,email
    threadPool.execute(new AddFriendMessage(applicantUser, accepterUser, friendApply));

    return friendApplyResult;
  }