Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Open conversation is opening with invalid Conversation ID #566

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ import kommunicate.io.sample.network.RetrofitClient
import kommunicate.io.sample.utils.getAuthToken
import kommunicate.io.sample.utils.getRandomKmUser
import kommunicate.io.sample.utils.getRandomString
import kommunicate.io.sample.utils.waitFor
import kommunicate.io.sample.utils.waitForLatch
import kommunicate.io.sample.utils.withItemCount
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.suspendCancellableCoroutine
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotSame
import org.junit.Assert.assertThrows
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Exception
import java.util.concurrent.CountDownLatch
import kotlin.Exception
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

Expand Down Expand Up @@ -163,22 +160,22 @@ class ConversationListTest {
val latch = CountDownLatch(1)
val conversationId = Integer.parseInt(getRandomString(8, allNumbers = true))

assertThrows("conversation is opened with invalid group id: $conversationId", IllegalStateException::class.java) {
mActivityRule.onActivity {
it.lifecycleScope.launch {
mActivityRule.onActivity {
it.lifecycleScope.launch {
try {
// Login user
loginUser(it, kmUser)

// Launch conversation with group id
val resultMessage = openConversationList(it, conversationId)
assertNotSame(resultMessage, conversationId)
}.invokeOnCompletion {
openConversationList(it, conversationId)
} catch (e: IllegalStateException) {
assertEquals("Invalid Conversation id, Unable to find conversation with given ID.", e.message)
} finally {
latch.countDown()
}
}
}
onView(isRoot())
.perform(waitForLatch(latch))

// Wait for the coroutine to complete
onView(isRoot()).perform(waitForLatch(latch))
}

private suspend fun createConversation(context: Context) =
Expand Down Expand Up @@ -221,7 +218,7 @@ class ConversationListTest {
}

override fun onFailure(error: Any) {
continuation.resumeWithException(IllegalStateException("unable to create conversation throw error: $error"))
continuation.resumeWithException(IllegalStateException("$error"))
}
})
}
Expand Down
40 changes: 26 additions & 14 deletions kommunicate/src/main/java/io/kommunicate/KmConversationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,34 @@ public void onFailure(Exception e, Context context) {
}

private static void openParticularConversation(Context context, boolean skipConversationList, Integer conversationId, String preFilledMessage, KmCallback callback) {
try {
Intent intent = new Intent(context, KmUtils.getClassFromName(KmConstants.CONVERSATION_ACTIVITY_NAME));
intent.putExtra(KmConstants.GROUP_ID, conversationId);
intent.putExtra(KmConstants.TAKE_ORDER, skipConversationList);
if (!TextUtils.isEmpty(preFilledMessage)) {
intent.putExtra(KmConstants.KM_PREFILLED_MESSAGE, preFilledMessage);
}
context.startActivity(intent);
if (callback != null) {
callback.onSuccess(conversationId);
KmGetConversationInfoCallback callbackListener = new KmGetConversationInfoCallback() {
@Override
public void onSuccess(Channel channel, Context context) {
try {
Intent intent = new Intent(context, KmUtils.getClassFromName(KmConstants.CONVERSATION_ACTIVITY_NAME));
intent.putExtra(KmConstants.GROUP_ID, conversationId);
intent.putExtra(KmConstants.TAKE_ORDER, skipConversationList);
if (!TextUtils.isEmpty(preFilledMessage)) {
intent.putExtra(KmConstants.KM_PREFILLED_MESSAGE, preFilledMessage);
}
context.startActivity(intent);
if (callback != null) {
callback.onSuccess(conversationId);
}
} catch (ClassNotFoundException e) {
if (callback != null) {
callback.onFailure(e.getMessage());
}
}
}
} catch (ClassNotFoundException e) {
if (callback != null) {
callback.onFailure(e.getMessage());

@Override
public void onFailure(Exception e, Context context) {
callback.onFailure("Invalid Conversation id, Unable to find conversation with given ID.");
}
}
};

new KmConversationInfoTask(context, conversationId, callbackListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

@Deprecated
Expand Down