diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..681f41ae --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 1cf9ec3e..de01c6a1 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,9 @@ android { } testOptions { - unitTests.returnDefaultValues = true + unitTests { + includeAndroidResources = true + } } } @@ -45,27 +47,31 @@ dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' + androidTestCompile 'org.hamcrest:hamcrest-library:1.3' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:support-v4:28.0.0' - implementation 'com.android.support:recyclerview-v7:28.0.0' + implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:support-emoji-appcompat:28.0.0' implementation 'com.android.support:support-annotations:28.0.0' implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' + //cometchat sdk - implementation 'com.cometchat:pro-android-chat-sdk:1.8.3' + implementation 'com.cometchat:pro-android-chat-sdk:1.8.5' implementation 'com.android.support:recyclerview-selection:28.0.0' - implementation'com.facebook.shimmer:shimmer:0.4.0' + + implementation 'com.facebook.shimmer:shimmer:0.4.0' } repositories { mavenCentral() + } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f1b42451..e3fb1e09 100755 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -19,3 +19,15 @@ # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile + +# Glide specific rules # +# https://github.com/bumptech/glide + +-keep public class com.dylanvann.fastimage.* {*;} +-keep public class com.dylanvann.fastimage.** {*;} +-keep public class * implements com.bumptech.glide.module.GlideModule +-keep public class * extends com.bumptech.glide.module.AppGlideModule +-keep public enum com.bumptech.glide.load.ImageHeaderParser$** { + **[] $VALUES; + public *; +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/inscripts/cometchatpulse/demo/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/inscripts/cometchatpulse/demo/ExampleInstrumentedTest.java index 4b534245..4208e1a0 100755 --- a/app/src/androidTest/java/com/inscripts/cometchatpulse/demo/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/inscripts/cometchatpulse/demo/ExampleInstrumentedTest.java @@ -3,24 +3,3670 @@ import android.content.Context; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; +import android.support.test.runner.AndroidJUnitRunner; +import android.util.Log; +import com.cometchat.pro.constants.CometChatConstants; +import com.cometchat.pro.core.BannedGroupMembersRequest; +import com.cometchat.pro.core.BlockedUsersRequest; +import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.core.GroupMembersRequest; +import com.cometchat.pro.core.GroupsRequest; +import com.cometchat.pro.core.MessagesRequest; +import com.cometchat.pro.core.UsersRequest; +import com.cometchat.pro.exceptions.CometChatException; +import com.cometchat.pro.models.BaseMessage; +import com.cometchat.pro.models.CustomMessage; +import com.cometchat.pro.models.Group; +import com.cometchat.pro.models.GroupMember; +import com.cometchat.pro.models.MediaMessage; +import com.cometchat.pro.models.TextMessage; +import com.cometchat.pro.models.User; +import com.inscripts.cometchatpulse.demo.Contracts.StringContract; +import org.json.JSONObject; +import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import static org.junit.Assert.*; + /** * Instrumented test, which will execute on an Android device. * * @see Testing documentation */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { + + private static final String TAG = "ExampleInstrumentedTest"; + private static final int MESSAGE_ID = 398; + + String GUID = "supergroup"; + + String UID="superhero1"; + + Context appContext = InstrumentationRegistry.getTargetContext(); + + private String filePath = "/storage/emulated/0/Pictures/1558684863347.jpg"; + + private String videoPath="/storage/emulated/0/DCIM/Camera/VID_20190814_121539.mp4"; + + @Test + public void init() { + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.init(appContext, StringContract.AppDetails.API_KEY, new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "init onSuccess: " + s); + assertEquals("Init Successful", s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + assertEquals("Init failed", e.getMessage()); + countDownLatch.countDown(); + + } + }); + + try { + countDownLatch.await(5, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + @Test + public void loginWithUID() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.login("superhero2", StringContract.AppDetails.API_KEY, new CometChat.CallbackListener() { + @Override + public void onSuccess(User user) { + Log.d(TAG, "loginWithUid onSuccess: " + user.getUid()); + //assertNotNull("Login success test",null); + assertEquals("superhero2", user.getUid()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "loginWithUID onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + + try { + countDownLatch.await(10, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void loginWithUIDEmpty() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.login("", StringContract.AppDetails.API_KEY, new CometChat.CallbackListener() { + @Override + public void onSuccess(User user) { + countDownLatch.countDown(); + assertEquals("superhero2", user.getUid()); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "loginWithEmptyUID onError: " + e.getMessage()); + assertEquals("UID cannot be blank. Please provide a valid UID", e.getMessage()); + countDownLatch.countDown(); + } + }); + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + + } catch (InterruptedException e) { + + } + } + + @Test + public void loginWithEmptyAPIKEY() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + CometChat.login("superhero3", "", new CometChat.CallbackListener() { + @Override + public void onSuccess(User user) { + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); +// assertEquals("ERROR_JSON_EXCEPTION",e.getCode()); + Log.d(TAG, "loginWithEmptyAPIKEY onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + + } + + } + + @Test + public void sendTextMessage() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage("superhero1", "Hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + countDownLatch.countDown(); + assertEquals("Hello", textMessage.getText()); + Log.d(TAG, "sendTextMessage onSuccess: "); + } + + @Override + public void onError(CometChatException e) { + assertNotEquals("sendTextMessage", null); + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessage onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (InterruptedException e) { + + } + + } + + @Test + public void sendMessageWithInvalidUID() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage("", "hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendMessageWithInvalidUID onSuccess: "); + } + + @Override + public void onError(CometChatException e) { + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + countDownLatch.countDown(); + Log.d(TAG, "sendMessageWithInvalidUID onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (InterruptedException e) { + + } + + } + + @Test + public void sendTextMessageWithImageType() { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "Hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + } + + @Override + public void onError(CometChatException e) { + assertNotEquals("sendTextMessage", null); + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithImageType onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + + } + } + + + @Test + public void sendTextMessageWithNullText() { + CountDownLatch countDownLatch = new CountDownLatch(1); + + + TextMessage textMessage = new TextMessage(UID, null, CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithNullText onSuccess: "); + } + + @Override + public void onError(CometChatException e) { + assertEquals("Message text should be non-empty string.", e.getMessage()); + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithNullText onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + + } + } + + @Test + public void sendTextMessageWithInvalidPara() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + + TextMessage textMessage = new TextMessage(UID, null,CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.CATEGORY_MESSAGE); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithInvalidPara onSuccess: "); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendTextMessageWithInvalidPara onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + countDownLatch.countDown(); + + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("Cometchat timeout", null); + } + } catch (InterruptedException e) { + + } + } + + + @Test + public void sendTextMessageWithGroupType() { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "Hello", CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.RECEIVER_TYPE_GROUP); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + } + + @Override + public void onError(CometChatException e) { + assertEquals("ERR_GUID_NOT_FOUND", e.getCode()); + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithGroupType onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (InterruptedException e) { + + } + } + + @Test + public void sendTextMessageInvalidTypeAndEmptyMessage() { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_GROUP); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + } + + @Override + public void onError(CometChatException e) { + assertEquals("ERR_GUID_NOT_FOUND", e.getCode()); + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithGroupType onError: " + e.getMessage()); + } + }); + + try { + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (InterruptedException e) { + + } + } + + + @Test + public void sendCustomMessage() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + JSONObject customData = new JSONObject(); + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + CustomMessage customMessage = new CustomMessage(UID, CometChatConstants.RECEIVER_TYPE_USER, "hello", customData); + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessage onSuccess : " + customMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessage onError: " + e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + + } + + + /*** + * send custom message with custom type equals to "user" + */ + @Test + public void sendCustomMessageWithTypeCustom() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + JSONObject customData = new JSONObject(); + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + CustomMessage customMessage = new CustomMessage(UID, CometChatConstants.RECEIVER_TYPE_USER, CometChatConstants.RECEIVER_TYPE_USER, customData); + + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithTypeCustom onSuccess : " + customMessage.toString()); + assertEquals(CometChatConstants.RECEIVER_TYPE_USER, customMessage.getType()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithTypeCustom onError: " + e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + + } + + @Test + public void sendCustomMessageWithGroupReceiver() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + JSONObject customData = new JSONObject(); + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + CustomMessage customMessage = new CustomMessage(GUID, CometChatConstants.RECEIVER_TYPE_GROUP, "t", customData); + + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithGroupReceiver onSuccess : " + customMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithGroupReceiver onError: " + e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + + @Test + public void sendCustomMessageWithEmptyCustomObject() { + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); +// +// JSONObject customData = new JSONObject(); +// customData.put("lattitue","19.0760"); +// customData.put("longitude","72.8777"); + + CustomMessage customMessage = new CustomMessage(GUID, CometChatConstants.RECEIVER_TYPE_GROUP, "t", null); + + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithEmptyCustomObject onSuccess : " + customMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithEmptyCustomObject onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test + public void sendCustomMessageWithEmptyCustomObjectAndInvalidPara() { + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + +// JSONObject customData = new JSONObject(); +// customData.put("lattitue","19.0760"); +// customData.put("longitude","72.8777"); + + CustomMessage customMessage = new CustomMessage(GUID, CometChatConstants.RECEIVER_TYPE_GROUP, "t", null); + + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithEmptyCustomObject onSuccess : " + customMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithEmptyCustomObject onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test + public void sendTextMessageWithNullPara() { + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); +// +// JSONObject customData = new JSONObject(); +// customData.put("lattitue","19.0760"); +// customData.put("longitude","72.8777"); + + TextMessage textMessage = new TextMessage(null, null, CometChatConstants.MESSAGE_TYPE_TEXT,null); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithNullPara onSuccess : " + textMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithNullPara onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test + public void sendCustomMessageWithNullPara() { + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); +// +// JSONObject customData = new JSONObject(); +// customData.put("lattitue","19.0760"); +// customData.put("longitude","72.8777"); + + CustomMessage customMessage = new CustomMessage(null, null, null, null); + + CometChat.sendCustomMessage(customMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(CustomMessage customMessage) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithNullPara onSuccess : " + customMessage.toString()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCustomMessageWithNullPara onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void sendTextMessageWithNullMessageAndReceiverType() { + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "Hello", CometChatConstants.MESSAGE_TYPE_TEXT,null); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithNullMessageAndReceiverType onSuccess: " + textMessage.toString()); + assertEquals("Hello", textMessage.getText()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithNullMessageAndReceiverType onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (InterruptedException e) { + + } + + } + + @Test + public void sendTextMessageWithMetaData() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "Hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + JSONObject customData = new JSONObject(); + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + textMessage.setMetadata(customData); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithMetaData onSuccess: " + textMessage.toString()); + assertEquals("Hello", textMessage.getText()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithMetaData onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (Exception e) { + + } + + } + + @Test + public void sendTextMessageWithNullMetaData() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(UID, "Hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + + textMessage.setMetadata(null); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithNullMetaData onSuccess: " + textMessage.toString()); + assertEquals("Hello", textMessage.getText()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithNullMetaData onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (Exception e) { + + } + + } + + @Test + public void sendTextMessageWithMetaGroupType() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(GUID, "Hello", CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.RECEIVER_TYPE_GROUP); + + JSONObject customData = new JSONObject(); + + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + textMessage.setMetadata(customData); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithMetaGroupType onSuccess: " + textMessage.toString()); + assertNotNull( textMessage.getMetadata()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithMetaGroupType onError: " + e.getMessage()); + assertEquals("Failed to validate the data sent with the request.", e.getMessage()); + } + }); + + + countDownLatch.await(8, TimeUnit.SECONDS); + + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (Exception e) { + + } + + } + @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + public void sendTextMessageWithMetaAndMUID() { + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage textMessage = new TextMessage(GUID, "Hello",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_GROUP); + + JSONObject customData = new JSONObject(); + + customData.put("lattitue", "19.0760"); + customData.put("longitude", "72.8777"); + + textMessage.setMetadata(customData); + + textMessage.setMuid("hey"); + + CometChat.sendMessage(textMessage, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendTextMessageWithMetaAndMUID onSuccess: " + textMessage.toString()); +// assertNotNull( textMessage.getMuid()); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendTextMessageWithMetaAndMUID onError: " + e.getMessage()); + assertNotNull("Failed to validate the data sent with the request.",null); + } + }); + + + countDownLatch.await(8, TimeUnit.SECONDS); + + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (Exception e) { + + } - assertEquals("com.inscripts.cometchat.demo", appContext.getPackageName()); } + + @Test + public void sendMessageWithNullTextMessageObject(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.sendMessage(null, new CometChat.CallbackListener() { + @Override + public void onSuccess(TextMessage textMessage) { + Log.d(TAG, "sendMessageWithNullTextMessageObject onSuccess: " + textMessage.toString()); + countDownLatch.countDown(); + assertNotNull( textMessage); + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendMessageWithNullTextMessageObject onError: " + e.getMessage()); + assertNotNull("Failed to validate the data sent with the request.",null); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } catch (Exception e) { + + } + + } + + @Test + public void sendImageMediaMessage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(filePath), CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendImageMediaMessage onSuccess: " + mediaMessage.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendImageMediaMessage onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + @Test + public void sendImageMediaMessageWithVideoType(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(filePath), CometChatConstants.MESSAGE_TYPE_VIDEO, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendImageMediaMessageWithVideoType onSuccess: " + mediaMessage.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendImageMediaMessageWithVideoType onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + @Test + public void sendImageMediaMessageWithAudioType(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(filePath), CometChatConstants.MESSAGE_TYPE_AUDIO, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendImageMediaMessageWithAudioType onSuccess: " + mediaMessage.toString()); + assertNotNull(mediaMessage.getAttachment()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendImageMediaMessageWithAudioType onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + @Test + public void sendImageMediaMessageWithCustomType(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(filePath), CometChatConstants.MESSAGE_TYPE_CUSTOM, CometChatConstants.RECEIVER_TYPE_USER); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendImageMediaMessageWithCustomType onSuccess: " + mediaMessage.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendImageMediaMessageWithCustomType onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + + @Test + public void sendImageMediaMessageWithCustomTypeInGroup(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(GUID, new File(filePath), CometChatConstants.MESSAGE_TYPE_CUSTOM, CometChatConstants.RECEIVER_TYPE_GROUP); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendImageMediaMessageWithCustomTypeInGroup onSuccess: " + mediaMessage.toString()); + assertNotNull(mediaMessage.getAttachment()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendImageMediaMessageWithCustomTypeInGroup onError: " + e.getMessage()); + countDownLatch.countDown(); +// assertNotNull("",null); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + @Test + public void sendVideoMediaMessage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(videoPath), CometChatConstants.MESSAGE_TYPE_VIDEO, CometChatConstants.RECEIVER_TYPE_USER); + + message.setCaption("Hello"); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendVideoMediaMessage onSuccess: " + mediaMessage.toString()); +// assertNotNull(mediaMessage.getAttachment()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendVideoMediaMessage onError: " + e.getMessage()); + countDownLatch.countDown(); +// assertNotNull("",null); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + @Test + public void sendVideoMediaMessageWithTypeImage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(videoPath), CometChatConstants.MESSAGE_TYPE_IMAGE, CometChatConstants.RECEIVER_TYPE_USER); + + message.setCaption("Hello"); + message.setMetadata(new JSONObject(message.getCaption())); + message.setUrl("okay"); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendVideoMediaMessageWithTypeImage onSuccess: " + mediaMessage.toString()); + countDownLatch.countDown(); + assertNotNull(mediaMessage.getAttachment()); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendVideoMediaMessageWithTypeImage onError: " + e.getMessage()); + countDownLatch.countDown(); + assertNotNull("",null); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + } + } + + + @Test + public void sendVideoMediaMessageWithTypeAudio(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MediaMessage message = new MediaMessage(UID, new File(videoPath), CometChatConstants.MESSAGE_TYPE_AUDIO, CometChatConstants.RECEIVER_TYPE_USER); + + message.setCaption("Hello"); + message.setMetadata(new JSONObject(message.getCaption())); + message.setUrl("okay"); + + CometChat.sendMediaMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendVideoMediaMessageWithTypeAudio onSuccess: " + mediaMessage.toString()); + countDownLatch.countDown(); + assertNotNull(mediaMessage.getAttachment()); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendVideoMediaMessageWithTypeAudio onError: " + e.getMessage()); + countDownLatch.countDown(); + assertNotNull("",null); + } + }); + + countDownLatch.await(15, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendEditMessage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, "text",CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + message.setId(MESSAGE_ID); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditMessage onSuccess: "+baseMessage.getEditedAt()); + assertEquals("text", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditMessage onError: "+e.getMessage()); + assertEquals("Message with id "+MESSAGE_ID+" does not exist.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendEditTextMessageWithImageType(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, "Hey", CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + message.setId(398); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditTextMessageWithImageType onSuccess: "+baseMessage.toString()+" "+baseMessage.getEditedAt()); + assertEquals("Hey", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditTextMessageWithImageType onError: "+e.getMessage()); + assertEquals("Message with id 398 does not exist.",e.getMessage()); +// assertNotNull(e.getMessage(),null); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendEditMessageWithTypeGroup(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, "Edit text Message ", CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.RECEIVER_TYPE_GROUP); + message.setId(489); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditMessageWithTypeUser onSuccess: "+baseMessage.getEditedAt()); + Log.d(TAG, "sendEditMessageWithTypeUser onSuccess: "+baseMessage.toString()); + assertEquals("Edit text Message ", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditMessageWithTypeUser onError: "+e.getMessage()); + assertNotNull("Message with id 489 does not exist.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendEditMessageWithNull(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, null,CometChatConstants.MESSAGE_TYPE_TEXT, CometChatConstants.RECEIVER_TYPE_USER); + message.setId(489); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditMessageWithNull onSuccess: "+baseMessage.getEditedAt()); + Log.d(TAG, "sendEditMessageWithNull onSuccess: "+baseMessage.toString()); + assertEquals("text", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditMessageWithNull onError: "+e.getMessage()); + assertNotNull("Failed to validate the data sent with the request.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendEditMessageWithWrongId(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, "h",CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.RECEIVER_TYPE_USER); + message.setId(48); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditMessageWithWrongId onSuccess: "+baseMessage.getEditedAt()); + Log.d(TAG, "sendEditMessageWithWrongId onSuccess: "+baseMessage.toString()); +// assertEquals("text", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + // TODO: 2019-08-19 check edit message feature in app + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditMessageWithWrongId onError: "+e.getMessage()); + assertNotNull("Failed to validate the data sent with the request.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + + @Test + public void sendEditMessageWithEmpty(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + TextMessage message = new TextMessage(UID, "", CometChatConstants.MESSAGE_TYPE_TEXT,CometChatConstants.RECEIVER_TYPE_USER); + message.setId(489); + + CometChat.editMessage(message, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendEditMessageWithEmpty onSuccess: "+baseMessage.getEditedAt()); + Log.d(TAG, "sendEditMessageWithEmpty onSuccess: "+baseMessage.toString()); + assertEquals("", ((TextMessage)baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendEditMessageWithEmpty onError: "+e.getMessage()); + assertNotNull("Failed to validate the data sent with the request.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendDeleteMessage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.deleteMessage(489, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "deleteMessage onSuccess: "+baseMessage.toString()); + assertNull(((TextMessage) baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "deleteMessage onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void sendDeleteDeletedMessage(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.deleteMessage(489, new CometChat.CallbackListener() { + @Override + public void onSuccess(BaseMessage baseMessage) { + Log.d(TAG, "sendDeleteDeletedMessage onSuccess: "+baseMessage.toString()); + assertNull(((TextMessage) baseMessage).getText()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendDeleteDeletedMessage onError: "+e.getMessage()); + assertEquals("Message with id 489 does not exist.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + @Test + public void userRequest(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequest onSuccess: "+users.size()); + assertEquals(4,users.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequest onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void userRequestWithOffline(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).setUserStatus(UsersRequest.USER_STATUS_OFFLINE).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithOffline onSuccess: "+users.size()); + + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithOffline onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + @Test + public void userRequestWithSearch(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).setSearchKeyword("iron Man").build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearch onSuccess: "+users.toString()); + assertEquals("Iron Man",users.get(0).getName()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearch onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + + @Test + public void userRequestWithSearchWithStatus(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100) + .setUserStatus(UsersRequest.USER_STATUS_OFFLINE) + .setSearchKeyword("iron Man").build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearchWithStatus onSuccess: "+users.toString()); + assertEquals("offline",users.get(0).getStatus()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearchWithStatus onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void userRequestWithSearchWithStatusNull(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100) + .setUserStatus(null) + .setSearchKeyword("iron Man").build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearchWithStatusNull onSuccess: "+users.size()); + + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearchWithStatusNull onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void userRequestWithSearchWithNull(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).setSearchKeyword(null).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearchWithNull onSuccess: "+users.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearchWithNull onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void userRequestWithSearchWithNullAndHideBlockerUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).hideBlockedUsers(true).setSearchKeyword(null).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearchWithNullAndHideBlockerUser onSuccess: "+users.size()); + assertEquals(3,users.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearchWithNullAndHideBlockerUser onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + + @Test + public void userRequestWithSearchWithNullAndShowBlockerUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + UsersRequest usersRequest=new UsersRequest.UsersRequestBuilder().setLimit(100).hideBlockedUsers(false).setSearchKeyword(null).build(); + + usersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "userRequestWithSearchWithNullAndShowBlockerUser onSuccess: "+users.size()); + assertEquals(4,users.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "userRequestWithSearchWithNullAndShowBlockerUser onError: "+e.getMessage()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void messageRequestFetchPrevious(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder().setLimit(100).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPrevious onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPrevious onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void messageRequestFetchPreviousWithId(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder().setMessageId(300).setLimit(100).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousWithId onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousWithId onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + + } + + @Test + public void messageRequestFetchNextWithId(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder().setMessageId(300).setLimit(100).build(); + + messagesRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchNextWithId onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchNextWithId onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + } + + @Test + public void messageRequestFetchNextWithUID(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder().setMessageId(300).setUID("superhero1").setLimit(100).build(); + + messagesRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchNextWithUID onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchNextWithUID onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + @Test + public void messageRequestFetchPreviousWithUIDAndLimit(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder().setMessageId(300).setUID("superhero1").setLimit(800).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousWithUID onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousWithUID onError: "+e.getMessage()); + assertEquals("Limit Exceeded Max limit of %s",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + @Test + public void messageRequestFetchPreviousAndLimitSearch(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setMessageId(300) + .setSearchKeyword("HEY") + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousAndLimitSearch onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousAndLimitSearch onError: "+e.getMessage()); + assertEquals("Limit Exceeded Max limit of %s",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + @Test + public void messageRequestFetchPreviousAndLimitSearchNull(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword(null) + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousAndLimitSearchNull onSuccess: "+messageList.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousAndLimitSearchNull onError: "+e.getMessage()); + assertEquals("Limit Exceeded Max limit of %s",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + @Test + public void messageRequestFetchPreviousWithBlockedUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword("hello") + .hideMessagesFromBlockedUsers(true) + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousWithBlockedUser onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousWithBlockedUser onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + @Test + public void messageRequestFetchPreviousUnreadWithBlockedUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword("hello") + .setUnread(true) + .hideMessagesFromBlockedUsers(true) + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousUnreadWithBlockedUser onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousUnreadWithBlockedUser onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + @Test + public void messageRequestFetchPreviousUnreadWithShowBlockedUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword("hello") + .setUnread(true) + .setMessageId(300) + .hideMessagesFromBlockedUsers(false) + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousUnreadWithShowBlockedUser onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousUnreadWithShowBlockedUser onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + @Test + public void messageRequestFetchNextUnreadWithShowBlockedUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword("hello") + .setUnread(true) + .setMessageId(300) + .hideMessagesFromBlockedUsers(false) + .setLimit(30).build(); + + messagesRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchNextUnreadWithShowBlockedUser onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchNextUnreadWithShowBlockedUser onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + @Test + public void messageRequestFetchNextUnreadWithBlockedUser(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setSearchKeyword("hello") + .setUnread(false) + .hideMessagesFromBlockedUsers(true) + .setLimit(30).build(); + + messagesRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchNextUnreadWithBlockedUser onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchNextUnreadWithBlockedUser onError: "+e.getMessage()); + assertNotNull("'Timestamp' or 'MessageId' required to use the 'fetchNext()' method.",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + @Test + public void messageRequestFetchPreviousWithGUID(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + MessagesRequest messagesRequest=new MessagesRequest.MessagesRequestBuilder() + .setGUID(GUID) + .hideMessagesFromBlockedUsers(true) + .setLimit(30).build(); + + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List messageList) { + Log.d(TAG, "messageRequestFetchPreviousWithGUID onSuccess: "+messageList.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "messageRequestFetchPreviousWithGUID onError: "+e.getMessage()); + + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + + } + + } + + + + @Test + public void sendGroupRequest(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + GroupsRequest groupsRequest=new GroupsRequest.GroupsRequestBuilder() + .setLimit(30) + .build(); + + groupsRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groups) { + Log.d(TAG, "sendGroupRequest onSuccess: "+groups.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendGroupRequest onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + e.printStackTrace(); + } + + } + + @Test + public void sendGroupRequestSearch(){ + + try { + CountDownLatch countDownLatch = new CountDownLatch(1); + + GroupsRequest groupsRequest=new GroupsRequest.GroupsRequestBuilder() + .setLimit(30) + .setSearchKeyWord("comic hero") + .build(); + + groupsRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groups) { + Log.d(TAG, "sendGroupRequestSearch onSuccess: "+groups.toString()); + assertEquals("Comic Heros' Hangout",groups.get(0).getName()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "sendGroupRequestSearch onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + } + catch (Exception e){ + e.printStackTrace(); + } + + } + + @Test + public void sendGetGroup(){ + + try { + + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.getGroup(GUID, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendgetGroup onSuccess: "+group.toString()); + assertEquals(GUID,group.getGuid()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendgetGroup onError: "+e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + } + + + @Test + public void sendCreateGroup(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("1","No 1",CometChatConstants.GROUP_TYPE_PUBLIC,"","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroup onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroup onError: "+e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + + @Test + public void sendCreateGroupWithNumber(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("0","No 1",CometChatConstants.GROUP_TYPE_PUBLIC,"","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithNumber onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithNumber onError: "+e.getMessage()); + assertEquals("Web socket process failed.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupWithNullGUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group(null,"No 1",CometChatConstants.GROUP_TYPE_PUBLIC,"","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithNullGUID onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithNullGUID onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void sendCreateGroupWithNullName(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("21",null,CometChatConstants.GROUP_TYPE_PUBLIC,"","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithNullName onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithNullName onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupWithPassword(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("21","password",CometChatConstants.GROUP_TYPE_PASSWORD,"123","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithPassword onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithPassword onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupWithPasswordTypePublic(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("22","password",CometChatConstants.GROUP_TYPE_PUBLIC,"123","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithPasswordTypePublic onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithPasswordTypePublic onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupWithPasswordWithNull(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("22","password",CometChatConstants.GROUP_TYPE_PASSWORD,null,"","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithPasswordWithNull onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithPasswordWithNull onError: "+e.getMessage()); + assertEquals("Password is mandatory for a protected group",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupGUIDEmptyWithPasswordWithLine(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("","password",CometChatConstants.GROUP_TYPE_PASSWORD,"","\n\n","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupGUIDEmptyWithPasswordWithLine onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupGUIDEmptyWithPasswordWithLine onError: "+e.getMessage()); + assertEquals("Password is mandatory for a protected group",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + + @Test + public void sendCreateGroupGUIDEmptyWithPassword(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("","password",CometChatConstants.GROUP_TYPE_PASSWORD,"1234","","Hello Description"); + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupGUIDEmptyWithPassword onSuccess: "+group.toString()); + assertEquals("Hello Description",group.getDescription()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupGUIDEmptyWithPassword onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void sendCreateGroupPrivate(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("133","password-2",CometChatConstants.GROUP_TYPE_PRIVATE,"1234","","Hello Description"); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("test","hello"); + group.setMetadata(jsonObject); + + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupPrivate onSuccess: "+group.toString()); + assertEquals("133",group.getGuid()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupPrivate onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupPrivateWithPassword(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("133","password-2",CometChatConstants.GROUP_TYPE_PRIVATE,"1234","","Hello Description"); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("test","hello"); + group.setMetadata(jsonObject); + + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupPrivate onSuccess: "+group.toString()); + assertEquals("133",group.getGuid()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupPrivate onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void sendCreateGroupWithLongName(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("135","zJfMus2WzLnMr82T4bmuzKTNjcylzYfNiGjMssyBZc2PzZPMvMyXzJnMvMyjzZQgzYfMnMyxzKDN\",\n" + + " \"k82NzYVOzZXNoGXMl8yxesyYzJ3MnMy6zZlwzKTMusy5zY3Mr82aZcygzLvMoM2ccsyozKTNjcy6\",\n" + + " \"zJbNlMyWzJZkzKDMn8ytzKzMnc2facymzZbMqc2TzZTMpGHMoMyXzKzNicyZbs2azZwgzLvMnsyw\",\n" + + " \"zZrNhWjMtc2JacyzzJ52zKLNh+G4mc2OzZ8t0onMrcypzLzNlG3MpMytzKtpzZXNh8ydzKZuzJfN\",\n" + + " \"meG4jcyfIMyvzLLNlc2ex6vMn8yvzLDMss2ZzLvMnWYgzKrMsMywzJfMlsytzJjNmGPMps2NzLLM\",\n" + + " \"ns2NzKnMmeG4pc2aYcyuzY7Mn8yZzZzGocypzLnNjnPMpC7MncydINKJWsyhzJbMnM2WzLDMo82J\",\n" + + " \"zJxhzZbMsM2ZzKzNoWzMssyrzLPNjcypZ8yhzJ/MvMyxzZrMnsyszYVvzJfNnC7Mnw==",CometChatConstants.GROUP_TYPE_PRIVATE,"1234","","Hello Description"); + JSONObject jsonObject=new JSONObject(); + jsonObject.put("test","hello"); + group.setMetadata(jsonObject); + + CometChat.createGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "sendCreateGroupWithLongName onSuccess: "+group.toString()); + assertEquals("zJfMus2WzLnMr82T4bmuzKTNjcylzYfNiGjMssyBZc2PzZPMvMyXzJnMvMyjzZQgzYfMnMyxzKDN\",\n" + + " \"k82NzYVOzZXNoGXMl8yxesyYzJ3MnMy6zZlwzKTMusy5zY3Mr82aZcygzLvMoM2ccsyozKTNjcy6\",\n" + + " \"zJbNlMyWzJZkzKDMn8ytzKzMnc2facymzZbMqc2TzZTMpGHMoMyXzKzNicyZbs2azZwgzLvMnsyw\",\n" + + " \"zZrNhWjMtc2JacyzzJ52zKLNh+G4mc2OzZ8t0onMrcypzLzNlG3MpMytzKtpzZXNh8ydzKZuzJfN\",\n" + + " \"meG4jcyfIMyvzLLNlc2ex6vMn8yvzLDMss2ZzLvMnWYgzKrMsMywzJfMlsytzJjNmGPMps2NzLLM\",\n" + + " \"ns2NzKnMmeG4pc2aYcyuzY7Mn8yZzZzGocypzLnNjnPMpC7MncydINKJWsyhzJbMnM2WzLDMo82J\",\n" + + " \"zJxhzZbMsM2ZzKzNoWzMssyrzLPNjcypZ8yhzJ/MvMyxzZrMnsyszYVvzJfNnC7Mnw==",group.getName()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "sendCreateGroupWithLongName onError: "+e.getMessage()); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void sendJoinGroupPrivate(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.joinGroup("133", CometChatConstants.GROUP_TYPE_PRIVATE, null, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "joinGroup onSuccess: "+group.toString()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "joinGroup onError: "+e.getMessage()); + assertEquals("The private groups cannot be joined. Users need to be added to such groups.",e.getMessage()); + } + }); + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void test_joinGroupPassword(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.joinGroup("21", CometChatConstants.GROUP_TYPE_PASSWORD, "123", new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "joinGroup onSuccess: "+group.toString()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "joinGroup onError: "+e.getMessage()); + assertEquals("The user with uid superhero2 has already joined the group with guid 21.",e.getMessage()); + } + }); + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void test_joinGroupWithEmptyGUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.joinGroup("", CometChatConstants.GROUP_TYPE_PASSWORD, "", new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "joinGroupWithEmptyGUID onSuccess: "+group.toString()); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + countDownLatch.countDown(); + Log.d(TAG, "joinGroupWithEmptyGUID onError: "+e.getMessage()); + assertEquals("Please provide a valid GUID",e.getMessage()); + } + }); + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_addMemberToGroup(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + List groupMemberList=new ArrayList<>(); + groupMemberList.add(new GroupMember("superhero1",CometChatConstants.SCOPE_ADMIN)); + + CometChat.addMembersToGroup("133", groupMemberList, null, new CometChat.CallbackListener>() { + + @Override + public void onSuccess(HashMap stringStringHashMap) { + Log.d(TAG, "test_addMemberToGroup onSuccess: "+stringStringHashMap.toString()); +// assertEquals("success",stringStringHashMap.get("superhero1")); + assertEquals("Member already has the same scope admin",stringStringHashMap.get("superhero1")); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_addMemberToGroup onError: "+e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_addMemberToGroupWithEmptyGUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + List groupMemberList=new ArrayList<>(); + groupMemberList.add(new GroupMember("superhero1",CometChatConstants.SCOPE_ADMIN)); + + CometChat.addMembersToGroup("", groupMemberList, null, new CometChat.CallbackListener>() { + + @Override + public void onSuccess(HashMap stringStringHashMap) { + Log.d(TAG, "test_addMemberToGroup onSuccess: "+stringStringHashMap.toString()); +// assertEquals("Member already has the same scope admin",stringStringHashMap.get("superhero1")); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_addMemberToGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + assertEquals("Please provide a valid GUID",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void test_addMemberToGroupWithEmptyList(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + List groupMemberList=new ArrayList<>(); +// groupMemberList.add(new GroupMember("superhero1",CometChatConstants.SCOPE_ADMIN)); + + CometChat.addMembersToGroup("133", groupMemberList, null, new CometChat.CallbackListener>() { + + @Override + public void onSuccess(HashMap stringStringHashMap) { + Log.d(TAG, "test_addMemberToGroupWithEmptyList onSuccess: "+stringStringHashMap.toString()); + assertEquals("Member already has the same scope admin",stringStringHashMap.get("superhero1")); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_addMemberToGroupWithEmptyList onError: "+e.getMessage()); + countDownLatch.countDown(); + assertEquals("The list provided is empty. Please provide a valid list.",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_leaveGroup(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + + CometChat.leaveGroup("133", new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_leaveGroup onSuccess: "+s); + assertEquals("Group left successfully",s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_leaveGroup onError: "+e.getMessage()); + assertEquals("ERR_NOT_A_MEMBER",e.getCode()); + countDownLatch.countDown(); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + @Test + public void test_leaveGroupWithEmptyGUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + + CometChat.leaveGroup("", new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_leaveGroupWithEmptyGUID onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_leaveGroupWithEmptyGUID onError: "+e.getMessage()); + assertEquals("Please provide a valid GUID",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + @Test + public void updateGroup(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("123","Updated Group",CometChatConstants.GROUP_TYPE_PRIVATE,null,null,null); + CometChat.updateGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "updateGroup onSuccess: "+group.toString()); + assertEquals("123",group.getGuid()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "updateGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + @Test + public void updateGroupPublic(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("123","Updated Group",CometChatConstants.GROUP_TYPE_PUBLIC,null,null,null); + CometChat.updateGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "updateGroup onSuccess: "+group.toString()); + assertEquals("123",group.getGuid()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "updateGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + + @Test + public void updateGroupPassword(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("123","Updated Group","protected","123",null,null); + + CometChat.updateGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "updateGroup onSuccess: "+group.toString()); + assertEquals("123",group.getGuid()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "updateGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + @Test + public void updateGroupWithEmptyName(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + Group group=new Group("123","",CometChatConstants.GROUP_TYPE_PUBLIC,"123",null,null); + + CometChat.updateGroup(group, new CometChat.CallbackListener() { + @Override + public void onSuccess(Group group) { + Log.d(TAG, "updateGroupWithEmptyName onSuccess: "+group.toString()); + assertEquals("123",group.getGuid()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "updateGroupWithEmptyName onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + + @Test + public void test_deleteGroup(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.deleteGroup("123", new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_deleteGroup onSuccess: "+s); + countDownLatch.countDown(); + assertEquals("Group deleted successfully.",s); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_deleteGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + assertEquals("The group with guid 123 does not exist. Please use correct guid or use create group API.",e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + + @Test + public void test_kickGroupMember(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.kickGroupMember("superhero1", "21", new CometChat.CallbackListener() { + + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_kickGroup onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_kickGroup onError: "+e.getMessage()); + countDownLatch.countDown(); + assertNotNull(e.getMessage()); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + } + + @Test + public void test_kickGroupMemberEmptyUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.kickGroupMember("", "21", new CometChat.CallbackListener() { + + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_kickGroupMemberEmptyUID onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_kickGroupMemberEmptyUID onError: "+e.getMessage()); + countDownLatch.countDown(); + assertEquals("Please provide a valid UID",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_banGroupMember(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.banGroupMember("superhero3", "21", new CometChat.CallbackListener() { + + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_banGroupMember onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_banGroupMember onError: "+e.getMessage()); + countDownLatch.countDown(); + assertNotNull(e.getMessage()); +// assertEquals("The user with uid superhero2 does not have enough clearance to ban the user with uid superhero3 from group with guid 21.",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_unbanGroupMember(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.unbanGroupMember("superhero3", "21", new CometChat.CallbackListener() { + + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_unbanGroupMember onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_unbanGroupMember onError: "+e.getMessage()); + countDownLatch.countDown(); + assertEquals("The user with uid superhero2 does not have enough clearance to unban the user with uid superhero3 from group with guid {{guid}}.",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void test_unbanGroupMemberWithEmptyUID(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + CometChat.unbanGroupMember("", "21", new CometChat.CallbackListener() { + + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_unbanGroupMemberWithEmptyUID onSuccess: "+s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_unbanGroupMemberWithEmptyUID onError: "+e.getMessage()); + countDownLatch.countDown(); +// assertEquals("The user with uid superhero2 does not have enough clearance to ban the user with uid superhero3 from group with guid 21.",e.getMessage()); + + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + @Test + public void bannedGroupMemberRequest(){ + + try { + + CountDownLatch countDownLatch=new CountDownLatch(1); + + BannedGroupMembersRequest bannedGroupMembersRequest=new BannedGroupMembersRequest.BannedGroupMembersRequestBuilder("21").setLimit(30).build(); + + bannedGroupMembersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groupMembers) { + Log.d(TAG, "bannedGroupMembersRequest onSuccess: "+groupMembers.toString()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "bannedGroupMembersRequest onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + }catch (Exception e){ + + } + + } + + @Test + public void test_changeMemberScope(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + CometChat.updateGroupMemberScope("superhero2", "supergroup", CometChatConstants.SCOPE_ADMIN, new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "updateGroupMemberScope onSuccess: " + s); + assertEquals("Group member scope changed successfully.",s); + countDownLatch.countDown(); + + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "updateGroupMemberScope onError: " + e.getMessage()); + countDownLatch.countDown(); + } + }); + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + e.printStackTrace(); + } + + } + + @Test + public void test_changeMemberScopeWithEmptyScope(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + CometChat.updateGroupMemberScope("superhero2", "supergroup", "", new CometChat.CallbackListener() { + @Override + public void onSuccess(String s) { + Log.d(TAG, "test_changeMemberScopeWithEmptyScope onSuccess: " + s); + assertEquals("Group member scope changed successfully.",s); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_changeMemberScopeWithEmptyScope onError: " + e.getMessage()); + countDownLatch.countDown(); + assertEquals("Failed to validate the data sent with the request.",e.getMessage()); + } + }); + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + e.printStackTrace(); + } + + } + + + @Test + public void test_GroupMemberRequest(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder("supergroup").setLimit(30).build(); + + groupMembersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groupMembers) { + Log.d(TAG, "test_GroupMemberRequest onSuccess: "+groupMembers.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_GroupMemberRequest onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + + } + + @Test + public void test_GroupMemberRequestWithZeroLimit(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder("supergroup").setLimit(0).build(); + + groupMembersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groupMembers) { + Log.d(TAG, "test_GroupMemberRequestWithZeroLimit onSuccess: "+groupMembers.size()); + assertEquals(3,groupMembers.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_GroupMemberRequestWithZeroLimit onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + + } + + + @Test + public void test_GroupMemberRequestWithEmptyGUID(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder("").setLimit(0).build(); + + groupMembersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List groupMembers) { + Log.d(TAG, "test_GroupMemberRequestWithEmptyGUID onSuccess: "+groupMembers.size()); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_GroupMemberRequestWithEmptyGUID onError: "+e.getMessage()); + assertEquals("Please provide a valid GUID",e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + + + } + + + @Test + public void test_blockedUser(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + BlockedUsersRequest blockedUsersRequest=new BlockedUsersRequest.BlockedUsersRequestBuilder().setLimit(30).build(); + + blockedUsersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "test_blockedUser onSuccess: "+users.toString()); + assertNotNull(users); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_blockedUser onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + @Test + public void test_blockedUserWithoutLimit(){ + + try { + + CountDownLatch countDownLatch = new CountDownLatch(1); + + BlockedUsersRequest blockedUsersRequest=new BlockedUsersRequest.BlockedUsersRequestBuilder().build(); + + blockedUsersRequest.fetchNext(new CometChat.CallbackListener>() { + @Override + public void onSuccess(List users) { + Log.d(TAG, "test_blockedUserWithoutLimit onSuccess: "+users.toString()); + assertNotNull(users); + countDownLatch.countDown(); + } + + @Override + public void onError(CometChatException e) { + Log.d(TAG, "test_blockedUserWithoutLimit onError: "+e.getMessage()); + countDownLatch.countDown(); + } + }); + + countDownLatch.await(8, TimeUnit.SECONDS); + if (countDownLatch.getCount() == 1) { + assertNotEquals("CometChat timeout", null); + } + + }catch (Exception e){ + + } + } + + + + + } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 134e3400..b431b024 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true" + android:largeHeap="true" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:allowBackup"> diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java index ee7b13f9..7ad059fe 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/CometChatActivity.java @@ -18,6 +18,8 @@ import android.view.Menu; import android.view.MenuItem; import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.models.Action; +import com.cometchat.pro.models.Group; import com.cometchat.pro.models.User; import com.inscripts.cometchatpulse.demo.Adapter.ViewPagerAdapter; import com.inscripts.cometchatpulse.demo.Contracts.CometChatActivityContract; @@ -56,7 +58,6 @@ public class CometChatActivity extends AppCompatActivity implements ScrollHelper private static final String TAG = "CometChatActivity"; - public static HashMap countMap; private MenuItem searchItem; @@ -132,6 +133,20 @@ public void onPageScrollStateChanged(int i) { @Override protected void onStart() { super.onStart(); + + CometChat.addGroupListener(TAG, new CometChat.GroupListener() { + @Override + public void onMemberAddedToGroup(Action action, User addedby, User userAdded, Group addedTo) { + super.onMemberAddedToGroup(action, addedby, userAdded, addedTo); + Log.d(TAG, "onMemberAddedToGroup: "+"action \n"+action+" \n addedby "+addedby+ " \n userAdded "+userAdded + " \n addedTo "+addedTo); + } + + @Override + public void onAddedToGroup(Action action, User addedby, User userAdded, Group addedTo) { + super.onAddedToGroup(action, addedby, userAdded, addedTo); + Log.d(TAG, "onAddedToGroup: "+"action \n"+action+" \n addedby "+addedby+ " \n userAdded "+userAdded + " \n addedTo "+addedTo); + } + }); } @Override @@ -220,6 +235,8 @@ public boolean onClose() { return true; } + + private void searchUser(String s) { switch (pageNumber){ diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java index 1b8e2162..9d649272 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/GroupChatActivity.java @@ -78,7 +78,7 @@ public class GroupChatActivity extends AppCompatActivity implements GroupChatActivityContract.GroupChatView, TextWatcher, View.OnClickListener, ActionMode.Callback { - private static final int LIMIT = 30; + private static final int LIMIT = 100; private static final String TAG = "GroupChatActivity"; @@ -566,7 +566,6 @@ public void run() { @Override protected void onStart() { super.onStart(); - } @@ -576,6 +575,7 @@ protected void onResume() { super.onResume(); groupChatPresenter.addMessageReceiveListener(getResources().getString(R.string.group_message_listener), groupId, ownerId); groupChatPresenter.addGroupEventListener("action_message", groupId, ownerId); + groupChatPresenter.refreshList(groupId,ownerId,LIMIT); groupChatPresenter.addCallListener("call_listener"); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/IncomingCallActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/IncomingCallActivity.java index 10f84e46..553746c7 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/IncomingCallActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/IncomingCallActivity.java @@ -279,8 +279,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis switch (requestCode) { case CAMERA_CODE: - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && - grantResults[1] == PackageManager.PERMISSION_GRANTED) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { camera = MediaUtils.openFrontCam(); cameraPreview = new CameraPreview(this, camera); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/LoginActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/LoginActivity.java index 1b45fe89..7044db72 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/LoginActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/LoginActivity.java @@ -80,7 +80,7 @@ private void login(){ if (!uid.isEmpty()) { Toast.makeText(LoginActivity.this, getString(R.string.wait), Toast.LENGTH_SHORT).show(); - loginActivityPresenter.Login(uid); + loginActivityPresenter.Login(this,uid); } else { Toast.makeText(LoginActivity.this, getString(R.string.enter_uid_toast), Toast.LENGTH_SHORT).show(); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java index 09807567..b74f050e 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Activity/OneToOneChatActivity.java @@ -642,6 +642,7 @@ protected void onResume() { Logger.error(TAG, "onResume: "); oneToOnePresenter.addPresenceListener(getString(R.string.presenceListener)); oneToOnePresenter.addMessageReceiveListener(contactUid); + oneToOnePresenter.refreshList(contactUid,LIMIT); oneToOnePresenter.addCallEventListener(TAG); } @@ -923,7 +924,6 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } else { sendButton.setTextColor(getResources().getColor(R.color.secondaryTextColor)); - } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java index 93a87250..cd05bf4b 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/GroupMessageAdapter.java @@ -326,10 +326,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) leftMessageViewHolder.senderName.setTypeface(FontUtils.robotoMedium); setAvatar(leftMessageViewHolder.avatar, avatar); - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - break; case RIGHT_TEXT_MESSAGE: RightMessageViewHolder rightMessageViewHolder = (RightMessageViewHolder) viewHolder; @@ -362,10 +358,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) String finalMediaFile7 = mediaFile; leftImageViewHolder.imageMessage.setOnClickListener(view -> startIntent(finalMediaFile7, false)); } - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - break; case RIGHT_IMAGE_MESSAGE: RightImageVideoViewHolder rightImageVideoViewHolder = (RightImageVideoViewHolder) viewHolder; @@ -421,9 +413,6 @@ public void onClick(View view) { startIntent(finalMediaFile3, true); } }); - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } break; case RIGHT_VIDEO_MESSAGE: @@ -595,10 +584,6 @@ public void run() { String audioPath = FileUtils.getPath(context, CometChatConstants.MESSAGE_TYPE_AUDIO) + FileUtils.getFileName(mediaFile); - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - File audioFile = new File(audioPath); audioFile.setReadable(true,false); if (audioFile.exists()) { @@ -784,9 +769,6 @@ public void onClick(View view) { } }); - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } } catch (Exception e) { e.printStackTrace(); } @@ -874,11 +856,6 @@ public void onClick(View view) { leftTextReplyViewHolder.tvNameReply.setText(textMessage.getMetadata().getString("senderName")); } } - - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - leftTextReplyViewHolder.tvNewMessage.setVisibility(View.VISIBLE); leftTextReplyViewHolder.tvNewMessage.setText(textMessage.getText()); @@ -1102,10 +1079,6 @@ public void run() { setAvatar(leftMediaReplyViewHolder.ivContactImage, avatar); - if (baseMessage.getReadByMeAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - try { if (mediaMessage != null) { if (mediaMessage.getMetadata().has("senderUid")) { @@ -1318,8 +1291,7 @@ public void run() { public void onCompletion(MediaPlayer mp) { currentPlayingSong = ""; currentlyPlayingId = 0l; - seekHandler - .removeCallbacks(timerRunnable); + seekHandler.removeCallbacks(timerRunnable); timerRunnable = null; mp.stop(); audioLength.setText(DateUtils.convertTimeStampToDurationTime(duration)); @@ -1509,7 +1481,6 @@ private void setDeliveryIcon(CircleImageView circleImageView,BaseMessage baseMes private void setReadIcon(CircleImageView circleImageView,BaseMessage baseMessage){ if (baseMessage.getReadAt()!=0){ - circleImageView.setImageResource(R.drawable.ic_double_tick_blue); circleImageView.setCircleBackgroundColor(context.getResources().getColor(android.R.color.transparent)); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java index 7a701b8b..cbbf6539 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Adapter/OneToOneAdapter.java @@ -283,9 +283,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { leftMessageViewHolder.messageTimeStamp.setText(timeStampString); leftMessageViewHolder.senderName.setVisibility(View.GONE); leftMessageViewHolder.avatar.setVisibility(View.GONE); - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } + break; case RIGHT_TEXT_MESSAGE: @@ -295,12 +293,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { rightMessageViewHolder.messageTimeStamp.setText(timeStampString); setDeliveryIcon(rightMessageViewHolder.messageStatus,baseMessage); setReadIcon(rightMessageViewHolder.messageStatus,baseMessage); - -// if (baseMessage.getDeletedAt()!=0){ -// rightMessageViewHolder.messageStatus.setVisibility(View.GONE); -// rightMessageViewHolder.textMessage.setVisibility(View.GONE); -// rightMessageViewHolder.messageTimeStamp.setVisibility(View.GONE); -// } break; case LEFT_IMAGE_MESSAGE: @@ -319,9 +311,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { String finalImageUrl1 = imageUrl; leftImageViewHolder.imageMessage.setOnClickListener(view -> startIntent(finalImageUrl1, false)); } - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } break; case RIGHT_IMAGE_MESSAGE: @@ -343,12 +332,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { setReadIcon(rightImageVideoViewHolder.messageStatus,baseMessage); -// if (baseMessage.getDeletedAt()!=0){ -// rightImageVideoViewHolder.messageTimeStamp.setVisibility(View.GONE); -// rightImageVideoViewHolder.messageStatus.setVisibility(View.GONE); -// rightImageVideoViewHolder.imageMessage.setVisibility(View.GONE); -// } - break; @@ -369,9 +352,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { final String finalMediaFile3 = mediaFile; leftVideoViewHolder.btnPlayVideo.setOnClickListener(view -> startIntent(finalMediaFile3, true)); - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } break; case RIGHT_VIDEO_MESSAGE: @@ -391,13 +371,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { rightVideoViewHolder.btnPlayVideo.setOnClickListener(view -> startIntent(finalMediaFile4, true)); setReadIcon(rightVideoViewHolder.messageStatus,baseMessage); - -// if (baseMessage.getDeletedAt()!=0){ -// rightVideoViewHolder.btnPlayVideo.setVisibility(View.GONE); -// rightVideoViewHolder.messageTimeStamp.setVisibility(View.GONE); -// rightVideoViewHolder.fileLoadingProgressBar.setVisibility(View.GONE); -// rightVideoViewHolder.messageStatus.setVisibility(View.GONE); -// } break; case RIGHT_AUDIO_MESSAGE: @@ -410,13 +383,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) { rightAudioViewHolder.playAudio.setImageResource(R.drawable.ic_play_arrow); } -// if (baseMessage.getDeletedAt()!=0){ -// rightAudioViewHolder.audioContainer.setVisibility(View.GONE); -// rightAudioViewHolder.messageTimeStamp.setVisibility(View.GONE); -// rightAudioViewHolder.audioSeekBar.setVisibility(View.GONE); -// rightAudioViewHolder.fileLoadingProgressBar.setVisibility(View.GONE); -// rightAudioViewHolder.messageStatus.setVisibility(View.GONE); -// } setDeliveryIcon(rightAudioViewHolder.messageStatus,baseMessage); rightAudioViewHolder.audioSeekBar.setProgress(0); String rightAudioPath = null; @@ -545,9 +511,6 @@ public void run() { leftAudioViewHolder.audioSeekBar.setProgress(0); final String finalMediaFile1 = mediaFile; - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } String audioPath = FileUtils.getPath(context, CometChatConstants.MESSAGE_TYPE_AUDIO)+ FileUtils.getFileName(mediaFile); @@ -706,12 +669,7 @@ public void run() { setReadIcon(rightFileViewHolder.messageStatus,baseMessage); rightFileViewHolder.fileName.setOnClickListener(view -> context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(finalMediaFile)))); -// if (baseMessage.getDeletedAt()!=0){ -// rightFileViewHolder.fileContainer.setVisibility(View.GONE); -// rightFileViewHolder.fileName.setVisibility(View.GONE); -// rightFileViewHolder.messageTimeStamp.setVisibility(View.GONE); -// rightFileViewHolder.fileType.setVisibility(View.GONE); -// } + } catch (Exception e) { e.printStackTrace(); } @@ -730,9 +688,7 @@ public void run() { leftFileViewHolder.fileType.setText(mediaMessage.getAttachment().getFileExtension()); final String finalMediaFile2 = mediaFile; - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } + leftFileViewHolder.fileName.setOnClickListener(view -> context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(finalMediaFile2)))); } catch (Exception e) { e.printStackTrace(); @@ -750,10 +706,6 @@ public void run() { rightTextReplyViewHolder.tvTimeStamp.setText(timeStampString); try { -// if (baseMessage.getDeletedAt()!=0){ -// rightTextReplyViewHolder.rlMain.setVisibility(View.GONE); -// rightTextReplyViewHolder.tvTimeStamp.setVisibility(View.GONE); -// } if (textMessage != null) { if (textMessage.getMetadata().has("senderUid")) { @@ -829,9 +781,6 @@ public void run() { } } - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } leftTextReplyViewHolder.tvNewMessage.setVisibility(View.VISIBLE); leftTextReplyViewHolder.tvNewMessage.setText(textMessage.getText()); @@ -1058,10 +1007,6 @@ public void run() { leftMediaReplyViewHolder.ivContactImage.setVisibility(View.GONE); - if (baseMessage.getReadAt()==0){ - CometChat.markMessageAsRead(baseMessage); - } - try { if (mediaMessage != null) { if (mediaMessage.getMetadata().has("senderUid")) { @@ -1467,7 +1412,10 @@ public void Delivered(MessageReceipt messageReceipt) { public void setRead(MessageReceipt messageReceipt) { BaseMessage baseMessage=messageArrayList.get(messageReceipt.getMessageId()); if (baseMessage!=null) { - baseMessage.setReadAt(messageReceipt.getTimestamp()); + baseMessage.setReadAt(messageReceipt.getReadAt()); + Log.d(TAG, "setRead:getTimestamp "+messageReceipt.getTimestamp()+" Id "+messageReceipt.getMessageId()); + Log.d(TAG, "setRead: getReadAt "+messageReceipt.getReadAt()+" Id "+messageReceipt.getMessageId()); + Log.d(TAG, "setRead: baseMessage "+baseMessage.toString()); messageArrayList.put(baseMessage.getId(), baseMessage); notifyDataSetChanged(); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/AsyncTask/DownloadFile.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/AsyncTask/DownloadFile.java index b3160996..9ec55f80 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/AsyncTask/DownloadFile.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/AsyncTask/DownloadFile.java @@ -9,9 +9,6 @@ import com.inscripts.cometchatpulse.demo.R; import com.inscripts.cometchatpulse.demo.Utils.FileUtils; import com.inscripts.cometchatpulse.demo.ViewHolders.LeftAudioViewHolder; - -import org.jivesoftware.smack.util.Async; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java index c6b33649..2e7b9344 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/CometApplication.java @@ -1,14 +1,14 @@ package com.inscripts.cometchatpulse.demo; import android.app.Application; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.os.Build; +import android.os.StrictMode; import android.util.Log; import android.widget.Toast; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; import com.inscripts.cometchatpulse.demo.Contracts.StringContract; +import java.util.ArrayList; +import java.util.List; public class CometApplication extends Application { @@ -16,9 +16,11 @@ public class CometApplication extends Application { @Override public void onCreate() { - super.onCreate(); + StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); + StrictMode.setVmPolicy(builder.build()); + CometChat.init(this,StringContract.AppDetails.APP_ID,new CometChat.CallbackListener() { @Override @@ -28,9 +30,10 @@ public void onSuccess(String s) { @Override public void onError(CometChatException e) { + Toast.makeText(CometApplication.this, e.getMessage(), Toast.LENGTH_SHORT).show(); Log.d(TAG, "onError: "+e.getMessage()); } - + }); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java index e63efc41..7b2490b6 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/GroupChatActivityContract.java @@ -89,6 +89,8 @@ interface GroupChatPresenter extends BasePresenter { void editMessage(BaseMessage baseMessage, String message); void searchMessage(String s, String groupId); + + void refreshList(String groupId, String ownerId, int limit); } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/LoginActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/LoginActivityContract.java index 19fd2559..e1770a74 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/LoginActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/LoginActivityContract.java @@ -1,5 +1,7 @@ package com.inscripts.cometchatpulse.demo.Contracts; +import android.content.Context; + import com.inscripts.cometchatpulse.demo.Base.BasePresenter; public interface LoginActivityContract { @@ -11,7 +13,7 @@ interface LoginActivityView { interface LoginActivityPresenter extends BasePresenter { - void Login(String uid); + void Login(Context context,String uid); void loginCheck(); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java index daddaa52..f1387783 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/OneToOneActivityContract.java @@ -99,5 +99,7 @@ interface OneToOnePresenter extends BasePresenter { void editMessage(BaseMessage baseMessage,String message); void searchMessage(String s,String UID); + + void refreshList(String contactUid, int limit); } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java index d334910d..4eb69d45 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Contracts/StringContract.java @@ -25,7 +25,7 @@ public static class IntentStrings { public static final String NAME = "name"; public static final String ID = "id"; public static final String AVATAR = "avatar"; - public static final String ISVIDEO ="isvideo"; + public static final String ISVIDEO ="isVideo"; public static final String INTENT_SCOPE = "intent_scope"; } @@ -45,7 +45,8 @@ public static class RequestCode { } public static class AppDetails{ - public static final String APP_ID = "XXXXXXXXXXXXXX"; - public static final String API_KEY = "XXXXXXXXXXXXXX"; + public static final String APP_ID = "XXXXXXXXXXXXXXX"; + public static final String API_KEY = "XXXXXXXXXXXXXXXXXXXXX"; + } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Fragments/GroupListFragment.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Fragments/GroupListFragment.java index c1201d11..199e9375 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Fragments/GroupListFragment.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Fragments/GroupListFragment.java @@ -210,7 +210,7 @@ public void onPause() { @Override public void onResume() { super.onResume(); - + groupPresenter.refresh(); } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Helper/AttachmentHelper.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Helper/AttachmentHelper.java index 00a86884..82e208cc 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Helper/AttachmentHelper.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Helper/AttachmentHelper.java @@ -7,11 +7,14 @@ import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Build; import android.os.Environment; +import android.os.FileUriExposedException; import android.provider.DocumentsContract; import android.provider.MediaStore; +import android.util.Log; import android.widget.Toast; import com.cometchat.pro.constants.CometChatConstants; @@ -22,12 +25,21 @@ import com.inscripts.cometchatpulse.demo.Utils.Logger; import com.inscripts.cometchatpulse.demo.Utils.MediaUtils; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; import java.net.URISyntaxException; +import java.text.SimpleDateFormat; +import java.util.Date; public class AttachmentHelper { + private static final String TAG = "AttachmentHelper"; + + public static String pictureImagePath = ""; + public static void selectMedia(Activity activity, String Type, String[] extraMimeType, int requestCode) { @@ -127,16 +139,11 @@ private static

