@WebMethod("friend/show") public RecordSet showFriends(QueryParams qp) { final int DEFAULT_USER_COUNT_IN_PAGE = 20; FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); String userId = qp.getString("user", ctx.getViewerIdString()); String cols = qp.getString( "columns", "user_id, display_name, remark,perhaps_name,image_url, status, gender, in_circles, his_friend, bidi,pedding_requests,profile_privacy"); if (cols.equals("#full")) cols = AccountLogic.USER_STANDARD_COLUMNS; boolean withPublicCircles = qp.getBoolean("with_public_circles", false); if (!withPublicCircles) return fs.getFriendsP( ctx, ctx.getViewerIdString(), userId, qp.getString("circles", Integer.toString(FRIENDS_CIRCLE)), cols, qp.getBoolean("in_public_circles", false), (int) qp.getInt("page", 0), (int) qp.getInt("count", DEFAULT_USER_COUNT_IN_PAGE)); else return fs.getFriendsV2P( ctx, ctx.getViewerIdString(), userId, qp.getString("circles", Integer.toString(FRIENDS_CIRCLE)), cols, (int) qp.getInt("page", 0), (int) qp.getInt("count", DEFAULT_USER_COUNT_IN_PAGE)); }
@WebMethod("circle/destroy") public boolean destroyCircle(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); return fs.destroyCircleP(ctx, ctx.getViewerIdString(), qp.checkGetString("circles")); }
@WebMethod("friend/usersset") public boolean setFriends(QueryParams qp, HttpServletRequest req) throws UnsupportedEncodingException { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); try { List<String> l = StringUtils2.splitList(qp.checkGetString("friendIds"), ",", true); MessageDelayCombineUtils.sendEmailCombineAndDelayNewFollower(ctx, ctx.getViewerIdString(), l); } catch (Exception e) { L.error(ctx, e, "delay and combine new follower email error!@@@@"); } String viewerId = ctx.getViewerIdString(); String friendIds = qp.checkGetString("friendIds"); String circleId = qp.checkGetString("circleId"); ConversationLogic c = GlobalLogics.getConversation(); if (c.getEnabled(ctx, Constants.LOCAL_CIRCLE_OBJECT, circleId) == 1) { Set<String> friends = StringUtils2.splitSet(friendIds, ",", true); for (String friend : friends) { c.createConversationP( ctx, Constants.USER_OBJECT, friend, Constants.C_SUBSCRIBE_LOCAL_CIRCLE, viewerId); } } return fs.setFriendsP( ctx, viewerId, friendIds, circleId, Constants.FRIEND_REASON_MANUALSELECT, qp.getBoolean("isadd", true)); }
@WebMethod("circle/create") public int createCircle(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); return Integer.parseInt( fs.createCircle(ctx, ctx.getViewerIdString(), qp.checkGetString("name"))); }
@WebMethod("circle/update") public boolean updateCircleName(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); return fs.updateCircleName( ctx, ctx.getViewerIdString(), qp.checkGetString("circle"), qp.checkGetString("name")); }
@WebMethod("remark/set") public boolean setUserRemark(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); return fs.setRemark( ctx, ctx.getViewerIdString(), qp.checkGetString("friend"), qp.getString("remark", "")); }
@WebMethod("relation/bidi") public Record getBidiRelation(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); String userId = qp.getString("source", ctx.getViewerIdString()); return fs.getBidiRelation( ctx, userId, qp.checkGetString("target"), qp.getString("circle", Integer.toString(FRIENDS_CIRCLE))); }
@WebMethod("friend/circlesset") public NoResponse setCircles(QueryParams qp, HttpServletRequest req, HttpServletResponse resp) throws IOException { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); String viewerId = ctx.getViewerIdString(); String friendId = qp.checkGetString("friendId"); String circleIds = qp.checkGetString("circleIds"); ConversationLogic c = GlobalLogics.getConversation(); Map<String, Integer> map = c.getEnabledByTargetIds(ctx, circleIds); for (Map.Entry<String, Integer> entry : map.entrySet()) { String circleId = entry.getKey(); int enabled = entry.getValue(); if (enabled == 1) { c.createConversationP( ctx, Constants.USER_OBJECT, friendId, Constants.C_SUBSCRIBE_LOCAL_CIRCLE, viewerId); } } Record rec = fs.setFriendP(ctx, viewerId, friendId, circleIds, Constants.FRIEND_REASON_MANUALSELECT); if (qp.containsKey("from_email")) { String notice = "Operate Success!"; String html = pageTemplate.merge( "notice.ftl", new Object[][] { {"host", serverHost}, {"notice", notice} }); resp.setContentType("text/html"); resp.getWriter().print(html); } else { output(qp, req, resp, rec.toString(false, false), 200, "text/plain"); } // add by wangpeng for delay and combine email try { List list = new ArrayList<String>(); list.add(qp.checkGetString("friendId")); MessageDelayCombineUtils.sendEmailCombineAndDelayNewFollower( ctx, ctx.getViewerIdString(), list); } catch (Exception e) { L.error(ctx, e, "delay and combine new follower email error!@@@@"); } return NoResponse.get(); }
@WebMethod("friend/both") public RecordSet getBothFriends(QueryParams qp) { final int DEFAULT_USER_COUNT_IN_PAGE = 20; FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); String userId = qp.getString("user", ctx.getViewerIdString()); return fs.getBothFriendsP( ctx, ctx.getViewerIdString(), userId, (int) qp.getInt("page", 0), (int) qp.getInt("count", DEFAULT_USER_COUNT_IN_PAGE)); }
@WebMethod("friend/exchange_vcard") public Record exchangeVcard(QueryParams qp, HttpServletRequest req) throws UnsupportedEncodingException { FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); boolean send_request = qp.getBoolean("send_request", false); return fs.exchangeVcardP( ctx, ctx.getViewerIdString(), qp.checkGetString("friendId"), qp.checkGetString("circleIds"), Constants.FRIEND_REASON_MANUALSELECT, send_request); }
@WebMethod("follower/show") public RecordSet showFollowers(QueryParams qp) { final int DEFAULT_USER_COUNT_IN_PAGE = 20; FriendshipLogic fs = GlobalLogics.getFriendship(); Context ctx = WutongContext.getContext(qp, true); String userId = qp.getString("user", ctx.getViewerIdString()); return fs.getFollowersP( ctx, ctx.getViewerIdString(), userId, qp.getString("circles", Integer.toString(FRIENDS_CIRCLE)), qp.getString( "columns", "user_id, display_name, remark,perhaps_name,image_url, status, gender, in_circles, his_friend, bidi,pedding_requests,profile_privacy"), (int) qp.getInt("page", 0), (int) qp.getInt("count", DEFAULT_USER_COUNT_IN_PAGE)); }
@WebMethod("circle/show") public RecordSet showCircles(QueryParams qp) { FriendshipLogic fs = GlobalLogics.getFriendship(); GroupLogic group = GlobalLogics.getGroup(); Context ctx = WutongContext.getContext(qp, false); String userId = qp.getString("user", ctx.getViewerIdString()); boolean withPublicCircles = qp.getBoolean("with_public_circles", false); if (!withPublicCircles) { RecordSet recs = fs.getCircles( ctx, userId, qp.getString("circles", ""), qp.getBoolean("with_users", false)); attachSubscribe(ctx, recs); return recs; } else { String circleIds = qp.getString("circles", ""); boolean withMembers = qp.getBoolean("with_users", false); List<String> circles = StringUtils2.splitList(circleIds, ",", true); List<String> groups = group.getGroupIdsFromMentions(ctx, circles); circles.removeAll(groups); RecordSet recs = fs.getCirclesP(ctx, userId, StringUtils2.joinIgnoreBlank(",", circles), withMembers); RecordSet recs0 = group.getGroups( ctx, PUBLIC_CIRCLE_ID_BEGIN, PUBLIC_CIRCLE_ID_END, ctx.getViewerIdString(), StringUtils2.joinIgnoreBlank(",", groups), GROUP_LIGHT_COLS + ",circle_ids,formal,subtype,parent_id", withMembers); recs0.renameColumn(GRP_COL_ID, "circle_id"); recs0.renameColumn(GRP_COL_NAME, "circle_name"); for (Record rec : recs) rec.put("type", CIRCLE_TYPE_LOCAL); for (Record rec : recs0) rec.put("type", CIRCLE_TYPE_PUBLIC); recs.addAll(recs0); attachSubscribe(ctx, recs); return recs; } }
@TraceCall @Override public RecordSet getPagesForMe(Context ctx) { long viewerId = ctx.getViewerId(); if (viewerId <= 0) return new RecordSet(); final LinkedHashSet<Long> pageIds = new LinkedHashSet<Long>(); String sql = new SQLBuilder.Select() .select("page_id") .from(pageTable) .where("destroyed_time=0 AND creator=${v(viewer_id)}", "viewer_id", viewerId) .toString(); SQLExecutor se = getSqlExecutor(); se.executeRecordHandler( sql, new RecordHandler() { @Override public void handle(Record rec) { pageIds.add(rec.getInt("page_id")); } }); // RecordSet groupRecs = GlobalLogics.getGroup().getGroups(ctx, Constants.GROUP_ID_BEGIN, // Constants.GROUP_ID_END, ctx.getViewerIdString(), "", "page_id", false); // for (Record groupRec : groupRecs) { // long pageId = groupRec.getInt("page_id", 0L); // if (pageId > 0) // pageIds.add(pageId); // } long[] followedPageIds = GlobalLogics.getFriendship().getFollowedPageIds(ctx, ctx.getViewerId()); if (ArrayUtils.isNotEmpty(followedPageIds)) { for (long pageId : followedPageIds) pageIds.add(pageId); } return getPages(ctx, CollectionUtils2.toLongArray(pageIds)); }
private void attachBasicInfo(Context ctx, Record pageRec) { long pageId = pageRec.getInt("page_id", 0); // viewer_can_update if (ctx.getViewerId() >= 0 && pageRec.getInt("creator") == ctx.getViewerId()) { pageRec.put("viewer_can_update", true); } else { pageRec.put("viewer_can_update", false); } // logo & cover url prefix addImagePrefix(imagePattern, pageRec); // followers count int followersCount = GlobalLogics.getFriendship().getFollowersCount(ctx, Long.toString(pageId)); pageRec.put("followers_count", followersCount); // followed long[] followedIds = GlobalLogics.getFriendship().isFollowedPages(ctx, ctx.getViewerId(), new long[] {pageId}); pageRec.put("followed", ArrayUtils.isNotEmpty(followedIds)); }
@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); } }
private void attachDetailInfo(Context ctx, Record pageRec) { long associatedId = pageRec.getInt("associated_id", 0L); Record rec = Commons.getUnifiedUser(ctx, associatedId); rec.copyColumn(GRP_COL_ID, "circle_id"); rec.copyColumn(GRP_COL_NAME, "circle_name"); String freeCircleIds = pageRec.getString("free_circle_ids"); RecordSet freeCircleRecs; if (StringUtils.isBlank(freeCircleIds)) { freeCircleRecs = new RecordSet(); } else { freeCircleRecs = GlobalLogics.getGroup() .getGroups( ctx, Constants.PUBLIC_CIRCLE_ID_BEGIN, Constants.PUBLIC_CIRCLE_ID_END, ctx.getViewerIdString(), freeCircleIds, Constants.GROUP_LIGHT_COLS, false); } freeCircleRecs.copyColumn(GRP_COL_ID, "circle_id"); freeCircleRecs.copyColumn(GRP_COL_NAME, "circle_name"); pageRec.put("associated", rec); pageRec.put("free_circles", freeCircleRecs); long[] followerIds = GlobalLogics.getFriendship() .getFollowerIds(ctx, ctx.getViewerId(), 0, Constants.GROUP_ID_BEGIN, 0, 15); RecordSet followerUserRecs = GlobalLogics.getAccount() .getUsers( ctx, ctx.getViewerIdString(), StringUtils2.join(followerIds, ","), AccountLogic.USER_LIGHT_COLUMNS, true); followerUserRecs.retainsCount(5); pageRec.put("followers", followerUserRecs); int objType = Constants.getUserTypeById(associatedId); if (objType == Constants.PUBLIC_CIRCLE_OBJECT) { boolean b = GlobalLogics.getGroup() .hasRight(ctx, associatedId, ctx.getViewerId(), Constants.ROLE_MEMBER); pageRec.put("in_associated_circle", b); } else { pageRec.put("in_associated_circle", false); } // shared count String viewerId = ctx.getViewerIdString(); String pageId = pageRec.getString("page_id"); StreamLogic stream = GlobalLogics.getStream(); Record sharedCount = new Record(); int sharedText = stream.getSharedCount(ctx, viewerId, pageId, TEXT_POST); sharedCount.put("shared_text", sharedText); int sharedPhoto = stream.getSharedCount(ctx, viewerId, pageId, PHOTO_POST); sharedCount.put("shared_photo", sharedPhoto); int sharedBook = stream.getSharedCount(ctx, viewerId, pageId, BOOK_POST); sharedCount.put("shared_book", sharedBook); int sharedApk = stream.getSharedCount(ctx, viewerId, pageId, APK_POST); sharedCount.put("shared_apk", sharedApk); int sharedLink = stream.getSharedCount(ctx, viewerId, pageId, LINK_POST); sharedCount.put("shared_link", sharedLink); int shared_static_file = stream.getSharedCount(ctx, viewerId, pageId, FILE_POST); sharedCount.put("shared_static_file", shared_static_file); int shared_audio = stream.getSharedCount(ctx, viewerId, pageId, AUDIO_POST); sharedCount.put("shared_audio", shared_audio); int shared_video = stream.getSharedCount(ctx, viewerId, pageId, VIDEO_POST); sharedCount.put("shared_video", shared_video); sharedCount.put( "shared_poll", GlobalLogics.getPoll().getRelatedPollCount(ctx, viewerId, pageId)); String eventIds = GlobalLogics.getGroup().getPageEvents(ctx, Long.parseLong(pageId)); Set<String> set = StringUtils2.splitSet(eventIds, ",", true); sharedCount.put("shared_event", set.size()); pageRec.put("shared_count", sharedCount); }
private void checkUpdatePagePermission(Context ctx, long pageId) { Record pageRec = getPage(ctx, pageId); if (pageRec.getInt("creator") != ctx.getViewerId()) throw new ServerException(WutongErrors.PAGE_ILLEGAL_PERMISSION); }
@TraceCall @Override public Record createPage(Context ctx, Record pageRec) { long viewerId = ctx.getViewerId(); GlobalLogics.getAccount().checkUserIds(ctx, Long.toString(viewerId)); long associatedId = pageRec.checkGetInt("associated_id"); // if (associatedId > 0) { // int userType = Constants.getUserTypeById(associatedId); // if (userType == Constants.PUBLIC_CIRCLE_OBJECT || userType == // Constants.EVENT_OBJECT) { // // TODO: group exists? // } else if (userType == Constants.USER_OBJECT) { // // TODO: user exists? // } else { // throw new ServerException(WutongErrors.PAGE_ILLEGAL_ASSOCIATED_ID); // } // } long now = DateUtils.nowMillis(); String sql = new SQLBuilder.Insert() .insertIgnoreInto(pageTable) .values( new Record() .set("created_time", now) .set("updated_time", now) .set("destroyed_time", 0L) .set("email_domain1", pageRec.getString("email_domain1")) .set("email_domain2", pageRec.getString("email_domain2")) .set("email_domain3", pageRec.getString("email_domain3")) .set("email_domain4", pageRec.getString("email_domain4")) .set("type", pageRec.getString("type")) .set("name", pageRec.getString("name")) .set("name_en", pageRec.getString("name_en")) .set("email", pageRec.getString("email")) .set("website", pageRec.getString("website")) .set("tel", pageRec.getString("tel")) .set("fax", pageRec.getString("fax")) .set("zip_code", pageRec.getString("zip_code")) .set("small_logo_url", pageRec.getString("small_logo_url")) .set("logo_url", pageRec.getString("logo_url")) .set("large_logo_url", pageRec.getString("large_logo_url")) .set("small_cover_url", pageRec.getString("small_cover_url")) .set("cover_url", pageRec.getString("cover_url")) .set("large_cover_url", pageRec.getString("large_cover_url")) .set("description", pageRec.getString("description")) .set("description_en", pageRec.getString("description_en")) .set("creator", viewerId) .set("associated_id", associatedId) .set("free_circle_ids", pageRec.getString("free_circle_ids"))) .toString(); SQLExecutor se = getSqlExecutor(); ObjectHolder<Long> idHolder = new ObjectHolder<Long>(0L); se.executeUpdate(sql, idHolder); if (idHolder.value == 0L) throw new ServerException(WutongErrors.PAGE_SERVICE_ERROR_CODE, "Create page error"); GlobalLogics.getFriendship().followPage(ctx, ctx.getViewerId(), idHolder.value); return getPage(ctx, idHolder.value); }