@WebMethod("friend/contactset")
  public Record setContactFriends(QueryParams qp, HttpServletRequest req)
      throws UnsupportedEncodingException {
    FriendshipLogic fs = GlobalLogics.getFriendship();
    AccountLogic account = GlobalLogics.getAccount();

    Context ctx = WutongContext.getContext(qp, true);

    Record rec = account.findUidLoginNameNotInID(ctx, qp.checkGetString("content"));
    String fid = "";
    String hasVirtualFriendId =
        fs.getUserFriendHasVirtualFriendId(
            ctx, ctx.getViewerIdString(), qp.checkGetString("content"));
    if (rec.isEmpty() && hasVirtualFriendId.equals("0")) {
      fid =
          fs.setContactFriendP(
              ctx,
              ctx.getViewerIdString(),
              qp.checkGetString("name"),
              qp.checkGetString("content"),
              qp.checkGetString("circleIds"),
              Constants.FRIEND_REASON_MANUALSELECT);
      return account.getUser(
          ctx,
          ctx.getViewerIdString(),
          fid,
          qp.getString("columns", AccountLogic.USER_LIGHT_COLUMNS));
    } else {
      fid = !rec.isEmpty() ? rec.getString("user_id") : hasVirtualFriendId;
      return fs.setFriendP(
          ctx,
          ctx.getViewerIdString(),
          fid,
          qp.checkGetString("circleIds"),
          Constants.FRIEND_REASON_MANUALSELECT);
    }
  }
Пример #2
0
  @Override
  protected List<Long> getScope(Context ctx, String senderId, Object... args) {
    List<Long> userIds = new ArrayList<Long>();
    RecordSet liked_Users = new RecordSet();
    if (getSettingKey(ctx).equals(Constants.NTF_MY_APP_LIKE)) {
      /*
          RecordSet es_shared_Users = p.findWhoSharedApp((String)args[0], 200);
          for (Record ue : es_shared_Users) {
          if (!userIds.contains(Long.parseLong(ue.getString("source"))) && !ue.getString("source").equals("0") && !ue.getString("source").equals("")) {
              userIds.add(Long.parseLong(ue.getString("source")));
          }


          liked_Users = p.likedUsers(Constants.APK_OBJECT, (String)args[0], 0, 200);
      }
      */

      // =========================new send to ,from conversation=========================

      String packageName = (String) args[0].toString().trim();
      String[] a = StringUtils.split(packageName, "-");
      if (a.length > 1) packageName = a[0];

      List<String> reasons = new ArrayList<String>();
      reasons.add(String.valueOf(Constants.C_APK_SHARE));
      ConversationLogic conversation = GlobalLogics.getConversation();
      RecordSet conversation_users =
          conversation.getConversation(ctx, Constants.APK_OBJECT, packageName, reasons, 0, 0, 100);
      for (Record r : conversation_users) {
        if (!userIds.contains(Long.parseLong(r.getString("from_"))))
          userIds.add(Long.parseLong(r.getString("from_")));
      }

      List<String> reasons1 = new ArrayList<String>();
      reasons1.add(String.valueOf(Constants.C_APK_LIKE));
      RecordSet conversation_users1 =
          conversation.getConversation(ctx, Constants.APK_OBJECT, packageName, reasons1, 0, 0, 100);

      AccountLogic account = GlobalLogics.getAccount();
      liked_Users.addAll(
          account.getUsers(
              ctx,
              (String) args[1],
              conversation_users1.joinColumnValues("from_", ","),
              "user_id,display_name",
              false));

      // =========================new send to ,from conversation end ====================
    }
    if (userIds.contains(Long.parseLong((String) args[1])))
      userIds.remove(Long.parseLong((String) args[1]));

    // exclude sender
    if (StringUtils.isNotBlank(senderId)) {
      userIds.remove(Long.parseLong(senderId));
    }

    try {
      IgnoreLogic ignore = GlobalLogics.getIgnore();
      userIds = ignore.formatIgnoreUserListP(ctx, userIds, "", "");
      List<Long> lu = new ArrayList<Long>();
      for (Record r : liked_Users) {
        lu.add(Long.parseLong(r.getString("user_id")));
      }
      lu = ignore.formatIgnoreUserListP(ctx, lu, "", "");
      for (int i = liked_Users.size() - 1; i >= 0; i--) {
        if (!lu.contains(Long.parseLong(liked_Users.get(i).getString("user_id"))))
          liked_Users.remove(i);
      }
    } catch (Exception e) {
    }

    List<String> l = new ArrayList<String>();
    int i = 0;
    for (Record user : liked_Users) {
      if (i > 3) break;

      String userId = user.getString("user_id");
      String displayName = user.getString("display_name");
      if (StringUtils.contains(displayNames, displayName)) {
        continue;
      } else {
        displayNames += displayName + ", ";
        l.add(
            "<a href=\"borqs://profile/details?uid=" + userId + "&tab=2\">" + displayName + "</a>");
        i++;
      }
    }

    nameLinks = StringUtils.join(l, ", ");
    if (StringUtils.isNotBlank(displayNames)) {
      displayNames = StringUtils.substringBeforeLast(displayNames, ",");
    }

    return userIds;
  }