void sendMedia(File file, String contactId, String type, P pr } public static

void handleCameraImage(Context context, P presenter, Intent data, String contactId) { - File file = null; - Logger.error("uri", String.valueOf(data.getData())); - Bitmap bitmap = (Bitmap) data.getExtras().get("data"); - Uri fileUri = MediaUtils.getImageUri(context, bitmap); - - Logger.error("", "fileUri: " + fileUri); - file = new File(MediaUtils.ImagePath(fileUri, context)); + File file = new File(pictureImagePath); +// if (file.exists()) { - + BitmapFactory.decodeFile(file.getAbsolutePath()); if (presenter instanceof OneToOneActivityPresenter) { ((OneToOneActivityPresenter) presenter).sendMediaMessage(file, contactId, CometChatConstants.MESSAGE_TYPE_IMAGE); } else if (presenter instanceof GroupChatPresenter) { @@ -146,6 +153,26 @@ public static

void handleCameraImage(Context context, P presenter, Intent da } + private static File persistImage(Context context,Bitmap bitmap) { + File filesDir = context.getFilesDir(); + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + File imageFile = new File(filesDir, timeStamp + ".jpg"); + + OutputStream os; + try { + os = new FileOutputStream(imageFile); + bitmap.compress(Bitmap.CompressFormat.PNG, 0, os); + os.flush(); + os.close(); + } catch (Exception e) { + + } + finally { + + return imageFile; + } + } + public static

void handleCameraVideo(Context context, P presenter, Intent data, String contactId) { String path = MediaUtils.getVideoPath(data.getData(), context); Logger.debug("handleCameraVideo", " Video Path" + path); @@ -257,8 +284,23 @@ public static boolean isMediaDocument(Uri uri) { } public static void captureImage(Activity activity, int code) { - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - activity.startActivityForResult(intent, code); + + try { + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String imageFileName = timeStamp + ".jpg"; + File storageDir = Environment.getExternalStoragePublicDirectory( + Environment.DIRECTORY_PICTURES); + pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName; + File file = new File(pictureImagePath); + Uri outputFileUri; +// if () + outputFileUri= Uri.fromFile(file); + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); + activity.startActivityForResult(intent, code); + }catch (Exception e){ + e.printStackTrace(); + } } public static void captureVideo(Activity activity, int code) { diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/BlockedUserListActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/BlockedUserListActivityPresenter.java index afdeab2b..5e902d10 100644 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/BlockedUserListActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/BlockedUserListActivityPresenter.java @@ -24,7 +24,7 @@ public class BlockedUserListActivityPresenter extends Presenter>() { @Override diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java index bb6b60af..1bd76866 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/ContactsListPresenter.java @@ -30,7 +30,7 @@ public void fetchUsers() { if (usersRequest==null) { - usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(30).build(); + usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(100).build(); usersRequest.fetchNext(new CometChat.CallbackListener>() { @Override @@ -42,7 +42,6 @@ public void onSuccess(List users) { userHashMap.put(users.get(i).getUid(), users.get(i)); } getBaseView().setContactAdapter(userHashMap); - } @Override @@ -81,11 +80,13 @@ public void addPresenceListener(String presenceListener) { CometChat.addUserListener(presenceListener, new CometChat.UserListener() { @Override public void onUserOnline(User user) { + Log.d(TAG, "onUserOnline: "+user.toString()); getBaseView().updatePresence(user); } @Override public void onUserOffline(User user) { + Log.d(TAG, "onUserOffline: "+user.toString()); getBaseView().updatePresence(user); } }); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/CreateGroupActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/CreateGroupActivityPresenter.java index 51e1a2fc..c9342cb1 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/CreateGroupActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/CreateGroupActivityPresenter.java @@ -37,6 +37,7 @@ public void onSuccess(Group group) { @Override public void onError(CometChatException e) { Log.d("createGroup", "onError: "+e.getMessage()); + Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } }); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java index 0247cf53..16d13e29 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupChatPresenter.java @@ -54,7 +54,6 @@ public class GroupChatPresenter extends Presenter() { @Override public void onSuccess(Call call) { @@ -325,7 +356,7 @@ public void onError(CometChatException e) { @Override public void editMessage(BaseMessage baseMessage, String message) { - TextMessage textMessage=new TextMessage(baseMessage.getReceiverUid(),message, baseMessage.getType(),baseMessage.getReceiverType()); + TextMessage textMessage=new TextMessage(baseMessage.getReceiverUid(),message,CometChatConstants.MESSAGE_TYPE_TEXT,baseMessage.getReceiverType()); textMessage.setId(baseMessage.getId()); CometChat.editMessage(textMessage, new CometChat.CallbackListener() { @Override @@ -385,6 +416,11 @@ public void onSuccess(List baseMessages) { Log.d(TAG, "onSuccess: fetchPrevious" + baseMessage.toString()); Logger.error("groupMessage" + baseMessage.getId() + " timestamp : " + baseMessage.getSentAt() + " list size :" + baseMessages.size()); + if (!baseMessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { + if (baseMessage.getReadByMeAt() == 0) { + CometChat.markMessageAsRead(baseMessage); + } + } if (baseMessage.getDeletedAt() == 0) { list.add(baseMessage); } @@ -413,6 +449,12 @@ public void onSuccess(List baseMessages) { if (baseMessage.getDeletedAt() == 0) { list.add(baseMessage); } + if (!baseMessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { + if (baseMessage.getReadByMeAt() == 0) { + CometChat.markMessageAsRead(baseMessage); + } + } + } getBaseView().setAdapter(baseMessages); @@ -503,7 +545,8 @@ public void onSuccess(MediaMessage mediaMessage1) { @Override public void onError(CometChatException e) { - + Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d(TAG, "onError: "+e.getMessage()); } }); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java index 7d1d7b50..b45ea6b5 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/GroupDetailActivityPresenter.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.Intent; +import android.util.Log; import android.widget.ImageView; import android.widget.Toast; @@ -22,6 +23,8 @@ public class GroupDetailActivityPresenter extends Presenter i private HashMap groupHashMap=new HashMap<>(); + private static final String TAG = "GroupListPresenter"; + @Override public void initGroupView() { @@ -36,7 +38,7 @@ public void initGroupView() { @Override public void onSuccess(List groups) { if (isViewAttached()) { - Logger.error("Groups List Received : " + groups); + Log.d(TAG, "onSuccess: "+groups.toString()); getBaseView().setGroupAdapter(groups); @@ -46,7 +48,7 @@ public void onSuccess(List groups) { @Override public void onError(CometChatException e) { - + Log.d(TAG, "onError: "+e.getMessage()); } }); @@ -54,10 +56,9 @@ public void onError(CometChatException e) { groupsRequest.fetchNext(new CometChat.CallbackListener>() { @Override public void onSuccess(List groups) { - Logger.error("Groups List Received : " + groups); + Log.d(TAG, "onSuccess: "+groups.toString()); if (isViewAttached()&&groups.size()!=0) { - getBaseView().setGroupAdapter(groups); } @@ -66,7 +67,7 @@ public void onSuccess(List groups) { @Override public void onError(CometChatException e) { - + Log.d(TAG, "onError: "+e.getMessage()); } }); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/IncomingCallActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/IncomingCallActivityPresenter.java index 1a61c9f0..88688ed5 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/IncomingCallActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/IncomingCallActivityPresenter.java @@ -34,18 +34,15 @@ public void handleIntent(Intent intent, Context context) { if (intent.hasExtra(StringContract.IntentStrings.ID)) { getBaseView().setContactUserId(intent.getStringExtra(StringContract.IntentStrings.ID)); } - if (intent.hasExtra(StringContract.IntentStrings.SESSION_ID)) { getBaseView().setSessionId(intent.getStringExtra(StringContract.IntentStrings.SESSION_ID)); } if (intent.hasExtra(StringContract.IntentStrings.AVATAR)) { getBaseView().setUserImage(intent.getStringExtra(StringContract.IntentStrings.AVATAR)); } - if (intent.hasExtra(StringContract.IntentStrings.NAME)) { getBaseView().setUserName(intent.getStringExtra(StringContract.IntentStrings.NAME)); } - try { boolean isVideo = intent.getAction().equals(CometChatConstants.CALL_TYPE_VIDEO); @@ -160,8 +157,6 @@ public void removeCallListener(String listenerId) { private void setContactImage(ImageView ivUserPic, String stringExtra) { if (stringExtra!=null) { Glide.with(context).load(stringExtra).into(ivUserPic); - }else { - } } } diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/LoginAcitivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/LoginAcitivityPresenter.java index 9fbdabb1..4a7dfd7a 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/LoginAcitivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/LoginAcitivityPresenter.java @@ -1,6 +1,11 @@ package com.inscripts.cometchatpulse.demo.Presenters; +import android.content.Context; +import android.util.Log; +import android.widget.Toast; + import com.inscripts.cometchatpulse.demo.Base.Presenter; +import com.inscripts.cometchatpulse.demo.CometApplication; import com.inscripts.cometchatpulse.demo.Contracts.LoginActivityContract; import com.cometchat.pro.core.CometChat; import com.cometchat.pro.exceptions.CometChatException; @@ -10,19 +15,23 @@ public class LoginAcitivityPresenter extends Presenter implements LoginActivityContract.LoginActivityPresenter{ + private static final String TAG = "LoginAcitivityPresenter"; @Override - public void Login(String uid) { + public void Login(Context context,String uid) { CometChat.login(uid, StringContract.AppDetails.API_KEY, new CometChat.CallbackListener() { @Override public void onSuccess(User user) { + Log.d(TAG, "onSuccess: "+user.getUid()); getBaseView().startCometChatActivity(); } @Override public void onError(CometChatException e) { e.printStackTrace(); + Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); + Log.d(TAG, "onError: "+e.getMessage()); } }); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java index 314e5123..0e3f5af8 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/OneToOneActivityPresenter.java @@ -49,7 +49,7 @@ public class OneToOneActivityPresenter extends Presenter() { @Override public void onSuccess(User user) { - if (isViewAttached()) { Log.d(TAG, "getUser onSuccess: "+user.toString()); getBaseView().setPresence(user); - } + } @Override public void onError(CometChatException e) { - Log.d(TAG, "onError: " + e.getMessage()); + Log.d(TAG, "getUser onError: " + e.getMessage()); } }); } @@ -127,6 +126,9 @@ public void onTextMessageReceived(TextMessage message) { if (message.getSender().getUid().equals(contactUid)) { MediaUtils.playSendSound(context, R.raw.receive); Log.d(TAG, "onTextMessageReceived: "+message.toString()); + if (message.getReadAt()==0){ + CometChat.markMessageAsRead(message); + } getBaseView().addSendMessage(message); } } @@ -136,6 +138,9 @@ public void onTextMessageReceived(TextMessage message) { public void onMediaMessageReceived(MediaMessage message) { if (isViewAttached()) { if (message.getSender().getUid().equals(contactUid)) { + if (message.getReadAt()==0){ + CometChat.markMessageAsRead(message); + } MediaUtils.playSendSound(context, R.raw.receive); getBaseView().addSendMessage(message); } @@ -205,12 +210,14 @@ public void sendMediaMessage(File filepath, String receiverUid, String type) { CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener() { @Override public void onSuccess(MediaMessage mediaMessage) { + Log.d(TAG, "sendMediaMessage onSuccess: "+mediaMessage.toString()); MediaUtils.playSendSound(context, R.raw.send); getBaseView().addMessage(mediaMessage); } @Override public void onError(CometChatException e) { + Log.d(TAG, "sendMediaMessage onError: "+e.getMessage()); } }); @@ -223,13 +230,23 @@ public void fetchPreviousMessage(String contactUid, int limit) { if (messagesRequest == null) { messagesRequest = new MessagesRequest.MessagesRequestBuilder().setUID(contactUid).setLimit(limit).build(); + messagesRequest.fetchPrevious(new CometChat.CallbackListener>() { @Override public void onSuccess(List baseMessages) { if (isViewAttached()) { for (BaseMessage baseMessage : baseMessages) { - Log.d(TAG, "onSuccess: delete "+baseMessage.getDeletedAt()); + + Log.d(TAG, "fetchPreviousMessage onSuccess: delete "+baseMessage.getDeletedAt()); + + Log.d(TAG, "fetchPreviousMessage onSuccess: "+baseMessage.toString()); if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)&&baseMessage.getDeletedAt()==0) { + + if (!baseMessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { + if (baseMessage.getReadAt() == 0) { + CometChat.markMessageAsRead(baseMessage); + } + } list.add(baseMessage); } } @@ -239,7 +256,7 @@ public void onSuccess(List baseMessages) { @Override public void onError(CometChatException e) { - Log.d(TAG, " onError: "+e.getMessage()); + Log.d(TAG, "fetchPreviousMessage onError: "+e.getMessage()); } }); @@ -256,6 +273,11 @@ public void onSuccess(List baseMessages) { if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)&&baseMessage.getDeletedAt()==0) { list.add(baseMessage); } + if (!baseMessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { + if (baseMessage.getReadAt() == 0) { + CometChat.markMessageAsRead(baseMessage); + } + } } getBaseView().setAdapter(list); } @@ -310,7 +332,7 @@ public void onSuccess(Call call) { @Override public void onError(CometChatException e) { - + Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } }); @@ -419,7 +441,7 @@ public void onError(CometChatException e) { @Override public void editMessage(BaseMessage baseMessage,String newMessage) { - TextMessage textMessage=new TextMessage(baseMessage.getReceiverUid(),newMessage, baseMessage.getType(),baseMessage.getReceiverType()); + TextMessage textMessage=new TextMessage(baseMessage.getReceiverUid(),newMessage,CometChatConstants.MESSAGE_TYPE_TEXT,baseMessage.getReceiverType()); textMessage.setId(baseMessage.getId()); CometChat.editMessage(textMessage, new CometChat.CallbackListener() { @Override @@ -448,7 +470,7 @@ public void searchMessage(String s,String UID) { public void onSuccess(List baseMessages) { if (isViewAttached()) { for (BaseMessage baseMessage : baseMessages) { - Log.d(TAG, "onSuccess: delete "+baseMessage.getDeletedAt()); + Log.d(TAG, "searchMessage onSuccess: delete "+baseMessage.getDeletedAt()); if (!baseMessage.getCategory().equals(CometChatConstants.CATEGORY_ACTION)&&baseMessage.getDeletedAt()==0) { list.add(baseMessage); } @@ -459,12 +481,18 @@ public void onSuccess(List baseMessages) { @Override public void onError(CometChatException e) { - Log.d(TAG, " onError: "+e.getMessage()); + Log.d(TAG, "searchMessage onError: "+e.getMessage()); } }); } + @Override + public void refreshList(String contactUid, int limit) { + messagesRequest=null; + fetchPreviousMessage(contactUid,limit); + } + @Override public void removeMessageLisenter(String listenerId) { CometChat.removeMessageListener(listenerId); diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/UserProfileViewPresenter.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/UserProfileViewPresenter.java index a647624a..595d05a3 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/UserProfileViewPresenter.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Presenters/UserProfileViewPresenter.java @@ -122,8 +122,9 @@ public void onSuccess(List baseMessages) { } } } - - getBaseView().setAdapter(messageList); + if (isViewAttached()) { + getBaseView().setAdapter(messageList); + } } @Override diff --git a/app/src/main/java/com/inscripts/cometchatpulse/demo/Utils/MediaUtils.java b/app/src/main/java/com/inscripts/cometchatpulse/demo/Utils/MediaUtils.java index eb726552..f802e7f2 100755 --- a/app/src/main/java/com/inscripts/cometchatpulse/demo/Utils/MediaUtils.java +++ b/app/src/main/java/com/inscripts/cometchatpulse/demo/Utils/MediaUtils.java @@ -1,9 +1,13 @@ package com.inscripts.cometchatpulse.demo.Utils; +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.drawable.Drawable; import android.hardware.Camera; import android.media.AudioManager; @@ -13,13 +17,11 @@ import android.os.Build; import android.os.Vibrator; import android.provider.MediaStore; - import com.inscripts.cometchatpulse.demo.ViewHolders.LeftImageVideoViewHolder; import com.inscripts.cometchatpulse.demo.ViewHolders.RightImageVideoViewHolder; - -import java.io.ByteArrayOutputStream; import java.util.HashMap; + public class MediaUtils { @@ -49,13 +51,6 @@ public static Bitmap getPlaceholderImage(Context context,Drawable drawable) return bitmap; } - public static Uri getImageUri(Context inContext, Bitmap inImage) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); - String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); - return Uri.parse(path); - } - public static String ImagePath(Uri uri, Context context) { String path = ""; if (context.getContentResolver() != null) { diff --git a/app/src/main/res/layout/group_detail.xml b/app/src/main/res/layout/group_detail.xml index b5ea6038..4200c62a 100755 --- a/app/src/main/res/layout/group_detail.xml +++ b/app/src/main/res/layout/group_detail.xml @@ -152,7 +152,6 @@ android:layout_marginTop="16dp" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" - android:background="@drawable/tab" app:tabBackground="@drawable/tab_background" app:tabIndicator="@null" diff --git a/app/src/test/java/com/inscripts/cometchatpulse/demo/ExampleUnitTest.java b/app/src/test/java/com/inscripts/cometchatpulse/demo/ExampleUnitTest.java index fe4a4427..c049a903 100755 --- a/app/src/test/java/com/inscripts/cometchatpulse/demo/ExampleUnitTest.java +++ b/app/src/test/java/com/inscripts/cometchatpulse/demo/ExampleUnitTest.java @@ -1,17 +1,29 @@ package com.inscripts.cometchatpulse.demo; -import org.junit.Test; +import android.content.Context; -import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; /** * Example local unit test, which will execute on the development machine (host). * * @see Testing documentation */ + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } + + private static final String TAG = "ExampleUnitTest"; + Context context; + + @Before + public void getContext(){ +// context = ShadowApplication.getInstance().getApplicationContext(); + } + + + + } \ No newline at end of file diff --git a/app/src/test/java/com/inscripts/cometchatpulse/demo/LoginTest.java b/app/src/test/java/com/inscripts/cometchatpulse/demo/LoginTest.java deleted file mode 100755 index 2ac32ad3..00000000 --- a/app/src/test/java/com/inscripts/cometchatpulse/demo/LoginTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.inscripts.cometchatpulse.demo; - -import android.app.Instrumentation; -import android.content.Context; - -import com.cometchat.pro.core.CometChat; -import com.cometchat.pro.exceptions.CometChatException; -import com.cometchat.pro.models.User; -import com.inscripts.cometchatpulse.demo.Contracts.StringContract; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; - - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(AndroidJUnit4.class) -public class LoginTest { - - @Test - public void login(){ - - Context appContext = InstrumentationRegistry.getTargetContext(); - CometChat.init(appContext, "337beda0759d2", new CometChat.CallbackListener() { - @Override - public void onSuccess(String s) { - System.out.println(s); - - } - - @Override - public void onError(CometChatException e) { - System.out.println(e.getMessage()); - } - }); - - } - - @Test - public void login1(){ - - CometChat.login("superhero2", "083e6894e7cd4b75348a607f254166b1f41462ef", new CometChat.CallbackListener() { - @Override - public void onSuccess(User user) { - System.out.println(user.toString()); - } - - @Override - public void onError(CometChatException e) { - System.out.println(e.getMessage()); - } - }); - } - - - - -} diff --git a/build.gradle b/build.gradle index dd363a2f..0accdf0e 100755 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:3.4.2' classpath 'com.google.gms:google-services:4.0.1' // NOTE: Do not place your application dependencies here; they belong diff --git a/settings.gradle b/settings.gradle index 36ccdb12..9d495b34 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':pro-android-chat-sdk' +include ':app' \ No newline at end of file