Example #1
0
 /**
  * 忽略所有好友申请
  *
  * @param host
  * @return
  */
 @Override
 public int denyAllFriendApply(int host) {
   try {
     SnsAdapterFactory.getBuddyCoreAdapter().denyAllApply(host);
     return Constants.SUCCESS;
   } catch (Exception e) {
     // TODO: Logger
   }
   return Constants.ERROR;
 }
Example #2
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;
 }
Example #3
0
 /**
  * 忽略好友申请
  *
  * @param fa
  * @return
  */
 @Override
 public int denyFriendApply(FriendApply fa) {
   try {
     BuddyApply buddyApply = new BuddyApply(fa.applicant, fa.accepter);
     SnsAdapterFactory.getBuddyCoreAdapter().denyApply(buddyApply);
     return Constants.SUCCESS;
   } catch (Exception e) {
     // TODO: Logger
   }
   return Constants.ERROR;
 }
Example #4
0
 /**
  * 移出黑名单
  *
  * @param host
  * @param guest
  * @return
  */
 @Override
 public int removeBlock(int host, int guest) {
   try {
     BuddyBlock buddyBlock = new BuddyBlock(host, guest);
     SnsAdapterFactory.getBuddyCoreAdapter().removeBlock(buddyBlock);
     return Constants.SUCCESS;
   } catch (Exception e) {
     // TODO: Logger
   }
   return Constants.ERROR;
 }
Example #5
0
 /**
  * 加入黑名单<br>
  * 步骤:<br>
  * Step1:查看是否有权限加黑<br>
  * Step2:做加黑操作<br>
  * Step3:解除所有关系<br>
  * Step4:异步操作
  *
  * @param host
  * @param guest
  * @return
  */
 @Override
 public int addBlock(int host, int guest) {
   try {
     BuddyBlock buddyBlock = new BuddyBlock(host, guest);
     SnsAdapterFactory.getBuddyCoreAdapter().addBlock(buddyBlock);
     delAllFriendRelation(host, guest);
     threadPool.execute(new BlockMessage(host, guest));
     return Constants.SUCCESS;
   } catch (Exception e) {
     // TODO: Logger
   }
   return Constants.ERROR;
 }
Example #6
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;
  }
Example #7
0
  /**
   * 推荐好友接口实现<br>
   * matchmaker向targetUserId推荐recommendIdList,如果isOneWay为false,则为双向推荐
   * 前提,targetUserId和recommendIdList都是matchmaker好友
   */
  @Override
  public int recommendFriend(
      int matchmaker, int targetUserId, List<Integer> recommendIdList, boolean isOneWay, int type) {
    if (matchmaker == targetUserId) { // 自己不能向自己推荐
      return Constants.ERROR;
    }

    List<Integer> matchmakerFriends = null;
    try {
      matchmakerFriends = SnsAdapterFactory.getBuddyByIdCacheAdapter().getFriendListAsc(matchmaker);
    } catch (Exception e) {
      e.printStackTrace();
      return Constants.ERROR;
    }

    if (!matchmakerFriends.contains(matchmaker)) { // 判断targetUserId与自己是否为好友关系
      return Constants.ERROR;
    }
    recommendIdList.retainAll(matchmakerFriends); // 去掉recommendIdList中不是自己好友

    List<Integer> userIdList = new ArrayList<Integer>();
    userIdList.add(matchmaker);
    userIdList.add(targetUserId);
    userIdList.addAll(recommendIdList);

    Map<Integer, WUserCache> userCaches = null;
    try {
      userCaches = SnsAdapterFactory.getUserCacheAdapter().getUserCacheMap(userIdList);
    } catch (Exception e) {
      e.printStackTrace();
      return Constants.ERROR;
    }

    WUserCache matchmakerUserCache = userCaches.get(matchmaker);
    WUserCache targetUserCache = userCaches.get(targetUserId);
    if (matchmakerUserCache == null || targetUserCache == null) {
      return Constants.ERROR;
    }

    int targetCount = 0;
    for (Integer recommendId : recommendIdList) {
      WUserCache recommendUserCache = userCaches.get(recommendId);
      if (recommendUserCache == null) {
        continue;
      }
      if (isOneWay) {
        try {
          FriendRecommendedDAO.getInstance()
              .addRecommendedOneWay(
                  targetUserCache.getId(),
                  targetUserCache.getName(),
                  targetUserCache.getUnivName(),
                  targetUserCache.getTiny_Url(),
                  recommendUserCache.getId(),
                  recommendUserCache.getName(),
                  recommendUserCache.getUnivName(),
                  recommendUserCache.getTiny_Url(),
                  matchmakerUserCache.getId(),
                  matchmakerUserCache.getName(),
                  type);
          ++targetCount;
        } catch (Exception e) {
          e.printStackTrace();
        }
      } else {
        try {
          FriendRecommendedDAO.getInstance()
              .addRecommended(
                  targetUserCache.getId(),
                  targetUserCache.getName(),
                  targetUserCache.getUnivName(),
                  targetUserCache.getTiny_Url(),
                  recommendUserCache.getId(),
                  recommendUserCache.getName(),
                  recommendUserCache.getUnivName(),
                  recommendUserCache.getTiny_Url(),
                  matchmakerUserCache.getId(),
                  matchmakerUserCache.getName(),
                  type);
          UserCountAdapter.getInstance()
              .inc(recommendUserCache.getId(), UserCountAdapter.RECOMMENDED_FRIEND, 1);
          ++targetCount;
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    try {
      UserCountAdapter.getInstance()
          .inc(targetUserCache.getId(), UserCountAdapter.RECOMMENDED_FRIEND, targetCount);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return Constants.SUCCESS;
  }
Example #8
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;
  }