Unverified Commit dc367b43 authored by Yang Libin's avatar Yang Libin Committed by GitHub

feat: add recent contact api (#32)

parent 4143b3bd
......@@ -22,7 +22,7 @@ Add the Maven dependency:
<dependency>
<groupId>io.github.doocs</groupId>
<artifactId>im-server-sdk-java</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
</dependency>
```
......
......@@ -6,7 +6,7 @@
<groupId>io.github.doocs</groupId>
<artifactId>im-server-sdk-java</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<packaging>jar</packaging>
<name>qcloud-im-server-sdk-java</name>
......
......@@ -24,6 +24,7 @@ public class IMClient {
public Group group;
public SNS sns;
public Operation operation;
public RecentContact recentContact;
/**
* init property
*/
......@@ -59,6 +60,7 @@ public class IMClient {
group = new Group(this);
operation = new Operation(this);
sns = new SNS(this);
recentContact = new RecentContact(this);
}
public String getUrl(String serviceName, String command) {
......
package io.github.doocs.im.core;
import io.github.doocs.im.IMClient;
import io.github.doocs.im.model.request.DeleteRecentContactRequest;
import io.github.doocs.im.model.request.GetRecentContactListRequest;
import io.github.doocs.im.model.response.DeleteRecentContactResult;
import io.github.doocs.im.model.response.GetRecentContactListResult;
import io.github.doocs.im.util.HttpUtil;
import io.github.doocs.im.util.JsonUtil;
import java.io.IOException;
/**
* @author bingo
* @since 2021/10/11 10:25
*/
public class RecentContact {
private static final String SERVICE_NAME = "recentcontact";
private static final String GET_RECENT_CONTACT_LIST = "get_list";
private static final String DELETE_RECENT_CONTACT = "delete";
private final IMClient imClient;
public RecentContact(IMClient imClient) {
this.imClient = imClient;
}
public GetRecentContactListResult recentContactList(GetRecentContactListRequest recentContactListRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_RECENT_CONTACT_LIST);
String result = HttpUtil.post(url, JsonUtil.obj2Str(recentContactListRequest), null);
return JsonUtil.str2Obj(result, GetRecentContactListResult.class);
}
public DeleteRecentContactResult deleteRecentContact(DeleteRecentContactRequest deleteRecentContactRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, DELETE_RECENT_CONTACT);
String result = HttpUtil.post(url, JsonUtil.obj2Str(deleteRecentContactRequest), null);
return JsonUtil.str2Obj(result, DeleteRecentContactResult.class);
}
}
package io.github.doocs.im.model.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/10/11 10:49
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeleteRecentContactRequest extends GenericRequest {
@JsonProperty("From_Account")
private String fromAccount;
@JsonProperty("Type")
private Integer type;
@JsonProperty("To_Account")
private String toAccount;
@JsonProperty("ClearRamble")
private Integer clearRamble;
public String getFromAccount() {
return fromAccount;
}
public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getToAccount() {
return toAccount;
}
public void setToAccount(String toAccount) {
this.toAccount = toAccount;
}
public Integer getClearRamble() {
return clearRamble;
}
public void setClearRamble(Integer clearRamble) {
this.clearRamble = clearRamble;
}
}
package io.github.doocs.im.model.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/10/11 10:28
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetRecentContactListRequest extends GenericRequest {
@JsonProperty("From_Account")
private String fromAccount;
@JsonProperty("TimeStamp")
private Integer timestamp;
@JsonProperty("StartIndex")
private Integer startIndex;
@JsonProperty("TopTimeStamp")
private Integer topTimestamp;
@JsonProperty("TopStartIndex")
private Integer topStartIndex;
@JsonProperty("AssistFlags")
private Integer assistFlags;
public String getFromAccount() {
return fromAccount;
}
public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
}
public Integer getTimestamp() {
return timestamp;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
public Integer getStartIndex() {
return startIndex;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
public Integer getTopTimestamp() {
return topTimestamp;
}
public void setTopTimestamp(Integer topTimestamp) {
this.topTimestamp = topTimestamp;
}
public Integer getTopStartIndex() {
return topStartIndex;
}
public void setTopStartIndex(Integer topStartIndex) {
this.topStartIndex = topStartIndex;
}
public Integer getAssistFlags() {
return assistFlags;
}
public void setAssistFlags(Integer assistFlags) {
this.assistFlags = assistFlags;
}
}
package io.github.doocs.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/10/11 10:53
*/
public class DeleteRecentContactResult extends GenericResult {
@JsonProperty("ErrorDisplay")
private String errorDisplay;
public String getErrorDisplay() {
return errorDisplay;
}
public void setErrorDisplay(String errorDisplay) {
this.errorDisplay = errorDisplay;
}
@Override
public String toString() {
return "DeleteRecentContactResult{" +
"errorDisplay='" + errorDisplay + '\'' +
'}';
}
}
package io.github.doocs.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
/**
* @author bingo
* @since 2021/10/11 10:31
*/
public class GetRecentContactListResult extends GenericResult {
@JsonProperty("SessionItem")
private List<RecentContactSessionItem> sessionItem;
@JsonProperty("CompleteFlag")
private Integer completeFlag;
@JsonProperty("TimeStamp")
private Integer timestamp;
@JsonProperty("StartIndex")
private Integer startIndex;
@JsonProperty("TopTimeStamp")
private Integer topTimestamp;
@JsonProperty("TopStartIndex")
private Integer topStartIndex;
@JsonProperty("ErrorDisplay")
private String errorDisplay;
public List<RecentContactSessionItem> getSessionItem() {
return sessionItem;
}
public void setSessionItem(List<RecentContactSessionItem> sessionItem) {
this.sessionItem = sessionItem;
}
public Integer getCompleteFlag() {
return completeFlag;
}
public void setCompleteFlag(Integer completeFlag) {
this.completeFlag = completeFlag;
}
public Integer getTimestamp() {
return timestamp;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
public Integer getStartIndex() {
return startIndex;
}
public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
}
public Integer getTopTimestamp() {
return topTimestamp;
}
public void setTopTimestamp(Integer topTimestamp) {
this.topTimestamp = topTimestamp;
}
public Integer getTopStartIndex() {
return topStartIndex;
}
public void setTopStartIndex(Integer topStartIndex) {
this.topStartIndex = topStartIndex;
}
public String getErrorDisplay() {
return errorDisplay;
}
public void setErrorDisplay(String errorDisplay) {
this.errorDisplay = errorDisplay;
}
@Override
public String toString() {
return "GetRecentContactListResult{" +
"sessionItem=" + sessionItem +
", completeFlag=" + completeFlag +
", timestamp=" + timestamp +
", startIndex=" + startIndex +
", topTimestamp=" + topTimestamp +
", topStartIndex=" + topStartIndex +
", errorDisplay='" + errorDisplay + '\'' +
'}';
}
}
package io.github.doocs.im.model.response;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author bingo
* @since 2021/10/11 10:37
*/
public class RecentContactSessionItem {
@JsonProperty("Type")
private Integer type;
@JsonProperty("To_Account")
private String toAccount;
@JsonProperty("GroupId")
private String groupId;
@JsonProperty("MsgTime")
private String msgTime;
@JsonProperty("TopFlag")
private Integer topFlag;
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getToAccount() {
return toAccount;
}
public void setToAccount(String toAccount) {
this.toAccount = toAccount;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getMsgTime() {
return msgTime;
}
public void setMsgTime(String msgTime) {
this.msgTime = msgTime;
}
public Integer getTopFlag() {
return topFlag;
}
public void setTopFlag(Integer topFlag) {
this.topFlag = topFlag;
}
@Override
public String toString() {
return "RecentContactSessionItem{" +
"type=" + type +
", toAccount='" + toAccount + '\'' +
", groupId='" + groupId + '\'' +
", msgTime='" + msgTime + '\'' +
", topFlag=" + topFlag +
'}';
}
}
package io.github.doocs.im;
import io.github.doocs.im.model.request.DeleteRecentContactRequest;
import io.github.doocs.im.model.request.GetRecentContactListRequest;
import io.github.doocs.im.model.response.DeleteRecentContactResult;
import io.github.doocs.im.model.response.GetRecentContactListResult;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @author bingo
* @since 2021/10/11 10:56
*/
public class RecentContactTest {
private static final Properties properties = new Properties();
private static final IMClient client;
static {
InputStream resourceAsStream = RecentContactTest.class.getClassLoader().getResourceAsStream("app.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
e.printStackTrace();
}
String key = properties.getProperty("key");
String identifier = properties.getProperty("identifier");
Long appId = Long.parseLong(properties.getProperty("appId"));
client = IMClient.getInstance(appId, identifier, key);
}
@Test
public void testGetRecentContactList() throws IOException {
GetRecentContactListRequest request = new GetRecentContactListRequest();
request.setFromAccount("bingo");
request.setAssistFlags(1);
request.setStartIndex(0);
request.setTimestamp(213213123);
request.setTopStartIndex(100);
request.setTopTimestamp(1121212121);
GetRecentContactListResult result = client.recentContact.recentContactList(request);
System.out.println(result);
Assert.assertEquals("OK", result.getActionStatus());
}
@Test
public void testDeleteRecentContact() throws IOException {
DeleteRecentContactRequest request = new DeleteRecentContactRequest();
request.setFromAccount("bingo");
request.setToAccount("test1");
request.setType(1);
request.setClearRamble(2);
DeleteRecentContactResult result = client.recentContact.deleteRecentContact(request);
System.out.println(result);
Assert.assertEquals("OK", result.getActionStatus());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment