Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/main/java/io/github/doocs/im/core/Sns.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Sns {
* 关系链管理服务名
*/
public static final String SERVICE_NAME = "sns";
public static final String SERVICE_NAME_FOLLOW = "follow";

/**
* 关系链管理相关命令字
Expand All @@ -37,6 +38,11 @@ public class Sns {
public static final String GROUP_ADD_COMMAND = "group_add";
public static final String GROUP_DELETE_COMMAND = "group_delete";
public static final String GROUP_GET_COMMAND = "group_get";
public static final String FOLLOW_ADD_COMMAND = "follow_add";
public static final String FOLLOW_DELETE_COMMAND = "follow_delete";
public static final String FOLLOW_GET_COMMAND = "follow_get";
public static final String FOLLOW_CHECK_COMMAND = "follow_check";
public static final String FOLLOW_GET_INFO_COMMAND = "follow_get_info";

private final ImClient imClient;

Expand Down Expand Up @@ -298,4 +304,90 @@ public GroupGetResult groupGet(GroupGetRequest groupGetRequest, long random) thr
String url = imClient.getUrl(SERVICE_NAME, GROUP_GET_COMMAND, random);
return HttpUtil.post(url, groupGetRequest, GroupGetResult.class, imClient.getConfig());
}

/**
* 关注用户
*
* @param followAddRequest 关注用户请求参数
* @return 关注用户结果
* @throws IOException 关注用户异常
*/
public FollowAddResult followAdd(FollowAddRequest followAddRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_ADD_COMMAND);
return HttpUtil.post(url, followAddRequest, FollowAddResult.class, imClient.getConfig());
}

public FollowAddResult followAdd(FollowAddRequest followAddRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_ADD_COMMAND, random);
return HttpUtil.post(url, followAddRequest, FollowAddResult.class, imClient.getConfig());
}

/**
* 取消关注用户
*
* @param followDeleteRequest 取消关注用户请求参数
* @return 取消关注用户结果
* @throws IOException 取消关注用户异常
*/
public FollowDeleteResult followDelete(FollowDeleteRequest followDeleteRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_DELETE_COMMAND);
return HttpUtil.post(url, followDeleteRequest, FollowDeleteResult.class, imClient.getConfig());
}

public FollowDeleteResult followDelete(FollowDeleteRequest followDeleteRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_DELETE_COMMAND, random);
return HttpUtil.post(url, followDeleteRequest, FollowDeleteResult.class, imClient.getConfig());
}

/**
* 拉取关注、粉丝与互关列表
*
* @param followGetRequest 拉取关注请求参数
* @return 拉取关注结果
* @throws IOException 拉取关注异常
*/
public FollowGetResult followGet(FollowGetRequest followGetRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_COMMAND);
return HttpUtil.post(url, followGetRequest, FollowGetResult.class, imClient.getConfig());
}

public FollowGetResult followGet(FollowGetRequest followGetRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_COMMAND, random);
return HttpUtil.post(url, followGetRequest, FollowGetResult.class, imClient.getConfig());
}

/**
* 检查关注关系
*
* @param followCheckRequest 检查关注关系请求参数
* @return 检查关注关系结果
* @throws IOException 检查关注关系异常
*/
public FollowCheckResult followCheck(FollowCheckRequest followCheckRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_CHECK_COMMAND);
return HttpUtil.post(url, followCheckRequest, FollowCheckResult.class, imClient.getConfig());
}

public FollowCheckResult followCheck(FollowCheckRequest followCheckRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_CHECK_COMMAND, random);
return HttpUtil.post(url, followCheckRequest, FollowCheckResult.class, imClient.getConfig());
}

/**
* 获取用户的关注、粉丝与互关数
*
* @param followGetInfoRequest 获取用户的关注、粉丝与互关数请求参数
* @return 获取用户的关注、粉丝与互关数结果
* @throws IOException 拉取关注异常
*/
public FollowGetInfoResult followGetInfo(FollowGetInfoRequest followGetInfoRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_INFO_COMMAND);
return HttpUtil.post(url, followGetInfoRequest, FollowGetInfoResult.class, imClient.getConfig());
}

public FollowGetInfoResult followGetInfo(FollowGetInfoRequest followGetInfoRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_INFO_COMMAND, random);
return HttpUtil.post(url, followGetInfoRequest, FollowGetInfoResult.class, imClient.getConfig());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.List;

/**
* <p>
* 关注用户-请求参数
* </p>
*
* @author MC.Yang
* @version V1.0
**/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FollowAddRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = -4998729848603268465L;

