createUserList = new ArrayList<>();
- EMCreateUser createUser = new EMCreateUser(randomUsername, randomPassword);
- EMCreateUser createUser1 = new EMCreateUser(randomUsername1, randomPassword);
- createUserList.add(createUser);
- createUserList.add(createUser1);
-
- assertDoesNotThrow(() -> this.service.user().create(createUserList)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().get(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().get(randomUsername1).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername1).block(Utilities.IT_TIMEOUT));
- assertThrows(EMNotFoundException.class,
- () -> this.service.user().get(randomUsername).block(Utilities.IT_TIMEOUT));
- assertThrows(EMNotFoundException.class,
- () -> this.service.user().get(randomUsername1).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserForceLogout() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().forceLogoutAllDevices(randomUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserUpdatePassword() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().updateUserPassword(randomUsername, "password")
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserListUsers() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().listUsers(1, null).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- // TODO: enable this once we can use a clean appkey for tests
- // currently we use easemob-demo#easechatui for the gateway token007 tests and this appkey has too many users
- @Disabled
- void testUserListAll() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- String username = assertDoesNotThrow(
- () -> this.service.user().listAllUsers().blockLast(Utilities.IT_TIMEOUT));
- if (!username.equals(randomUsername)) {
- throw new RuntimeException(
- String.format("%s is not found in the user list", randomUsername));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserContactAdd() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomContactUsername = Utilities.randomUserName();
- String randomContactPassword = randomContactUsername;
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().create(randomContactUsername, randomContactPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.contact().add(randomUsername, randomContactUsername)
- .block(Utilities.IT_TIMEOUT));
- String username = assertDoesNotThrow(
- () -> this.service.contact().list(randomUsername).blockLast(Utilities.IT_TIMEOUT));
- if (!username.equals(randomContactUsername)) {
- throw new RuntimeException(
- String.format("%s did not found %s in his contact list", randomUsername,
- randomContactUsername));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomContactUsername)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserContactRemove() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomContactUsername = Utilities.randomUserName();
- String randomContactPassword = randomContactUsername;
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().create(randomContactUsername, randomContactPassword)
- .block(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(() -> this.service.contact().add(randomUsername, randomContactUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.contact().remove(randomUsername, randomContactUsername)
- .block(Utilities.IT_TIMEOUT));
- String username = assertDoesNotThrow(
- () -> this.service.contact().list(randomUsername).blockLast(Utilities.IT_TIMEOUT));
- if (username != null) {
- throw new RuntimeException(String.format("%s contact remove fail", username));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomContactUsername)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserContactList() {
- // add bob to alice's contact list
- String aliceUserName = Utilities.randomUserName();
- String bobUserName = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- assertDoesNotThrow(() -> this.service.user().create(aliceUserName, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().create(bobUserName, randomPassword)
- .block(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(() -> this.service.contact().add(aliceUserName, bobUserName)
- .block(Utilities.IT_TIMEOUT));
- String aliceFirstFriend =
- assertDoesNotThrow(() -> this.service.contact().list(aliceUserName))
- .blockFirst(Utilities.IT_TIMEOUT);
- if (aliceFirstFriend == null) {
- throw new RuntimeException(String.format("%s contact list is null", aliceUserName));
- }
-
- if (!aliceFirstFriend.equals(bobUserName)) {
- throw new RuntimeException(String.format("%s did not found %s in his contact list",
- aliceUserName, bobUserName));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(aliceUserName).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(bobUserName)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserGetUsersBlockedFromSendMsg() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomUsernameCodeJack = Utilities.randomUserName();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().create(randomUsernameCodeJack, randomPassword)
- .block(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(() -> this.service.block()
- .blockUserSendMsgToUser(randomUsernameCodeJack, randomUsername)
- .block(Utilities.IT_TIMEOUT));
- EMBlock block = assertDoesNotThrow(
- () -> this.service.block().getUsersBlockedFromSendMsgToUser(randomUsername))
- .blockFirst(Utilities.IT_TIMEOUT);
- if (!block.getUsername().equals(randomUsernameCodeJack)) {
- throw new RuntimeException(
- String.format("%s did not found %s in his block list", randomUsername,
- randomUsernameCodeJack));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserBlockUserSendMsg() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomUsernameCodeJack = Utilities.randomUserName();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().create(randomUsernameCodeJack, randomPassword)
- .block(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(() -> this.service.contact().add(randomUsername, randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block()
- .blockUserSendMsgToUser(randomUsernameCodeJack, randomUsername)
- .block(Utilities.IT_TIMEOUT));
- EMBlock block = assertDoesNotThrow(
- () -> this.service.block().getUsersBlockedFromSendMsgToUser(randomUsername)
- .blockLast(Utilities.IT_TIMEOUT));
- String username = assertDoesNotThrow(
- () -> this.service.contact().list(randomUsername).blockLast(Utilities.IT_TIMEOUT));
- if (!block.getUsername().equals(randomUsernameCodeJack)) {
- throw new RuntimeException(
- String.format("%s did not found %s in his block list", randomUsername,
- randomUsernameCodeJack));
- }
-
- if (username == null) {
- throw new RuntimeException(
- String.format("%s does not exist in %s contact list", randomUsernameCodeJack,
- randomUsername));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserUnblockUserSendMsg() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomUsernameCodeJack = Utilities.randomUserName();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().create(randomUsernameCodeJack, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.contact().add(randomUsername, randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block()
- .blockUserSendMsgToUser(randomUsernameCodeJack, randomUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block()
- .unblockUserSendMsgToUser(randomUsernameCodeJack, randomUsername)
- .block(Utilities.IT_TIMEOUT));
- EMBlock block = assertDoesNotThrow(
- () -> this.service.block().getUsersBlockedFromSendMsgToUser(randomUsername)
- .blockLast(Utilities.IT_TIMEOUT));
- String username = assertDoesNotThrow(
- () -> this.service.contact().list(randomUsername).blockLast(Utilities.IT_TIMEOUT));
- if (block != null) {
- throw new RuntimeException(
- String.format("%s unblock %s fail", randomUsername, randomUsernameCodeJack));
- }
- if (!username.equals(randomUsernameCodeJack)) {
- throw new RuntimeException(
- String.format("%s does not exist in %s contact list", randomUsernameCodeJack,
- randomUsername));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserCountMissedMessages() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
-
- String randomUsernameCodeJack = Utilities.randomUserName();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().create(randomUsernameCodeJack, randomPassword)
- .block(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(() -> this.service.message().send()
- .fromUser(randomUsernameCodeJack)
- .toUser(randomUsername)
- .text(msg -> msg.text("offlineMessage"))
- .send()
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.message().countMissedMessages(randomUsername)
- .blockFirst(Utilities.IT_TIMEOUT));
-
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().delete(randomUsernameCodeJack)
- .block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserBlockLogin() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block().blockUserLogin(randomUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserUnblockLogin() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block().blockUserLogin(randomUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.block().unblockUserLogin(randomUsername)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testUserOnlineStatus() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- boolean isOnline = assertDoesNotThrow(() -> this.service.user().isUserOnline(randomUsername)
- .block(Utilities.IT_TIMEOUT));
- if (isOnline) {
- throw new RuntimeException(String.format("%s is online status", randomUsername));
- }
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testIsUsersOnline() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(() -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(() -> this.service.user().isUsersOnline(Arrays.asList(randomUsername))
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(
- () -> this.service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT));
- }
-
- @Test
- void testGetUserToken() {
- String randomUsername = Utilities.randomUserName();
- String randomPassword = Utilities.randomPassword();
- assertDoesNotThrow(
- () -> this.service.user().create(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- // notice the deprecated stuff
- assertDoesNotThrow(() -> this.service.user().getToken(randomUsername, randomPassword)
- .block(Utilities.IT_TIMEOUT));
- }
-
-
- @Test
- public void testGetUserTokenWithInherit() throws Exception {
- String randomUsername = Utilities.randomUserName();
- // notice the deprecated stuff
- assertDoesNotThrow(() -> {
- service.token().getUserTokenWithInherit(randomUsername);
- });
- assertDoesNotThrow(() -> {
- service.user().get(randomUsername).block(Utilities.IT_TIMEOUT);
- });
- assertDoesNotThrow(() -> {
- service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT);
- });
- }
-
- @Test
- public void testGetUserTokenTtlWithInherit() throws Exception {
- String randomUsername = Utilities.randomUserName();
- // notice the deprecated stuff
- assertDoesNotThrow(() -> {
- service.token().getUserTokenWithInherit(randomUsername, 1000);
- });
- assertDoesNotThrow(() -> {
- service.user().get(randomUsername).block(Utilities.IT_TIMEOUT);
- });
- assertDoesNotThrow(() -> {
- service.user().delete(randomUsername).block(Utilities.IT_TIMEOUT);
- });
- }
-
-}
diff --git a/im-sdk-core/src/integration-test/java/com/easemob/im/server/api/user/UserNameIT.java b/im-sdk-core/src/integration-test/java/com/easemob/im/server/api/user/UserNameIT.java
deleted file mode 100644
index 0f8c51e20..000000000
--- a/im-sdk-core/src/integration-test/java/com/easemob/im/server/api/user/UserNameIT.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.easemob.im.server.api.user;
-
-import com.easemob.im.server.EMProperties;
-import com.easemob.im.server.EMService;
-import com.easemob.im.server.api.util.Utilities;
-import com.easemob.im.server.exception.EMInvalidArgumentException;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-public class UserNameIT {
-
- /*EMService serviceWithUserNameValidation;
- EMService serviceNoUserNameValidation;
-
- public UserNameIT() {
- String realm = System.getenv("IM_REALM");
- String appkey = System.getenv("IM_APPKEY");
- String baseUri = System.getenv("IM_BASE_URI");
-
- EMProperties propertiesWithUserNameValidation = null;
- EMProperties propertiesNoUserNameValidation = null;
-
- if (realm != null && realm.equals(EMProperties.Realm.AGORA_REALM.toString())) {
- String appId = System.getenv("IM_APP_ID");
- String appCert = System.getenv("IM_APP_CERT");
-
- propertiesWithUserNameValidation = EMProperties.builder()
- .setBaseUri(baseUri)
- .setRealm(EMProperties.Realm.AGORA_REALM)
- .setAppkey(appkey)
- .setAppId(appId)
- .setAppCert(appCert)
- .build();
-
- propertiesNoUserNameValidation = EMProperties.builder()
- .turnOffUserNameValidation()
- .setBaseUri(baseUri)
- .setRealm(EMProperties.Realm.AGORA_REALM)
- .setAppkey(appkey)
- .setAppId(appId)
- .setAppCert(appCert)
- .build();
-
- } else {
- String clientId = System.getenv("IM_CLIENT_ID");
- String clientSecret = System.getenv("IM_CLIENT_SECRET");
-
- propertiesWithUserNameValidation = EMProperties.builder()
- .setRealm(EMProperties.Realm.EASEMOB_REALM)
- .setBaseUri(baseUri)
- .setAppkey(appkey)
- .setClientId(clientId)
- .setClientSecret(clientSecret)
- .setHttpConnectionPoolSize(10)
- .setServerTimezone("+8")
- .build();
-
- propertiesNoUserNameValidation = EMProperties.builder()
- .turnOffUserNameValidation()
- .setRealm(EMProperties.Realm.EASEMOB_REALM)
- .setBaseUri(baseUri)
- .setAppkey(appkey)
- .setClientId(clientId)
- .setClientSecret(clientSecret)
- .setHttpConnectionPoolSize(10)
- .setServerTimezone("+8")
- .build();
- }
-
- this.serviceWithUserNameValidation = new EMService(propertiesWithUserNameValidation);
- this.serviceNoUserNameValidation = new EMService(propertiesNoUserNameValidation);
- }
-
- @Test
- public void withUserNameValidation() {
- String goodUserName = Utilities.randomUserName();
- String badUserName = "000" + Utilities.randomUserName();
- String password = Utilities.randomPassword();
- assertThrows(EMInvalidArgumentException.class,
- () -> serviceWithUserNameValidation.user().create(badUserName, password)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(()-> serviceWithUserNameValidation.user().create(goodUserName, password)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(()-> serviceWithUserNameValidation.user().delete(goodUserName)
- .block(Utilities.IT_TIMEOUT));
-
- }
-
- @Test
- public void noUserNameValidation() {
- String goodUserName = Utilities.randomUserName();
- String badUserName = "000" + Utilities.randomUserName();
- String password = Utilities.randomPassword();
- assertDoesNotThrow(()-> serviceNoUserNameValidation.user().create(goodUserName, password)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(()-> serviceNoUserNameValidation.user().create(badUserName, password)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(()-> serviceNoUserNameValidation.user().delete(goodUserName)
- .block(Utilities.IT_TIMEOUT));
- assertDoesNotThrow(()-> serviceNoUserNameValidation.user().delete(badUserName)
- .block(Utilities.IT_TIMEOUT));
- }*/
-}
diff --git a/im-sdk-core/src/integration-test/resources/download/attachment/image.png b/im-sdk-core/src/integration-test/resources/download/attachment/image.png
deleted file mode 100644
index aa4d6b94a..000000000
Binary files a/im-sdk-core/src/integration-test/resources/download/attachment/image.png and /dev/null differ
diff --git a/im-sdk-core/src/integration-test/resources/upload/image.png b/im-sdk-core/src/integration-test/resources/upload/image.png
deleted file mode 100644
index aa4d6b94a..000000000
Binary files a/im-sdk-core/src/integration-test/resources/upload/image.png and /dev/null differ
diff --git a/im-sdk-core/src/main/java-templates/com/easemob/im/server/EMVersion.java b/im-sdk-core/src/main/java-templates/com/easemob/im/server/EMVersion.java
deleted file mode 100644
index ed5a85f00..000000000
--- a/im-sdk-core/src/main/java-templates/com/easemob/im/server/EMVersion.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.easemob.im.server;
-
-public class EMVersion {
- public static String version = "${project.version}";
-
- public static String getVersion() {
- return EMVersion.version;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/AgoraAppCredentials.java b/im-sdk-core/src/main/java/com/easemob/im/server/AgoraAppCredentials.java
deleted file mode 100644
index ad6c10a96..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/AgoraAppCredentials.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.easemob.im.server;
-
-import com.easemob.im.server.api.util.Utilities;
-import com.easemob.im.server.exception.EMInvalidArgumentException;
-import io.netty.util.internal.StringUtil;
-
-public class AgoraAppCredentials implements Credentials {
- private final String appId;
- private final String appCert;
-
- public AgoraAppCredentials(String appId, String appCert) {
- if (StringUtil.isNullOrEmpty(appId) || StringUtil.isNullOrEmpty(appCert)) {
- throw new EMInvalidArgumentException("appId/appCert cannot be blank");
- }
- this.appId = appId;
- this.appCert = appCert;
- }
-
- @Override
- public String getId() {
- return appId;
- }
-
- @Override
- public String getSecret() {
- return appCert;
- }
-
- @Override public String toString() {
- return "AgoraAppCredentials{" +
- "appId='" + Utilities.mask(appId) + '\'' +
- ", appCert='" + Utilities.mask(appCert) + '\'' +
- '}';
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/Credentials.java b/im-sdk-core/src/main/java/com/easemob/im/server/Credentials.java
deleted file mode 100644
index d26ef94d0..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/Credentials.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.easemob.im.server;
-
-public interface Credentials {
-
- String getId();
-
- String getSecret();
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EMErrorResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/EMErrorResponse.java
deleted file mode 100644
index 710eb1817..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EMErrorResponse.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.easemob.im.server;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class EMErrorResponse {
- @JsonProperty("error_description")
- private String errorDescription;
-
- public EMErrorResponse(@JsonProperty("error_description") String errorDescription) {
- this.errorDescription = errorDescription;
- }
-
- public String getErrorDescription() {
- return errorDescription;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EMException.java b/im-sdk-core/src/main/java/com/easemob/im/server/EMException.java
deleted file mode 100644
index f82e88003..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EMException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.easemob.im.server;
-
-public class EMException extends RuntimeException {
- /**
- *错误码(HttpResponseStatus.code)
- */
- private Integer errorCode;
-
- public EMException(String message) {
- super(message);
- }
-
- public EMException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public Integer getErrorCode() {
- return errorCode;
- }
-
- public void setErrorCode(Integer errorCode) {
- this.errorCode = errorCode;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EMProperties.java b/im-sdk-core/src/main/java/com/easemob/im/server/EMProperties.java
deleted file mode 100644
index 7b82d0dfd..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EMProperties.java
+++ /dev/null
@@ -1,533 +0,0 @@
-package com.easemob.im.server;
-
-import com.easemob.im.server.api.util.Utilities;
-import com.easemob.im.server.exception.EMInvalidArgumentException;
-import com.easemob.im.server.exception.EMInvalidStateException;
-import com.easemob.im.server.exception.EMUnsupportedEncodingException;
-import io.netty.util.internal.StringUtil;
-import reactor.netty.transport.logging.AdvancedByteBufFormat;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-public class EMProperties {
-
- private final Realm realm;
- private final String appKey;
- private final Credentials credentials;
- private final String baseUri;
- private final EMProxy proxy;
- private final int httpConnectionPoolSize;
- private final int httpConnectionMaxIdleTime;
- private final int httpConnectionMaxLifeTime;
- private final int httpConnectionEvictInBackground;
- private final int httpConnectionPendingAcquireMaxCount;
- private final int httpConnectionPendingAcquireTimeout;
- private final int nettyWorkerCount;
- private final String serverTimezone;
- private final int agoraTokenExpireInSeconds;
- private final AdvancedByteBufFormat httpLogFormat;
- private final boolean validateUserName;
-
- public EMProperties(Realm realm, String appKey, Credentials credentials, String baseUri,
- EMProxy proxy, int httpConnectionPoolSize, int httpConnectionMaxIdleTime,
- int httpConnectionMaxLifeTime, int httpConnectionEvictInBackground,
- int httpConnectionPendingAcquireMaxCount, int httpConnectionPendingAcquireTimeout,
- int nettyWorkerCount, String serverTimezone, int agoraTokenExpireInSeconds,
- AdvancedByteBufFormat httpLogFormat, boolean validateUserName) {
- this.realm = realm;
- this.appKey = appKey;
- this.credentials = credentials;
- this.baseUri = baseUri;
- this.proxy = proxy;
- this.httpConnectionPoolSize = httpConnectionPoolSize;
- this.httpConnectionMaxIdleTime = httpConnectionMaxIdleTime;
- this.httpConnectionMaxLifeTime = httpConnectionMaxLifeTime;
- this.httpConnectionEvictInBackground = httpConnectionEvictInBackground;
- this.httpConnectionPendingAcquireMaxCount = httpConnectionPendingAcquireMaxCount;
- this.httpConnectionPendingAcquireTimeout = httpConnectionPendingAcquireTimeout;
- this.nettyWorkerCount = nettyWorkerCount;
- this.serverTimezone = serverTimezone;
- this.agoraTokenExpireInSeconds = agoraTokenExpireInSeconds;
- this.httpLogFormat = httpLogFormat;
- this.validateUserName = validateUserName;
- }
-
- /**
- * @param baseUri baseUri
- * @param appKey appKey
- * @param proxy proxy
- * @param clientId clientId
- * @param clientSecret clientSecret
- * @param httpConnectionPoolSize httpConnectionPoolSize
- * @param serverTimezone serverTimezone
- * @param httpConnectionMaxIdleTime httpConnectionMaxIdleTime
- * @param httpConnectionMaxLifeTime
- * @param httpConnectionEvictInBackground
- * @param nettyWorkerCount nettyWorkerCount
- * @param httpConnectionPendingAcquireMaxCount httpConnectionPendingAcquireMaxCount
- * @param httpConnectionPendingAcquireTimeout
- * @deprecated use {@link #builder()} instead.
- */
- @Deprecated
- public EMProperties(String baseUri, String appKey, EMProxy proxy, String clientId,
- String clientSecret, int httpConnectionPoolSize, String serverTimezone,
- int httpConnectionMaxIdleTime, int httpConnectionMaxLifeTime,
- int httpConnectionEvictInBackground, int nettyWorkerCount, int httpConnectionPendingAcquireMaxCount,
- int httpConnectionPendingAcquireTimeout) {
- this.httpConnectionMaxLifeTime = httpConnectionMaxLifeTime;
- this.httpConnectionEvictInBackground = httpConnectionEvictInBackground;
- this.nettyWorkerCount = nettyWorkerCount;
- this.httpConnectionPendingAcquireTimeout = httpConnectionPendingAcquireTimeout;
- this.realm = Realm.EASEMOB_REALM;
- this.appKey = appKey;
- this.credentials = new EasemobAppCredentials(clientId, clientSecret);
- this.baseUri = baseUri;
- this.proxy = proxy;
- this.httpConnectionPoolSize = httpConnectionPoolSize;
- this.serverTimezone = serverTimezone;
- this.agoraTokenExpireInSeconds = Utilities.DEFAULT_AGORA_TOKEN_EXPIRE_IN_SECONDS;
- this.httpLogFormat = AdvancedByteBufFormat.SIMPLE;
- this.validateUserName = true;
- this.httpConnectionMaxIdleTime = httpConnectionMaxIdleTime;
- this.httpConnectionPendingAcquireMaxCount = httpConnectionPendingAcquireMaxCount;
- }
-
- // easemob realm by default
- public static Builder builder() {
- return new Builder().setRealm(Realm.EASEMOB_REALM);
- }
-
- public String getAppkey() {
- return this.appKey;
- }
-
- public String getClientId() {
- if (this.realm.equals(Realm.EASEMOB_REALM)) {
- return this.credentials.getId();
-
- } else if (this.realm.equals(Realm.AGORA_REALM)) {
- return null;
- } else {
- throw new EMInvalidStateException(
- String.format("invalid realm type %s", this.realm.toString()));
- }
- }
-
- public String getClientSecret() {
- if (this.realm.equals(Realm.EASEMOB_REALM)) {
- return this.credentials.getSecret();
-
- } else if (this.realm.equals(Realm.AGORA_REALM)) {
- return null;
- } else {
- throw new EMInvalidStateException(
- String.format("invalid realm type %s", this.realm.toString()));
- }
- }
-
- public String getAppId() {
- if (this.realm.equals(Realm.AGORA_REALM)) {
- return this.credentials.getId();
-
- } else if (this.realm.equals(Realm.EASEMOB_REALM)) {
- return null;
- } else {
- throw new EMInvalidStateException(
- String.format("invalid realm type %s", this.realm.toString()));
- }
- }
-
- public String getAppCert() {
- if (this.realm.equals(Realm.AGORA_REALM)) {
- return this.credentials.getSecret();
-
- } else if (this.realm.equals(Realm.EASEMOB_REALM)) {
- return null;
- } else {
- throw new EMInvalidStateException(
- String.format("invalid realm type %s", this.realm.toString()));
- }
- }
-
- public Realm getRealm() {
- return realm;
- }
-
- public Credentials getCredentials() {
- return credentials;
- }
-
- public String getBaseUri() {
- return baseUri;
- }
-
- public EMProxy getProxy() {
- return this.proxy;
- }
-
- public String getAppkeyUrlEncoded() {
- try {
- return URLEncoder.encode(this.appKey, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new EMUnsupportedEncodingException(e.getMessage());
- }
- }
-
- public String getAppkeySlashDelimited() {
- return this.appKey.replace('#', '/');
- }
-
- public int getHttpConnectionPoolSize() {
- return this.httpConnectionPoolSize;
- }
-
- public int getHttpConnectionMaxIdleTime() {
- return this.httpConnectionMaxIdleTime;
- }
-
- public int getHttpConnectionMaxLifeTime() {
- return httpConnectionMaxLifeTime;
- }
-
- public int getHttpConnectionEvictInBackground() {
- return httpConnectionEvictInBackground;
- }
-
- public int getHttpConnectionPendingAcquireMaxCount() {
- return httpConnectionPendingAcquireMaxCount;
- }
-
- public int getHttpConnectionPendingAcquireTimeout() {
- return httpConnectionPendingAcquireTimeout;
- }
-
- public String getServerTimezone() {
- return this.serverTimezone;
- }
-
- public String getAppKey() {
- return appKey;
- }
-
- public int getAgoraTokenExpireInSeconds() {
- return agoraTokenExpireInSeconds;
- }
-
- public AdvancedByteBufFormat getHttpLogFormat() {
- return httpLogFormat;
- }
-
- public boolean getValidateUserName() {
- return validateUserName;
- }
-
- public int getNettyWorkerCount() {
- return nettyWorkerCount;
- }
-
- @Override
- public String toString() {
- return "EMProperties{" +
- "realm=" + realm +
- ", appKey='" + appKey + '\'' +
- ", credentials=" + credentials +
- ", baseUri='" + baseUri + '\'' +
- ", proxy=" + proxy +
- ", httpConnectionPoolSize=" + httpConnectionPoolSize +
- ", httpConnectionMaxIdleTime=" + httpConnectionMaxIdleTime +
- ", httpConnectionPendingAcquireMaxCount=" + httpConnectionPendingAcquireMaxCount +
- ", serverTimezone='" + serverTimezone + '\'' +
- ", agoraTokenExpireInSeconds=" + agoraTokenExpireInSeconds +
- ", httpLogFormat=" + httpLogFormat +
- ", validateUserName=" + validateUserName +
- '}';
- }
-
- public enum Realm {
- AGORA_REALM(1),
- EASEMOB_REALM(2),
- ;
- public short intValue;
-
- Realm(int value) {
- intValue = (short) value;
- }
- }
-
-
- public static class Builder {
- private Realm realm;
- private String appKey;
- private String clientId;
- private String clientSecret;
- private String appId;
- private String appCert;
-
- private String baseUri;
- private EMProxy proxy;
- private int httpConnectionPoolSize = 50;
- private int httpConnectionMaxIdleTime = 10 * 1000;
- private int httpConnectionMaxLifeTime = 60 * 1000;
- private int httpConnectionEvictInBackground = 60 * 1000;
- private int nettyWorkerCount = 0;
- private int httpConnectionPendingAcquireMaxCount = 100;
- private int httpConnectionPendingAcquireTimeout = 60 * 1000;
- private String serverTimezone = "+8";
- private int agoraTokenExpireInSeconds = Utilities.DEFAULT_AGORA_TOKEN_EXPIRE_IN_SECONDS;
- private AdvancedByteBufFormat httpLogFormat = AdvancedByteBufFormat.SIMPLE;
- private boolean validateUserName = true;
-
- public Builder setRealm(Realm realm) {
- this.realm = realm;
- return this;
- }
-
- public Builder setAppkey(String appKey) {
- if (StringUtil.isNullOrEmpty(appKey)) {
- throw new EMInvalidArgumentException("appKey must not be null or blank");
- }
- String[] tokens = appKey.split("#");
- if (tokens.length != 2) {
- throw new EMInvalidArgumentException("appKey must contains #");
- }
- if (tokens[0].isEmpty()) {
- throw new EMInvalidArgumentException("appKey must contains {org}");
- }
- if (tokens[1].isEmpty()) {
- throw new EMInvalidArgumentException("appKey must contains {app}");
- }
- this.appKey = appKey;
- return this;
- }
-
- public Builder setClientId(String clientId) {
- if (StringUtil.isNullOrEmpty(clientId)) {
- throw new EMInvalidArgumentException("clientId must not be null or blank");
- }
- this.clientId = clientId;
- return this;
- }
-
- public Builder setClientSecret(String clientSecret) {
- if (StringUtil.isNullOrEmpty(clientSecret)) {
- throw new EMInvalidArgumentException("clientSecret must not be null or blank");
- }
- this.clientSecret = clientSecret;
- return this;
- }
-
- public Builder setAppId(String appId) {
- if (StringUtil.isNullOrEmpty(appId)) {
- throw new EMInvalidArgumentException("appId must not be null or blank");
- }
- this.appId = appId;
- return this;
- }
-
- public Builder setAppCert(String appCert) {
- if (StringUtil.isNullOrEmpty(appCert)) {
- throw new EMInvalidArgumentException("appCert must not be null or blank");
- }
- this.appCert = appCert;
- return this;
- }
-
- public Builder setBaseUri(String baseUri) {
- this.baseUri = baseUri;
- return this;
- }
-
- public Builder setProxy(EMProxy proxy) {
- this.proxy = proxy;
- return this;
- }
-
- public Builder setHttpConnectionPoolSize(int httpConnectionPoolSize) {
- if (httpConnectionPoolSize < 0) {
- throw new EMInvalidArgumentException("httpConnectionPoolSize must not be negative");
- }
- this.httpConnectionPoolSize = httpConnectionPoolSize;
- return this;
- }
-
- public Builder setServerTimezone(String timezone) {
- this.serverTimezone = timezone;
- return this;
- }
-
- public Builder setAgoraTokenExpireInSeconds(int agoraTokenExpireInSeconds) {
- this.agoraTokenExpireInSeconds = agoraTokenExpireInSeconds;
- return this;
- }
-
- public Builder setHttpLogFormat(AdvancedByteBufFormat httpLogFormat) {
- this.httpLogFormat = httpLogFormat;
- return this;
- }
-
- public Builder turnOffUserNameValidation() {
- this.validateUserName = false;
- return this;
- }
-
- /**
- * @param httpConnectionMaxIdleTime httpConnection最大空闲时间,单位:毫秒
- * @return Builder
- */
- public Builder httpConnectionMaxIdleTime(int httpConnectionMaxIdleTime) {
- if (httpConnectionMaxIdleTime <= 0) {
- throw new EMInvalidArgumentException("httpConnectionMaxIdleTime must not be negative");
- }
- this.httpConnectionMaxIdleTime = httpConnectionMaxIdleTime;
- return this;
- }
-
- /**
- * @param httpConnectionMaxIdleTime httpConnection最大空闲时间,单位:毫秒
- * @return Builder
- */
- public Builder setHttpConnectionMaxIdleTime(int httpConnectionMaxIdleTime) {
- if (httpConnectionMaxIdleTime <= 0) {
- throw new EMInvalidArgumentException("httpConnectionMaxIdleTime must not be negative");
- }
- this.httpConnectionMaxIdleTime = httpConnectionMaxIdleTime;
- return this;
- }
-
- /**
- * @param httpConnectionMaxLifeTime httpConnection最大存活时间,单位:毫秒
- * @return Builder
- */
- public Builder setHttpConnectionMaxLifeTime(int httpConnectionMaxLifeTime) {
- if (httpConnectionMaxLifeTime <= 0) {
- throw new EMInvalidArgumentException("httpConnectionMaxLifeTime must not be negative");
- }
- this.httpConnectionMaxLifeTime = httpConnectionMaxLifeTime;
- return this;
- }
-
- /**
- * @param nettyWorkerCount netty最大工作线程数
- * @return Builder
- */
- public Builder setNettyWorkerCount(int nettyWorkerCount) {
- if (nettyWorkerCount <= 0) {
- throw new EMInvalidArgumentException("nettyWorkerCount must not be negative");
- }
- this.nettyWorkerCount = nettyWorkerCount;
- return this;
- }
-
- /**
- * @param httpConnectionPendingAcquireMaxCount pendingAcquire最大数量
- * @return Builder
- */
- public Builder setHttpConnectionPendingAcquireMaxCount(int httpConnectionPendingAcquireMaxCount) {
- if (httpConnectionPendingAcquireMaxCount <= 0) {
- throw new EMInvalidArgumentException("httpConnectionPendingAcquireMaxCount must not be negative");
- }
- this.httpConnectionPendingAcquireMaxCount = httpConnectionPendingAcquireMaxCount;
- return this;
- }
-
- /**
- * @param httpConnectionPendingAcquireTimeout pendingAcquire超时时间,单位:毫秒
- * @return Builder
- */
- public Builder setHttpConnectionPendingAcquireTimeout(int httpConnectionPendingAcquireTimeout) {
- if (httpConnectionPendingAcquireTimeout <= 0) {
- throw new EMInvalidArgumentException("httpConnectionPendingAcquireTimeout must not be negative");
- }
- this.httpConnectionPendingAcquireTimeout = httpConnectionPendingAcquireTimeout;
- return this;
- }
-
- /**
- * @param httpConnectionEvictInBackground 后台检查连接池中适用于删除连接的时间间隔,单位:毫秒
- * @return Builder
- */
- public Builder setHttpConnectionEvictInBackground(int httpConnectionEvictInBackground) {
- if (httpConnectionEvictInBackground <= 0) {
- throw new EMInvalidArgumentException("httpConnectionEvictInBackground must not be negative");
- }
- this.httpConnectionEvictInBackground = httpConnectionEvictInBackground;
- return this;
- }
-
- public EMProperties build() {
- if (this.realm == null) {
- throw new EMInvalidStateException("realm not set");
- }
- if (this.appKey == null) {
- throw new EMInvalidStateException("appKey not set");
- }
- if (this.realm.equals(Realm.EASEMOB_REALM)) {
- if (this.clientId == null) {
- throw new EMInvalidStateException("clientId not set");
- }
- if (this.clientSecret == null) {
- throw new EMInvalidStateException("clientSecret not set");
- }
- if (this.appId != null || this.appCert != null) {
- throw new EMInvalidStateException("appId and appCert must be blank");
- }
- Credentials credentials =
- new EasemobAppCredentials(this.clientId, this.clientSecret);
- return new EMProperties(this.realm, this.appKey, credentials, this.baseUri,
- this.proxy, this.httpConnectionPoolSize, this.httpConnectionMaxIdleTime,
- this.httpConnectionMaxLifeTime, this.httpConnectionEvictInBackground,
- this.httpConnectionPendingAcquireMaxCount,
- this.httpConnectionPendingAcquireTimeout,
- this.nettyWorkerCount, this.serverTimezone,
- this.agoraTokenExpireInSeconds, this.httpLogFormat, this.validateUserName);
- } else if (this.realm.equals(Realm.AGORA_REALM)) {
- if (this.appId == null) {
- throw new EMInvalidStateException("appId not set");
- }
- if (this.appCert == null) {
- throw new EMInvalidStateException("appCert not set");
- }
- if (this.clientId != null || this.clientSecret != null) {
- throw new EMInvalidStateException("clientId and clientSecret must be blank");
- }
- Credentials credentials = new AgoraAppCredentials(this.appId, this.appCert);
- return new EMProperties(this.realm, this.appKey, credentials, this.baseUri,
- this.proxy, this.httpConnectionPoolSize, this.httpConnectionMaxIdleTime,
- this.httpConnectionMaxLifeTime, this.httpConnectionEvictInBackground,
- this.httpConnectionPendingAcquireMaxCount,
- this.httpConnectionPendingAcquireTimeout,
- this.nettyWorkerCount, this.serverTimezone,
- this.agoraTokenExpireInSeconds, this.httpLogFormat, this.validateUserName);
- } else {
- throw new EMInvalidStateException(
- String.format("invalid realm type %s", this.realm.toString()));
- }
- }
-
- @Override
- public String toString() {
- return "Builder{" +
- "realm=" + realm +
- ", appKey='" + appKey + '\'' +
- ", clientId='" + Utilities.mask(clientId) + '\'' +
- ", clientSecret='" + Utilities.mask(clientSecret) + '\'' +
- ", appId='" + Utilities.mask(appId) + '\'' +
- ", appCert='" + Utilities.mask(appCert) + '\'' +
- ", baseUri='" + baseUri + '\'' +
- ", proxy=" + proxy +
- ", httpConnectionPoolSize=" + httpConnectionPoolSize +
- ", httpConnectionMaxIdleTime=" + httpConnectionMaxIdleTime +
- ", httpConnectionMaxLifeTime=" + httpConnectionMaxLifeTime +
- ", httpConnectionEvictInBackground=" + httpConnectionEvictInBackground +
- ", nettyWorkerCount=" + nettyWorkerCount +
- ", httpConnectionPendingAcquireMaxCount=" + httpConnectionPendingAcquireMaxCount +
- ", httpConnectionPendingAcquireTimeout=" + httpConnectionPendingAcquireTimeout +
- ", serverTimezone='" + serverTimezone + '\'' +
- ", agoraTokenExpireInSeconds=" + agoraTokenExpireInSeconds +
- ", httpLogFormat=" + httpLogFormat +
- ", validateUserName=" + validateUserName +
- '}';
- }
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EMProxy.java b/im-sdk-core/src/main/java/com/easemob/im/server/EMProxy.java
deleted file mode 100644
index 4fca1f906..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EMProxy.java
+++ /dev/null
@@ -1,100 +0,0 @@
-package com.easemob.im.server;
-
-import com.easemob.im.server.exception.EMInvalidArgumentException;
-import io.netty.util.internal.StringUtil;
-
-public class EMProxy {
- private String ip;
- private int port;
- private String username;
- private String password;
-
- public EMProxy(String ip, int port, String username, String password) {
- this.ip = ip;
- this.port = port;
- this.username = username;
- this.password = password;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public String getIp() {
- return ip;
- }
-
- public int getPort() {
- return port;
- }
-
- public String getUsername() {
- return username;
- }
-
- public String getPassword() {
- return password;
- }
-
- @Override
- public String toString() {
- return "EMProxy{" +
- "ip='" + ip + '\'' +
- ", port=" + port +
- ", username='" + username + '\'' +
- ", password='" + password + '\'' +
- '}';
- }
-
- public static class Builder {
- private String ip;
- private int port;
- private String username;
- private String password;
-
- public Builder setIP(String ip) {
- if (StringUtil.isNullOrEmpty(ip)) {
- throw new EMInvalidArgumentException("ip must not be null or blank");
- }
- this.ip = ip;
- return this;
- }
-
- public Builder setPort(int port) {
- if (port < 0 || port > 65535) {
- throw new EMInvalidArgumentException(String.format("port %s is illegal", port));
- }
- this.port = port;
- return this;
- }
-
- public Builder setUsername(String username) {
- this.username = username;
- return this;
- }
-
- public Builder setPassword(String password) {
- this.password = password;
- return this;
- }
-
- public EMProxy build() {
- if (StringUtil.isNullOrEmpty(this.ip)) {
- throw new EMInvalidArgumentException(
- "the IP of setting proxy cannot be null or blank");
- }
- return new EMProxy(this.ip, this.port, this.username, this.password);
- }
-
- @Override
- public String toString() {
- return "Builder{" +
- "ip='" + ip + '\'' +
- ", port=" + port +
- ", username='" + username + '\'' +
- ", password='" + password + '\'' +
- '}';
- }
- }
-}
-
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EMService.java b/im-sdk-core/src/main/java/com/easemob/im/server/EMService.java
deleted file mode 100644
index a87de67fc..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EMService.java
+++ /dev/null
@@ -1,268 +0,0 @@
-package com.easemob.im.server;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultContext;
-import com.easemob.im.server.api.block.BlockApi;
-import com.easemob.im.server.api.attachment.AttachmentApi;
-import com.easemob.im.server.api.message.MessageApi;
-import com.easemob.im.server.api.metadata.MetadataApi;
-import com.easemob.im.server.api.moderation.ModerationApi;
-import com.easemob.im.server.api.mute.MuteApi;
-import com.easemob.im.server.api.push.PushApi;
-import com.easemob.im.server.api.token.TokenApi;
-import com.easemob.im.server.api.room.RoomApi;
-import com.easemob.im.server.api.group.GroupApi;
-import com.easemob.im.server.api.contact.ContactApi;
-import com.easemob.im.server.api.user.UserApi;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Server SDK API服务类
- */
-public class EMService {
-
- private static final Logger log = LoggerFactory.getLogger(EMService.class);
-
- private final Context context;
-
- private final BlockApi blockV1;
-
- private final ContactApi contactApi;
-
- private final AttachmentApi attachmentApi;
-
- private final GroupApi groupApi;
-
- private final MessageApi messageApi;
-
- private final RoomApi roomApi;
-
- private final UserApi userApi;
-
- private final MetadataApi metadataApi;
-
- private final TokenApi tokenApi;
-
- private final PushApi pushApi;
-
- private final ModerationApi moderationApi;
-
- private final MuteApi muteApi;
-
- public EMService(EMProperties properties) {
- log.debug("EMService properties: {}", properties);
- this.context = new DefaultContext(properties);
-
- this.blockV1 = new BlockApi(this.context);
- this.contactApi = new ContactApi(this.context);
- this.attachmentApi = new AttachmentApi(this.context);
- this.messageApi = new MessageApi(this.context);
- this.groupApi = new GroupApi(this.context);
- this.roomApi = new RoomApi(this.context);
- this.userApi = new UserApi(this.context);
- this.metadataApi = new MetadataApi(this.context);
- this.tokenApi = new TokenApi(this.context);
- this.pushApi = new PushApi(this.context);
- this.moderationApi = new ModerationApi(this.context);
- this.muteApi = new MuteApi(this.context);
- }
-
- public Context getContext() {
- return context;
- }
-
- /**
- * 封禁API.
- * 支持:
- * - 用户禁言
- * - 群禁言(可以定时解除)
- * - 聊天室禁言(可以定时解除)
- * - 禁止加入群
- * - 禁止加入聊天室
- * - 禁止登录
- *
- * @return {@code BlockApi}
- */
- public BlockApi block() {
- return this.blockV1;
- }
-
- /**
- * 通讯录API.
- * 支持:
- * - 添加联系人
- * - 移除联系人
- * - 获取联系人列表
- *
- * 目前联系人只作为通讯录之用.
- *
- * @return {@code ContactApi}
- */
- public ContactApi contact() {
- return this.contactApi;
- }
-
- /**
- * 附件API.
- * 支持:
- * - 附件上传
- * - 附件下载
- *
- * 目前,只支持本地文件的上传和下载.
- *
- * @return {@code AttachmentApi}
- */
- public AttachmentApi attachment() {
- return this.attachmentApi;
- }
-
- /**
- * 群API.
- *
支持群管理:
- * - 创建群
- * - 删除群
- * - 获取群列表
- * - 获取群详情
- * - 获取用户加入的群
- * - 修改群详情
- * - 修改群主
- *
- *
支持群成员管理:
- * - 获取群成员列表
- * - 添加群成员
- * - 删除群成员
- *
- *
支持群管理员管理:
- * - 获取群管理员列表
- * - 添加群管理员
- * - 删除群管理员
- *
- * 群与聊天室都是多人聊天,与聊天室主要差别在于群支持离线消息,即群成员上线时可以收到离线时错过的消息。
- * 如果配置了推送,则离线消息也会产生推送。
- * 群分为公开群和私有群,区别在于:在设备SDK中(指iOS、Android、Web、小程序等),私有群不会出现在群列表API的返回结果。
- *
- * @return {@code GroupApi}
- * @see com.easemob.im.server.api.block.BlockApi
- */
- public GroupApi group() {
- return this.groupApi;
- }
-
- /**
- * 消息API.
- * 支持:
- * - 发送消息
- * - 查询离线消息数
- * - 获取/下载聊天历史
- *
- * @return {@code MessageApi}
- */
- public MessageApi message() {
- return this.messageApi;
- }
-
- /**
- * 用户API.
- * 支持:
- * - 创建用户
- * - 删除用户
- * - 获取用户
- * - 修改用户密码
- * - 强制用户下线
- * - 获取用户在线状态
- * - 获取用户token
- *
- * @return {@code UserApi}
- */
- public UserApi user() {
- return this.userApi;
- }
-
- /**
- * 聊天室API.
- * 支持聊天室管理:
- * - 创建聊天室
- * - 获取聊天室详情
- * - 修改聊天室
- * - 获取聊天室列表
- * - 获取用户加入的聊天室列表
- *
- *
支持聊天室成员管理:
- * - 获取聊天室成员列表
- * - 添加聊天室成员
- * - 移除聊天室成员
- *
- *
支持聊天室管理员管理:
- * - 获取聊天室管理员
- * - 添加聊天室管理员
- *
- * @return {@code RoomApi}
- * @see com.easemob.im.server.api.block.BlockApi
- */
- public RoomApi room() {
- return this.roomApi;
- }
-
- /**
- * 用户属性API.
- * 支持:
- * - 设置用户属性
- * - 获取用户属性
- * - 获取app用户属性容量
- * - 删除用户属性
- *
- * @return {@code MetadataApi}
- */
- public MetadataApi metadata() {
- return this.metadataApi;
- }
-
- /**
- * token API.
- * 支持:
- * - TODO: generate user token
- *
- * @return {@code TokenApi}
- */
- public TokenApi token() {
- return this.tokenApi;
- }
-
- /**
- * 推送API.
- * 支持:
- * - 设置推送昵称
- *
- * @return {@code PushApi}
- */
- public PushApi push() {
- return this.pushApi;
- }
-
- /**
- * 内容审核记录API.
- * 支持:
- * - 按查询条件导出文件
- * - 获取导出详情列表
- * - 下载内容审核记录文件
- *
- * @return {@code ModerationApi}
- */
- public ModerationApi moderation() {
- return this.moderationApi;
- }
-
- /**
- * 用户全局禁言API.
- * 支持:
- * - 设置用户全局禁言
- * - 查询单个用户全局禁言剩余时间
- * - 查询所有用户全局禁言剩余时间
- *
- * @return {@code MuteApi}
- */
- public MuteApi mute() {
- return this.muteApi;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/EasemobAppCredentials.java b/im-sdk-core/src/main/java/com/easemob/im/server/EasemobAppCredentials.java
deleted file mode 100644
index 3e1c3e266..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/EasemobAppCredentials.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.easemob.im.server;
-
-import com.easemob.im.server.api.util.Utilities;
-import com.easemob.im.server.exception.EMInvalidArgumentException;
-import io.netty.util.internal.StringUtil;
-
-public class EasemobAppCredentials implements Credentials {
- private final String clientId;
- private final String clientSecret;
-
- public EasemobAppCredentials(String clientId, String clientSecret) {
- if (StringUtil.isNullOrEmpty(clientId) || StringUtil.isNullOrEmpty(clientSecret)) {
- throw new EMInvalidArgumentException("clientId/clientSecret cannot be blank");
- }
- this.clientId = clientId;
- this.clientSecret = clientSecret;
- }
-
- @Override
- public String getId() {
- return this.clientId;
- }
-
- @Override
- public String getSecret() {
- return this.clientSecret;
- }
-
- @Override
- public String toString() {
- return "EasemobAppCredentials{" +
- "clientId='" + Utilities.mask(clientId) + '\'' +
- ", clientSecret='" + Utilities.mask(clientSecret) + '\'' +
- '}';
- }
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/BearerAuthorization.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/BearerAuthorization.java
deleted file mode 100644
index 51ee13192..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/BearerAuthorization.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.easemob.im.server.api;
-
-import com.easemob.im.server.api.token.allocate.TokenProvider;
-import io.netty.handler.codec.http.HttpHeaders;
-import reactor.core.publisher.Mono;
-
-import java.util.function.Function;
-
-public class BearerAuthorization implements Function> {
-
- private TokenProvider tokenProvider;
-
- public BearerAuthorization(TokenProvider tokenProvider) {
- this.tokenProvider = tokenProvider;
- }
-
- @Override
- public Mono extends HttpHeaders> apply(HttpHeaders headers) {
- return this.tokenProvider.fetchAppToken()
- .map(t -> headers.add("Authorization", String.format("Bearer %s", t.getValue())));
- }
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/Codec.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/Codec.java
deleted file mode 100644
index 6a5fcb7d4..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/Codec.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.easemob.im.server.api;
-
-import io.netty.buffer.ByteBuf;
-
-public interface Codec {
- ByteBuf encode(Object object);
-
- T decode(ByteBuf buffer, Class tClass);
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/Context.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/Context.java
deleted file mode 100644
index 39734b29c..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/Context.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.easemob.im.server.api;
-
-import com.easemob.im.server.EMProperties;
-import com.easemob.im.server.api.token.allocate.TokenProvider;
-import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClient;
-
-public interface Context {
-
- Mono getHttpClient();
-
- EMProperties getProperties();
-
- TokenProvider getTokenProvider();
-
- Codec getCodec();
-
- ErrorMapper getErrorMapper();
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultContext.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultContext.java
deleted file mode 100644
index 327699761..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultContext.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.easemob.im.server.api;
-
-import com.easemob.im.server.EMProperties;
-import com.easemob.im.server.api.codec.JsonCodec;
-import com.easemob.im.server.api.loadbalance.*;
-import com.easemob.im.server.api.token.allocate.AgoraTokenProvider;
-import com.easemob.im.server.api.token.allocate.DefaultTokenProvider;
-import com.easemob.im.server.api.token.allocate.TokenProvider;
-import com.easemob.im.server.exception.EMInvalidStateException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClient;
-
-import java.time.Duration;
-
-public class DefaultContext implements Context {
-
- private static final Logger log = LoggerFactory.getLogger(DefaultContext.class);
-
- private final EMProperties properties;
-
- private final HttpClient httpClient;
-
- private final TokenProvider tokenProvider;
-
- private final Codec codec;
-
- private final ErrorMapper errorMapper;
-
- private final LoadBalancer loadBalancer;
-
- private final EndpointProvider endpointProvider;
-
- private final EndpointRegistry endpointRegistry;
-
- public DefaultContext(EMProperties properties) {
- this.properties = properties;
- HttpClient httpClient = EMHttpClientFactory.create(properties);
- this.codec = new JsonCodec();
- this.errorMapper = new DefaultErrorMapper();
- this.loadBalancer = new UniformRandomLoadBalancer();
- EndpointProviderFactory endpointProviderFactory =
- new DefaultEndpointProviderFactory(this.properties, this.codec,
- httpClient.baseUrl("http://rs.easemob.com"), this.errorMapper);
- this.endpointProvider = endpointProviderFactory.create();
- this.endpointRegistry =
- new TimedRefreshEndpointRegistry(this.endpointProvider, Duration.ofMinutes(5));
-
- EMProperties.Realm realm = properties.getRealm();
- if (realm == EMProperties.Realm.AGORA_REALM) {
- this.tokenProvider =
- new AgoraTokenProvider(properties, httpClient, this.endpointRegistry,
- this.loadBalancer, this.codec, this.errorMapper);
- } else if (realm == EMProperties.Realm.EASEMOB_REALM) {
- this.tokenProvider =
- new DefaultTokenProvider(properties, httpClient, this.endpointRegistry,
- this.loadBalancer, this.codec, this.errorMapper);
- } else {
- throw new EMInvalidStateException(
- String.format("Realm value = %d is illegal", realm.intValue));
- }
-
- this.httpClient = httpClient.headersWhen(headers -> this.tokenProvider.fetchAppToken()
- .map(token -> headers
- .set("Authorization", String.format("Bearer %s", token.getValue()))));
- }
-
- @Override
- public EMProperties getProperties() {
- return this.properties;
- }
-
- @Override
- public Mono getHttpClient() {
- return this.endpointRegistry.endpoints().map(endpoints -> {
- Endpoint endpoint = this.loadBalancer.loadBalance(endpoints);
- String baseUri = String.format("%s/%s", endpoint.getUri(),
- this.properties.getAppkeySlashDelimited());
- if (log.isDebugEnabled()) {
- log.debug("load balanced base uri: {}", baseUri);
- }
- return this.httpClient.baseUrl(baseUri);
- });
- }
-
- @Override
- public TokenProvider getTokenProvider() {
- return this.tokenProvider;
- }
-
- @Override
- public Codec getCodec() {
- return this.codec;
- }
-
- @Override
- public ErrorMapper getErrorMapper() {
- return this.errorMapper;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultErrorMapper.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultErrorMapper.java
deleted file mode 100644
index 0c4e1e758..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/DefaultErrorMapper.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.easemob.im.server.api;
-
-import com.easemob.im.server.EMErrorResponse;
-import com.easemob.im.server.EMException;
-import com.easemob.im.server.exception.*;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import reactor.netty.http.client.HttpClientResponse;
-
-import java.io.IOException;
-
-public class DefaultErrorMapper implements ErrorMapper {
-
- private ObjectMapper objectMapper;
-
- private HttpClientResponse httpClientResponse;
-
- private int statusCode;
-
- public DefaultErrorMapper() {
- this.objectMapper = new ObjectMapper();
- this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- }
-
- @Override
- public void statusCode(HttpClientResponse response) {
- this.statusCode = response.status().code();
- this.httpClientResponse = response;
- }
-
- @Override
- public void checkError(ByteBuf buf) {
- if (this.statusCode >= 400) {
- throw toException(this.httpClientResponse, decode(buf, EMErrorResponse.class));
- }
- }
-
- private EMException toException(HttpClientResponse response, EMErrorResponse errorResponse) {
- String reason =
- String.format("%s %s -> %d %s, \n error_description -> %s", response.method().toString(), response.uri(),
- response.status().code(), response.status().reasonPhrase(), errorResponse.getErrorDescription());
- HttpResponseStatus status = response.status();
- EMException emException = new EMUnknownException(reason);
- if (HttpResponseStatus.BAD_REQUEST.equals(status)
- || HttpResponseStatus.METHOD_NOT_ALLOWED.equals(status)
- || HttpResponseStatus.NOT_ACCEPTABLE.equals(status)
- || HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE.equals(status)) {
- emException = new EMBadRequestException(reason);
- } else if (HttpResponseStatus.UNAUTHORIZED.equals(status)) {
- emException = new EMUnauthorizedException(reason);
- } else if (HttpResponseStatus.PAYMENT_REQUIRED.equals(status)
- || HttpResponseStatus.FORBIDDEN.equals(status)) {
- emException = new EMForbiddenException(reason);
- } else if (HttpResponseStatus.NOT_FOUND.equals(status)) {
- emException = new EMNotFoundException(reason);
- } else if (HttpResponseStatus.TOO_MANY_REQUESTS.equals(status)) {
- emException = new EMTooManyRequestsException(reason);
- } else if (HttpResponseStatus.INTERNAL_SERVER_ERROR.equals(status)) {
- emException = new EMInternalServerErrorException(reason);
- } else if (HttpResponseStatus.BAD_GATEWAY.equals(status)) {
- emException = new EMBadGatewayException(reason);
- } else if (HttpResponseStatus.SERVICE_UNAVAILABLE.equals(status)) {
- emException = new EMServiceUnavailableException(reason);
- } else if (HttpResponseStatus.GATEWAY_TIMEOUT.equals(status)) {
- emException = new EMGatewayTimeoutException(reason);
- }
- //设置错误状态码
- emException.setErrorCode(statusCode);
- return emException;
- }
-
- public T decode(ByteBuf buffer, Class tClass) {
- byte[] array;
- final int offset;
- int len = buffer.readableBytes();
- if (buffer.hasArray()) {
- array = buffer.array();
- offset = buffer.arrayOffset() + buffer.readerIndex();
- } else {
- array = ByteBufUtil.getBytes(buffer, buffer.readerIndex(), len, false);
- offset = 0;
- }
-
- try {
- return this.objectMapper.readValue(array, offset, len, tClass);
- } catch (IOException e) {
- throw new EMJsonException(
- String.format("could not decode class %s: %s", tClass.getName(),
- e.getMessage()), e);
- }
- }
-
-}
\ No newline at end of file
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/EMHttpClientFactory.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/EMHttpClientFactory.java
deleted file mode 100644
index a39bec50b..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/EMHttpClientFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.easemob.im.server.api;
-
-import com.easemob.im.server.EMProperties;
-import com.easemob.im.server.EMProxy;
-import com.easemob.im.server.EMVersion;
-import io.github.resilience4j.core.StringUtils;
-import io.netty.channel.ChannelOption;
-import io.netty.handler.logging.LogLevel;
-import io.netty.handler.timeout.ReadTimeoutHandler;
-import reactor.netty.http.client.HttpClient;
-import reactor.netty.resources.ConnectionProvider;
-import reactor.netty.transport.ProxyProvider;
-
-import java.net.InetSocketAddress;
-import java.time.Duration;
-import java.util.concurrent.TimeUnit;
-
-import static reactor.netty.ReactorNetty.IO_WORKER_COUNT;
-
-public class EMHttpClientFactory {
-
- public static HttpClient create(EMProperties properties) {
- ConnectionProvider connectionProvider = ConnectionProvider.builder("easemob-sdk")
- .maxConnections(properties.getHttpConnectionPoolSize())
- .maxIdleTime(Duration.ofMillis(properties.getHttpConnectionMaxIdleTime()))
- .maxLifeTime(Duration.ofMillis(properties.getHttpConnectionMaxLifeTime()))
- .pendingAcquireMaxCount(properties.getHttpConnectionPendingAcquireMaxCount())
- .pendingAcquireTimeout(Duration.ofMillis(properties.getHttpConnectionPendingAcquireTimeout()))
- .evictInBackground(Duration.ofMillis(properties.getHttpConnectionEvictInBackground()))
- .lifo()
- .build();
-
- if (properties.getNettyWorkerCount() > 0) {
- System.setProperty(IO_WORKER_COUNT, String.valueOf(properties.getNettyWorkerCount()));
- }
-
- HttpClient httpClient = HttpClient.create(connectionProvider)
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 60000)
- .doOnConnected(conn -> conn
- .addHandlerLast(new ReadTimeoutHandler(60000, TimeUnit.MILLISECONDS)))
- .headers(headers -> headers.add("User-Agent",
- String.format("EasemobServerSDK/%s", EMVersion.getVersion())))
- .wiretap("com.easemob.im.http", LogLevel.DEBUG, properties.getHttpLogFormat());
-
- EMProxy proxyInfo = properties.getProxy();
- if (proxyInfo == null) {
- return httpClient;
- } else {
- final String username = proxyInfo.getUsername();
- final String password = proxyInfo.getPassword();
- final String ip = proxyInfo.getIp();
- final int port = proxyInfo.getPort();
-
- if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
- return httpClient.proxy(
- proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
- .address(new InetSocketAddress(ip, port))
- .username(username)
- .password(p -> password)
- );
- } else {
- return httpClient.proxy(
- proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
- .address(new InetSocketAddress(ip, port))
- );
- }
- }
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/ErrorMapper.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/ErrorMapper.java
deleted file mode 100644
index 083509e5e..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/ErrorMapper.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.easemob.im.server.api;
-
-import io.netty.buffer.ByteBuf;
-import reactor.netty.http.client.HttpClientResponse;
-
-public interface ErrorMapper {
- void statusCode(HttpClientResponse response);
-
- void checkError(ByteBuf buf);
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/AttachmentApi.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/AttachmentApi.java
deleted file mode 100644
index 07bbacd42..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/AttachmentApi.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.easemob.im.server.api.attachment;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.attachment.download.Download;
-import com.easemob.im.server.api.attachment.upload.Upload;
-import com.easemob.im.server.model.EMAttachment;
-import reactor.core.publisher.Mono;
-
-import java.nio.file.Path;
-
-/**
- * 附件API
- * TODO: 支持上传和下载带有密码的附件
- */
-public class AttachmentApi {
-
- private Context context;
-
- private Upload upload;
-
- private Download download;
-
- public AttachmentApi(Context context) {
- this.context = context;
- this.upload = new Upload(context);
- this.download = new Download(context);
- }
-
- /**
- * 上传附件。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * Path uploadPath = Paths.get("/local/path/.../icon_180.png");
- * try {
- * EMAttachment attachment = service.attachment().uploadFile(uploadPath).block();
- * String fileId = attachment.getId();
- * String url = attachment.getUrl();
- * String secret = attachment.getSecret();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param path 要上传的文件的路径
- * @return 上传完成后返回附件的id
- * @see 上传附件
- */
- public Mono uploadFile(Path path) {
- return this.upload.fromLocalFile(path, false);
- }
-
- /* TODO: 上传带有密码保护的附件 */
-
- /**
- * 下载附件。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * Path downloadPath = Paths.get("/local/path/...");
- * Path path = service.attachment().downloadFile("fileId", downloadPath, "filename").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param fileId 附件的id
- * @param dir 下载到哪个目录,如果不存在会自动创建
- * @param filename 下载到哪个文件
- * @return 下载完成后返回文件路径
- * @see 下载附件
- */
- public Mono downloadFile(String fileId, Path dir, String filename) {
- return this.download.toLocalFile(fileId, dir, filename);
- }
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/download/Download.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/download/Download.java
deleted file mode 100644
index 0d9966b50..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/download/Download.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.easemob.im.server.api.attachment.download;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.api.util.FileSystem;
-import com.easemob.im.server.exception.EMUnknownException;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.io.OutputStream;
-import java.nio.file.Path;
-
-public class Download {
-
- private Context context;
-
- public Download(Context context) {
- this.context = context;
- }
-
- public Mono toLocalFile(String id, Path dir, String filename) {
- Path local = FileSystem.choosePath(dir, filename);
- return Mono.create(sink -> sink.success(FileSystem.open(local)))
- .flatMap(out -> this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.get()
- .uri(String.format("/chatfiles/%s", id))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .doOnSuccess(suc -> {
- FileSystem.close(out);
- })
- .then())
- .thenReturn(local);
- }
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/Upload.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/Upload.java
deleted file mode 100644
index 2577613ba..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/Upload.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.easemob.im.server.api.attachment.upload;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import com.easemob.im.server.model.EMAttachment;
-import reactor.core.publisher.Mono;
-
-import java.nio.file.Path;
-
-public class Upload {
-
- private Context context;
-
- public Upload(Context context) {
- this.context = context;
- }
-
- public Mono fromLocalFile(Path path, boolean restrictAccess) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient
- .headers(headers -> headers.add("restrict-access", restrictAccess))
- .post()
- .uri("/chatfiles")
- .sendForm((req, form) -> form.multipart(true)
- .attr("filename", path.getFileName().toString())
- .file("file", path.toFile()))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec().decode(buf, UploadFileResponse.class))
- .handle((rsp, sink) -> {
- if (rsp.getFiles().isEmpty()) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- String id = rsp.getFiles().get(0).getId();
- String url = rsp.getBaseUrl() + "/" + id;
- String secret = rsp.getFiles().get(0).getSecret();
- sink.next(new EMAttachment(id, url, secret));
- });
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/UploadFileResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/UploadFileResponse.java
deleted file mode 100644
index 5e9cc631b..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/attachment/upload/UploadFileResponse.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.easemob.im.server.api.attachment.upload;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.List;
-
-public class UploadFileResponse {
-
- @JsonProperty("uri")
- private String baseUrl;
-
- @JsonProperty("entities")
- private List files;
-
- @JsonCreator
- public UploadFileResponse(@JsonProperty("entities") List files,
- @JsonProperty("uri") String baseUrl) {
- this.files = files;
- this.baseUrl = baseUrl;
- }
-
- public String getBaseUrl() {
- return this.baseUrl;
- }
-
- public List getFiles() {
- return this.files;
- }
-
- public static class FileUploaded {
- @JsonProperty("uuid")
- private String id;
- @JsonProperty("type")
- private String type;
- @JsonProperty("share-secret")
- private String secret;
-
- @JsonCreator
- public FileUploaded(@JsonProperty("uuid") String id,
- @JsonProperty("type") String type,
- @JsonProperty("share-secret") String secret) {
- this.id = id;
- this.type = type;
- this.secret = secret;
- }
-
- public String getId() {
- return this.id;
- }
-
- public String getType() {
- return this.type;
- }
-
- public String getSecret() {
- return this.secret;
- }
- }
-
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/BlockApi.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/BlockApi.java
deleted file mode 100644
index 35aa2315c..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/BlockApi.java
+++ /dev/null
@@ -1,621 +0,0 @@
-package com.easemob.im.server.api.block;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.block.group.join.BlockUserJoinGroup;
-import com.easemob.im.server.api.block.group.msg.BlockAllUserSendMsgToGroup;
-import com.easemob.im.server.api.block.group.msg.BlockUserSendMsgToGroup;
-import com.easemob.im.server.api.block.group.msg.UnblockAllUserSendMsgToGroup;
-import com.easemob.im.server.api.block.login.BlockUserLogin;
-import com.easemob.im.server.api.block.room.join.BlockUserJoinRoom;
-import com.easemob.im.server.api.block.room.msg.block.BlockAllUserSendMsgToRoom;
-import com.easemob.im.server.api.block.room.msg.block.BlockUserSendMsgToRoom;
-import com.easemob.im.server.api.block.room.msg.list.ListUsersBlockedSendMsgToRoom;
-import com.easemob.im.server.api.block.room.msg.unblock.UnblockAllUserSendMsgToRoom;
-import com.easemob.im.server.api.block.room.msg.unblock.UnblockUserSendMsgToRoom;
-import com.easemob.im.server.api.block.user.SendMsgToUser;
-import com.easemob.im.server.model.EMBlock;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.time.Duration;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 封禁API,提供封禁相关的功能。
- */
-public class BlockApi {
-
- private SendMsgToUser sendMsgToUser;
-
- private BlockUserLogin blockUserLogin;
-
- private BlockUserJoinGroup blockUserJoinGroup;
-
- private BlockUserJoinRoom blockUserJoinRoom;
-
- private BlockUserSendMsgToGroup blockUserSendMsgToGroup;
-
- private UnblockUserSendMsgToRoom unblockUserSendMsgToRoom;
-
- private BlockUserSendMsgToRoom blockUserSendMsgToRoom;
-
- private ListUsersBlockedSendMsgToRoom listUsersBlockedSendMsgToRoom;
-
- private UnblockAllUserSendMsgToRoom unblockAllUserSendMsgToRoom;
-
- private BlockAllUserSendMsgToRoom blockAllUserSendMsgToRoom;
-
- private UnblockAllUserSendMsgToGroup unblockAllUserSendMsgToGroup;
-
- private BlockAllUserSendMsgToGroup blockAllUserSendMsgToGroup;
-
- public BlockApi(Context context) {
- this.sendMsgToUser = new SendMsgToUser(context);
- this.blockUserLogin = new BlockUserLogin(context);
- this.blockUserJoinGroup = new BlockUserJoinGroup(context);
- this.blockUserJoinRoom = new BlockUserJoinRoom(context);
- this.blockUserSendMsgToGroup = new BlockUserSendMsgToGroup(context);
- this.unblockUserSendMsgToRoom = new UnblockUserSendMsgToRoom(context);
- this.blockUserSendMsgToRoom = new BlockUserSendMsgToRoom(context);
- this.listUsersBlockedSendMsgToRoom = new ListUsersBlockedSendMsgToRoom(context);
- this.unblockAllUserSendMsgToRoom = new UnblockAllUserSendMsgToRoom(context);
- this.blockAllUserSendMsgToRoom = new BlockAllUserSendMsgToRoom(context);
- this.unblockAllUserSendMsgToGroup = new UnblockAllUserSendMsgToGroup(context);
- this.blockAllUserSendMsgToGroup = new BlockAllUserSendMsgToGroup(context);
- }
-
- /**
- * 获取禁言列表,即这个用户禁言的其他用户。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List blocks = service.block().getUsersBlockedFromSendMsgToUser("username").collectList().block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 发起禁言的用户名
- * @return 每个被禁言用户的用户的用户名或错误
- * @see 获取用户禁言列表
- */
- public Flux getUsersBlockedFromSendMsgToUser(String username) {
- return this.sendMsgToUser.getUsersBlocked(username);
- }
-
- /**
- * 用户禁言,阻止向这个用户发消息。
- *
- * 要阻止 userA 给 userB发送消息:
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserSendMsgToUser("userA", "userB").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param fromUser 被阻止的用户的用户名
- * @param toUser 接收消息的用户的用户名
- * @return 成功或错误
- * @see 添加用户禁言
- */
- public Mono blockUserSendMsgToUser(String fromUser, String toUser) {
- return this.sendMsgToUser.blockUser(fromUser, toUser);
- }
-
- /**
- * 解除用户禁言,恢复向这个用户发消息。
- *
- * 要恢复 userA 给 userB发送消息:
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserSendMsgToUser("userA", "userB").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param fromUser 被阻止的用户的用户名
- * @param toUser 接受消息的用户的用户名
- * @return 成功或错误
- * @see 解除用户禁言
- */
- public Mono unblockUserSendMsgToUser(String fromUser, String toUser) {
- return this.sendMsgToUser.unblockUser(fromUser, toUser);
- }
-
- /**
- * 用户账号禁用,阻止该用户登录。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserLogin("username").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @return 成功或失败
- * @see 用户账号禁用
- */
- public Mono blockUserLogin(String username) {
- return this.blockUserLogin.blockUser(username);
- }
-
- /**
- * 用户账号解禁,恢复该用户登录。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserLogin("username").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @return 成功或失败
- * @see 用户账号解禁
- */
- public Mono unblockUserLogin(String username) {
- return this.blockUserLogin.unblockUser(username);
- }
-
- /**
- * 获取阻止进群的用户列表。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List blocks = service.block().getUsersBlockedJoinGroup("groupId").collectList().block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param groupId 群id
- * @return 被阻止进入的用户名
- * @see 获取阻止进群列表
- */
- public Flux getUsersBlockedJoinGroup(String groupId) {
- return this.blockUserJoinGroup.getBlockedUsers(groupId);
- }
-
- /**
- * 阻止进群。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserJoinGroup("username", "groupId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @param groupId 群id
- * @return 成功或错误
- * @see 阻止进群
- */
- public Mono blockUserJoinGroup(String username, String groupId) {
- return this.blockUserJoinGroup.blockUser(username, groupId);
- }
-
- /**
- * 解除阻止进群。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserJoinGroup("username", "groupId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @param groupId 群id
- * @return 成功或错误
- * @see
- */
- public Mono unblockUserJoinGroup(String username, String groupId) {
- return this.blockUserJoinGroup.unblockUser(username, groupId);
- }
-
- /**
- * 获取阻止进聊天室的用户列表。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List blocks = service.block().getUsersBlockedJoinRoom("roomId").collectList().block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param roomId 聊天室id
- * @return 被阻止进入的用户名
- */
- public Flux getUsersBlockedJoinRoom(String roomId) {
- return this.blockUserJoinRoom.getBlockedUsers(roomId);
- }
-
- /**
- * 阻止进聊天室。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserJoinRoom("username", "roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @param roomId 聊天室id
- * @return 成功或错误
- */
- public Mono blockUserJoinRoom(String username, String roomId) {
- return this.blockUserJoinRoom.blockUser(username, roomId);
- }
-
- /**
- * 解除阻止进聊天室。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserJoinRoom("username", "roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被阻止的用户的用户名
- * @param roomId 聊天室id
- * @return 成功或错误
- */
- public Mono unblockUserJoinRoom(String username, String roomId) {
- return this.blockUserJoinRoom.unblockUser(username, roomId);
- }
-
- /**
- * 获取群禁言列表。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List blocks = service.block().getUsersBlockedSendMsgToGroup("groupId").collectList().block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param groupId 群id
- * @return 每个禁言或错误.
- * @see 获取禁言列表
- */
- public Flux getUsersBlockedSendMsgToGroup(String groupId) {
- return this.blockUserSendMsgToGroup.getBlockedUsers(groupId);
- }
-
- /**
- * 添加群禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserSendMsgToGroup("username", "groupId", Duration.ofMillis(6000)).block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被禁言的用户的用户名
- * @param groupId 群id
- * @param duration 禁言多长时间,为null则永久禁言
- * @return 成功或错误
- * @see 添加禁言
- */
- public Mono blockUserSendMsgToGroup(String username, String groupId, Duration duration) {
- return this.blockUserSendMsgToGroup.blockUser(username, groupId, duration);
- }
-
- /**
- * 添加群禁言,支持同时禁言多个用户。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List usernames = new ArrayList<>();
- * usernames.add("user1");
- * usernames.add("user2");
- *
- * service.block().blockUsersSendMsgToGroup(usernames, "groupId", Duration.ofMillis(6000)).block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param usernames 被禁言的用户的用户名列表
- * @param groupId 群id
- * @param duration 禁言多长时间,为null则永久禁言
- * @return 成功或错误
- * @see 添加禁言
- */
- public Mono blockUsersSendMsgToGroup(List usernames, String groupId, Duration duration) {
- return this.blockUserSendMsgToGroup.blockUsers(usernames, groupId, duration);
- }
-
- /**
- * 解除群禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserSendMsgToGroup("username", "groupId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被禁言的用户的用户名
- * @param groupId 群id
- * @return 成功或错误
- * @see 移除禁言
- */
- public Mono unblockUserSendMsgToGroup(String username, String groupId) {
- return this.blockUserSendMsgToGroup.unblockUser(username, groupId);
- }
-
- /**
- * 解除群组全员禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockAllUserSendMsgToGroup("groupId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param groupId 群组id
- * @return 成功或错误
- * @see 解除群组全员禁言
- */
- public Mono unblockAllUserSendMsgToGroup(String groupId) {
- return this.unblockAllUserSendMsgToGroup.single(groupId);
- }
-
- /**
- * 禁言群组全体成员。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockAllUserSendMsgToGroup("groupId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param groupId 群组id
- * @return 成功或错误
- * @see 禁言群组全体成员
- */
- public Mono blockAllUserSendMsgToGroup(String groupId) {
- return this.blockAllUserSendMsgToGroup.single(groupId);
- }
-
- /**
- * 获取聊天室禁言列表。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List blocks = service.block().listUsersBlockedSendMsgToRoom("roomId").collectList().block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param roomId 聊天室id
- * @return 每个禁言或错误
- * @see 获取禁言列表
- */
- public Flux listUsersBlockedSendMsgToRoom(String roomId) {
- return this.listUsersBlockedSendMsgToRoom.all(roomId);
- }
-
- /**
- * 添加聊天室禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockUserSendMsgToRoom("username", "roomId", Duration.ofMillis(6000)).block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被禁言的用户的用户名
- * @param roomId 聊天室id
- * @param duration 禁言时长,为null则永久禁言
- * @return 成功或错误
- * @see 添加禁言
- */
- public Mono blockUserSendMsgToRoom(String username, String roomId, Duration duration) {
- return this.blockUserSendMsgToRoom.single(username, roomId, duration);
- }
-
- /**
- * 将多个用户添加聊天室禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List usernames = new ArrayList<>();
- * usernames.add("user1");
- * service.block().blockUserSendMsgToRoom(usernames, "roomId", Duration.ofMillis(6000)).block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param usernames 被禁言的用户名列表
- * @param roomId 聊天室id
- * @param duration 禁言时长,为null则永久禁言
- * @return 成功或错误
- * @see 添加禁言
- */
- public Mono blockUserSendMsgToRoom(List usernames, String roomId, Duration duration) {
- return this.blockUserSendMsgToRoom.batch(usernames, roomId, duration);
- }
-
- /**
- * 解除聊天室禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockUserSendMsgToRoom("username", "roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param username 被解除禁言的用户的用户名
- * @param roomId 聊天室id
- * @return 成功或错误
- * @see 移除禁言
- */
- public Mono unblockUserSendMsgToRoom(String username, String roomId) {
- return this.unblockUserSendMsgToRoom.single(username, roomId);
- }
-
- /**
- * 将多个用户解除聊天室禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * List usernames = new ArrayList<>();
- * usernames.add("user1");
- * service.block().unblockUserSendMsgToRoom(usernames, "roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param usernames 被解除禁言的用户名列表
- * @param roomId 聊天室id
- * @return 成功或错误
- * @see 移除禁言
- */
- public Mono unblockUserSendMsgToRoom(List usernames, String roomId) {
- return this.unblockUserSendMsgToRoom.batch(usernames, roomId);
- }
-
- /**
- * 解除聊天室全员禁言。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().unblockAllUserSendMsgToRoom("roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param roomId 聊天室id
- * @return 成功或错误
- * @see 解除聊天室全员禁言
- */
- public Mono unblockAllUserSendMsgToRoom(String roomId) {
- return this.unblockAllUserSendMsgToRoom.single(roomId);
- }
-
- /**
- * 禁言聊天室全体成员。
- *
- * API使用示例:
- *
{@code
- * EMService service;
- * try {
- * service.block().blockAllUserSendMsgToRoom("roomId").block();
- * } catch (EMException e) {
- * e.getErrorCode();
- * e.getMessage();
- * }
- * }
- *
- * @param roomId 聊天室id
- * @return 成功或错误
- * @see 禁言聊天室全体成员
- */
- public Mono blockAllUserSendMsgToRoom(String roomId) {
- return this.blockAllUserSendMsgToRoom.single(roomId);
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroup.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroup.java
deleted file mode 100644
index 4ff7e6abb..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroup.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.easemob.im.server.api.block.group.join;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import com.easemob.im.server.model.EMBlock;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-public class BlockUserJoinGroup {
-
- private Context context;
-
- public BlockUserJoinGroup(Context context) {
- this.context = context;
- }
-
- public Flux getBlockedUsers(String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.get()
- .uri(String.format("/chatgroups/%s/blocks/users", groupId))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> context.getCodec().decode(buf, GetBlockedUsersResponse.class))
- .flatMapIterable(GetBlockedUsersResponse::getUsernames)
- .map(username -> new EMBlock(username, null));
- }
-
- public Mono blockUser(String username, String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/chatgroups/%s/blocks/users/%s", groupId, username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec().decode(buf, BlockUserJoinGroupResponse.class))
- .handle((rsp, sink) -> {
- if (!rsp.getSuccess()) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- sink.complete();
- });
- }
-
- public Mono unblockUser(String username, String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.delete()
- .uri(String.format("/chatgroups/%s/blocks/users/%s", groupId, username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec().decode(buf, UnblockUserJoinGroupResponse.class))
- .handle((rsp, sink) -> {
- if (!rsp.getSuccess()) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- sink.complete();
- });
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroupResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroupResponse.java
deleted file mode 100644
index 8ac7ae084..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/BlockUserJoinGroupResponse.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.easemob.im.server.api.block.group.join;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class BlockUserJoinGroupResponse {
- @JsonProperty("data")
- private BlockUserJoinGroupResource resource;
-
- @JsonCreator
- public BlockUserJoinGroupResponse(@JsonProperty("data") BlockUserJoinGroupResource resource) {
- this.resource = resource;
- }
-
- public boolean getSuccess() {
- return this.resource != null && this.resource.success;
- }
-
- public static class BlockUserJoinGroupResource {
- @JsonProperty("result")
- private boolean success;
-
- @JsonCreator
- public BlockUserJoinGroupResource(@JsonProperty("result") boolean success) {
- this.success = success;
- }
-
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/GetBlockedUsersResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/GetBlockedUsersResponse.java
deleted file mode 100644
index 33505cad7..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/GetBlockedUsersResponse.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.easemob.im.server.api.block.group.join;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.List;
-
-public class GetBlockedUsersResponse {
- @JsonProperty("data")
- private List usernames;
-
- @JsonCreator
- public GetBlockedUsersResponse(@JsonProperty("data") List usernames) {
- this.usernames = usernames;
- }
-
- public List getUsernames() {
- return this.usernames;
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/UnblockUserJoinGroupResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/UnblockUserJoinGroupResponse.java
deleted file mode 100644
index 7bc0ef86d..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/join/UnblockUserJoinGroupResponse.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.easemob.im.server.api.block.group.join;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class UnblockUserJoinGroupResponse {
- @JsonProperty("data")
- private UnblockUserJoinGroupResource resource;
-
- @JsonCreator
- public UnblockUserJoinGroupResponse(
- @JsonProperty("data") UnblockUserJoinGroupResource resource) {
- this.resource = resource;
- }
-
- public boolean getSuccess() {
- return this.resource != null && this.resource.success;
- }
-
- public static class UnblockUserJoinGroupResource {
- @JsonProperty("result")
- private boolean success;
-
- @JsonCreator
- public UnblockUserJoinGroupResource(@JsonProperty("result") boolean success) {
- this.success = success;
- }
-
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockAllUserSendMsgToGroup.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockAllUserSendMsgToGroup.java
deleted file mode 100644
index 0d6b11fb3..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockAllUserSendMsgToGroup.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import reactor.core.publisher.Mono;
-
-public class BlockAllUserSendMsgToGroup {
-
- private Context context;
-
- public BlockAllUserSendMsgToGroup(Context context) {
- this.context = context;
- }
-
- public Mono single(String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/chatgroups/%s/ban", groupId))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .then();
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroup.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroup.java
deleted file mode 100644
index 7820390ef..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroup.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import com.easemob.im.server.model.EMBlock;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.time.Duration;
-import java.util.List;
-
-public class BlockUserSendMsgToGroup {
-
- private Context context;
-
- public BlockUserSendMsgToGroup(Context context) {
- this.context = context;
- }
-
- public Flux getBlockedUsers(String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.get()
- .uri(String.format("/chatgroups/%s/mute", groupId))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(rsp -> this.context.getCodec()
- .decode(rsp, GetUsersBlockedSendMsgToGroupResponse.class))
- .flatMapIterable(GetUsersBlockedSendMsgToGroupResponse::getEMBlocks);
-
- }
-
- public Mono blockUser(String username, String groupId, Duration duration) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/chatgroups/%s/mute", groupId))
- .send(Mono.create(sink -> sink.success(this.context.getCodec()
- .encode(BlockUserSendMsgToGroupRequest.of(username, duration)))))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec()
- .decode(buf, BlockUserSendMsgToGroupResponse.class))
- .handle((rsp, sink) -> {
- if (!rsp.getSuccess(username)) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- sink.complete();
- });
- }
-
- public Mono blockUsers(List usernames, String groupId, Duration duration) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/chatgroups/%s/mute", groupId))
- .send(Mono.create(sink -> sink.success(this.context.getCodec()
- .encode(BlockUserSendMsgToGroupRequest.of(usernames, duration)))))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec()
- .decode(buf, BlockUserSendMsgToGroupResponse.class))
- .then();
- }
-
- public Mono unblockUser(String username, String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.delete()
- .uri(String.format("/chatgroups/%s/mute/%s", groupId, username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec()
- .decode(buf, UnblockUserSendMsgToGroupResponse.class))
- .handle((rsp, sink) -> {
- if (!rsp.getSuccess(username)) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- sink.complete();
- });
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupRequest.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupRequest.java
deleted file mode 100644
index 74dfbd46d..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupRequest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.time.Duration;
-import java.util.ArrayList;
-import java.util.List;
-
-public class BlockUserSendMsgToGroupRequest {
- @JsonProperty("usernames")
- private List usernames;
-
- @JsonProperty("mute_duration")
- private long durationInMillis;
-
- @JsonCreator
- public BlockUserSendMsgToGroupRequest(@JsonProperty("usernames") List usernames,
- @JsonProperty("mute_duration") long durationInMillis) {
- this.usernames = usernames;
- this.durationInMillis = durationInMillis;
- }
-
- public static BlockUserSendMsgToGroupRequest of(String username, Duration duration) {
- List usernames = new ArrayList<>();
- usernames.add(username);
- return new BlockUserSendMsgToGroupRequest(usernames,
- duration == null ? -1 : duration.toMillis());
- }
-
- public static BlockUserSendMsgToGroupRequest of(List usernames, Duration duration) {
- return new BlockUserSendMsgToGroupRequest(usernames,
- duration == null ? -1 : duration.toMillis());
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupResponse.java
deleted file mode 100644
index eb4a7ed36..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/BlockUserSendMsgToGroupResponse.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.List;
-
-public class BlockUserSendMsgToGroupResponse {
- @JsonProperty("data")
- private List resources;
-
- @JsonCreator
- public BlockUserSendMsgToGroupResponse(
- @JsonProperty("data") List resources) {
- this.resources = resources;
- }
-
- public boolean getSuccess(String username) {
- return this.resources.stream()
- .filter(res -> res.getUsername().equals(username))
- .findFirst().map(BlockUsersResource::getSuccess)
- .orElse(false);
- }
-
- public static class BlockUsersResource {
- @JsonProperty("result")
- private boolean success;
-
- @JsonProperty("user")
- private String username;
-
- @JsonCreator
- public BlockUsersResource(@JsonProperty("result") boolean success,
- @JsonProperty("user") String username) {
- this.success = success;
- this.username = username;
- }
-
- public boolean getSuccess() {
- return this.success;
- }
-
- public String getUsername() {
- return this.username;
- }
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/GetUsersBlockedSendMsgToGroupResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/GetUsersBlockedSendMsgToGroupResponse.java
deleted file mode 100644
index bb86a67ed..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/GetUsersBlockedSendMsgToGroupResponse.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.easemob.im.server.model.EMBlock;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.time.Instant;
-import java.util.List;
-import java.util.stream.Collectors;
-
-public class GetUsersBlockedSendMsgToGroupResponse {
- @JsonProperty("data")
- private List resources;
-
- @JsonCreator
- public GetUsersBlockedSendMsgToGroupResponse(
- @JsonProperty("data") List resources) {
- this.resources = resources;
- }
-
- public List getEMBlocks() {
- return this.resources.stream().map(UserBlockedSendMsgToGroupResource::toEMBlock)
- .collect(Collectors.toList());
- }
-
- public static class UserBlockedSendMsgToGroupResource {
- @JsonProperty("user")
- private String username;
- @JsonProperty("expire")
- private long expireTimestamp;
-
- public UserBlockedSendMsgToGroupResource(@JsonProperty("user") String username,
- @JsonProperty("expire") long expireTimestamp) {
- this.username = username;
- this.expireTimestamp = expireTimestamp;
- }
-
- public EMBlock toEMBlock() {
- return new EMBlock(this.username, Instant.ofEpochMilli(this.expireTimestamp));
- }
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockAllUserSendMsgToGroup.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockAllUserSendMsgToGroup.java
deleted file mode 100644
index 2c93a5cef..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockAllUserSendMsgToGroup.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import reactor.core.publisher.Mono;
-
-public class UnblockAllUserSendMsgToGroup {
-
- private Context context;
-
- public UnblockAllUserSendMsgToGroup(Context context) {
- this.context = context;
- }
-
- public Mono single(String groupId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.delete()
- .uri(String.format("/chatgroups/%s/ban", groupId))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .then();
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockUserSendMsgToGroupResponse.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockUserSendMsgToGroupResponse.java
deleted file mode 100644
index 6555ba758..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/group/msg/UnblockUserSendMsgToGroupResponse.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.easemob.im.server.api.block.group.msg;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import java.util.List;
-
-public class UnblockUserSendMsgToGroupResponse {
- @JsonProperty("data")
- private List resources;
-
- @JsonCreator
- public UnblockUserSendMsgToGroupResponse(
- @JsonProperty("data") List resources) {
- this.resources = resources;
- }
-
- public boolean getSuccess(String username) {
- return this.resources.stream()
- .filter(res -> res.getUsername().equals(username))
- .findFirst().map(UnblockUsersResource::getSuccess)
- .orElse(false);
- }
-
- public static class UnblockUsersResource {
- @JsonProperty("result")
- private boolean success;
-
- @JsonProperty("user")
- private String username;
-
- @JsonCreator
- public UnblockUsersResource(@JsonProperty("result") boolean success,
- @JsonProperty("user") String username) {
- this.success = success;
- this.username = username;
- }
-
- public boolean getSuccess() {
- return this.success;
- }
-
- public String getUsername() {
- return this.username;
- }
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/login/BlockUserLogin.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/login/BlockUserLogin.java
deleted file mode 100644
index ca08a5f3a..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/login/BlockUserLogin.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.easemob.im.server.api.block.login;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import reactor.core.publisher.Mono;
-
-public class BlockUserLogin {
-
- private Context context;
-
- public BlockUserLogin(Context context) {
- this.context = context;
- }
-
- public Mono blockUser(String username) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/users/%s/deactivate", username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .then();
- }
-
- public Mono unblockUser(String username) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/users/%s/activate", username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .then();
- }
-}
diff --git a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/room/join/BlockUserJoinRoom.java b/im-sdk-core/src/main/java/com/easemob/im/server/api/block/room/join/BlockUserJoinRoom.java
deleted file mode 100644
index 797c954f1..000000000
--- a/im-sdk-core/src/main/java/com/easemob/im/server/api/block/room/join/BlockUserJoinRoom.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.easemob.im.server.api.block.room.join;
-
-import com.easemob.im.server.api.Context;
-import com.easemob.im.server.api.DefaultErrorMapper;
-import com.easemob.im.server.api.ErrorMapper;
-import com.easemob.im.server.exception.EMUnknownException;
-import com.easemob.im.server.model.EMBlock;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-public class BlockUserJoinRoom {
-
- private Context context;
-
- public BlockUserJoinRoom(Context context) {
- this.context = context;
- }
-
- public Flux getBlockedUsers(String roomId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.get()
- .uri(String.format("/chatrooms/%s/blocks/users", roomId))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec().decode(buf, GetBlockedUsersResponse.class))
- .flatMapIterable(GetBlockedUsersResponse::getUsernames)
- .map(username -> new EMBlock(username, null));
- }
-
- public Mono blockUser(String username, String roomId) {
- return this.context.getHttpClient()
- .flatMap(httpClient -> httpClient.post()
- .uri(String.format("/chatrooms/%s/blocks/users/%s", roomId, username))
- .responseSingle((rsp, buf) -> {
- return buf.switchIfEmpty(
- Mono.error(new EMUnknownException("response is null")))
- .flatMap(byteBuf -> {
- ErrorMapper mapper = new DefaultErrorMapper();
- mapper.statusCode(rsp);
- mapper.checkError(byteBuf);
- return Mono.just(byteBuf);
- });
- }))
- .map(buf -> this.context.getCodec().decode(buf, BlockUserJoinRoomResponse.class))
- .handle((rsp, sink) -> {
- if (!rsp.isSuccess()) {
- sink.error(new EMUnknownException("unknown"));
- return;
- }
- sink.complete();
- });
- }
-
- public Mono