示例#1
0
 /**
  * 删除好友 步骤:<br>
  * Step1:删除所有关系<br>
  * Step2:当天删除好友操作计数加1<br>
  * Step3:异步操作<br>
  *
  * @param host
  * @param guest
  * @return
  */
 @Override
 public int deleteFriend(int host, int guest) {
   // 删除所有关系
   delAllFriendRelation(host, guest);
   try {
     // 当天删除好友操作计数加1
     BuddyCountAdapter.getInstance().inc(host, Operation.DeleteFriend.value(), 1);
   } catch (Exception e) {
     e.printStackTrace();
   }
   try {
     threadPool.execute(new DelFriendMessage(host, guest));
   } catch (Exception e) {
     e.printStackTrace();
   }
   return Constants.SUCCESS;
 }
示例#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;
  }