/**
* 发起关注操作的用户的 UserID
*/
@JsonProperty("From_Account")
private String fromAccount;

/**
* 关注结构体对象
*/
@JsonProperty("FollowItem")
List<FollowRequestItem> followItemList;

public FollowAddRequest() {
}

public FollowAddRequest(String fromAccount, List<FollowRequestItem> followItemList) {
this.fromAccount = fromAccount;
this.followItemList = followItemList;
}

private FollowAddRequest(Builder builder) {
this.fromAccount = builder.fromAccount;
this.followItemList = builder.followItemList;
}

public static Builder builder() {
return new Builder();
}

public String getFromAccount() {
return fromAccount;
}

public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
}

public List<FollowRequestItem> getFollowItemList() {
return followItemList;
}

public void setFollowItemList(List<FollowRequestItem> followRequestItemList) {
this.followItemList = followRequestItemList;
}

public static final class Builder {
private String fromAccount;
private List<FollowRequestItem> followItemList;

private Builder() {
}

public FollowAddRequest build() {
return new FollowAddRequest(this);
}

public Builder fromAccount(String fromAccount) {
this.fromAccount = fromAccount;
return this;
}

public Builder followItemList(List<FollowRequestItem> followRequestItemList) {
this.followItemList = followRequestItemList;
return this;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.List;

/**
* <p>
* 检查关注关系-请求参数
* </p>
*
* @author MC.Yang
* @version V1.0
**/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FollowCheckRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = -1540312147327812439L;

/**
* 请求检查该用户与 To_Account 之间的关注关系
*/
@JsonProperty("From_Account")
private String fromAccount;

/**
* 待检查的用户列表,单次请求的 To_Account 数不得超过100
*/
@JsonProperty("To_Account")
private List<String> toAccount;

public FollowCheckRequest() {
}

public FollowCheckRequest(String fromAccount, List<String> toAccount) {
this.fromAccount = fromAccount;
this.toAccount = toAccount;
}

private FollowCheckRequest(FollowCheckRequest.Builder builder) {
this.fromAccount = builder.fromAccount;
this.toAccount = builder.toAccount;
}

public static FollowCheckRequest.Builder builder() {
return new FollowCheckRequest.Builder();
}

public String getFromAccount() {
return fromAccount;
}

public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
}

public List<String> getToAccount() {
return toAccount;
}

public void setToAccount(List<String> toAccount) {
this.toAccount = toAccount;
}


public static final class Builder {
private String fromAccount;
private List<String> toAccount;

private Builder() {
}

public FollowCheckRequest build() {
return new FollowCheckRequest(this);
}

public FollowCheckRequest.Builder fromAccount(String fromAccount) {
this.fromAccount = fromAccount;
return this;
}

public FollowCheckRequest.Builder toAccount(List<String> toAccount) {
this.toAccount = toAccount;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.List;

/**
* <p>
* 取消关注用户-请求参数
* </p>
*
* @author MC.Yang
* @version V1.0
**/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class FollowDeleteRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = -6307672357208946936L;

/**
* 发起取关操作的用户的 UserID
*/
@JsonProperty("From_Account")
private String fromAccount;

/**
* 待取关的用户的 UserID,单次请求的 To_Account 数不得超过20
*/
@JsonProperty("To_Account")
private List<String> toAccount;

public FollowDeleteRequest() {
}

public FollowDeleteRequest(String fromAccount, List<String> toAccount) {
this.fromAccount = fromAccount;
this.toAccount = toAccount;
}

private FollowDeleteRequest(FollowDeleteRequest.Builder builder) {
this.fromAccount = builder.fromAccount;
this.toAccount = builder.toAccount;
}

public static FollowDeleteRequest.Builder builder() {
return new FollowDeleteRequest.Builder();
}

public String getFromAccount() {
return fromAccount;
}

public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
}

public List<String> getToAccount() {
return toAccount;
}

public void setToAccount(List<String> toAccount) {
this.toAccount = toAccount;
}


public static final class Builder {
private String fromAccount;
private List<String> toAccount;

private Builder() {
}

public FollowDeleteRequest build() {
return new FollowDeleteRequest(this);
}

public FollowDeleteRequest.Builder fromAccount(String fromAccount) {
this.fromAccount = fromAccount;
return this;
}

public FollowDeleteRequest.Builder toAccount(List<String> toAccount) {
this.toAccount = toAccount;
return this;
}
}
}
Loading