Skip to content

Commit

Permalink
[AND-159] Ensure ChatClient is initialized before internal SDK activi…
Browse files Browse the repository at this point in the history
…ties are started (#5510)

* Ensure ChatClient is initialized before internal SDK activities are started

* Add check to AttachmentDocumentActivity
  • Loading branch information
JcMinarro authored Dec 11, 2024
1 parent 4bbea69 commit 47f7df2
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public final class io/getstream/chat/android/client/ChatClient {
public static final fun instance ()Lio/getstream/chat/android/client/ChatClient;
public final fun inviteMembers (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lio/getstream/chat/android/models/Message;Ljava/lang/Boolean;)Lio/getstream/result/call/Call;
public static synthetic fun inviteMembers$default (Lio/getstream/chat/android/client/ChatClient;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Lio/getstream/chat/android/models/Message;Ljava/lang/Boolean;ILjava/lang/Object;)Lio/getstream/result/call/Call;
public static final fun isInitialized ()Z
public final fun isSocketConnected ()Z
public final fun keystroke (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/getstream/result/call/Call;
public static synthetic fun keystroke$default (Lio/getstream/chat/android/client/ChatClient;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lio/getstream/result/call/Call;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3821,6 +3821,7 @@ internal constructor(
)
}

@JvmStatic
public val isInitialized: Boolean
get() = instance != null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ public class MediaGalleryPreviewActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}

uiState = savedInstanceState?.getParcelable(
KeyMediaGalleryPreviewActivityState,
) ?: intent?.getParcelableExtra(KeyMediaGalleryPreviewActivityState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.view.isVisible
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.compose.ui.util.mirrorRtl
Expand All @@ -71,7 +72,7 @@ public class MediaPreviewActivity : AppCompatActivity() {
val url = intent.getStringExtra(KEY_URL)
val title = intent.getStringExtra(KEY_TITLE) ?: ""

if (url.isNullOrEmpty()) {
if (url.isNullOrEmpty() || ChatClient.isInitialized.not()) {
finish()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public class AttachmentDocumentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!ChatClient.isInitialized()) {
finish();
return;
}

setContentView(R.layout.stream_activity_attachment_document);
rootView = findViewById(R.id.rootView);
webView = findViewById(R.id.webView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.ui.R
import io.getstream.chat.android.ui.databinding.StreamUiFragmentContainerBinding

Expand All @@ -35,6 +36,11 @@ public open class ChannelListActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}
binding = StreamUiFragmentContainerBinding.inflate(layoutInflater)
setContentView(binding.root)
setupEdgeToEdge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.models.AttachmentType
import io.getstream.chat.android.ui.R
import io.getstream.chat.android.ui.databinding.StreamUiActivityAttachmentBinding
Expand All @@ -46,6 +47,11 @@ public class AttachmentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}

binding = StreamUiActivityAttachmentBinding.inflate(streamThemeInflater)
setContentView(binding.root)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.ViewPager2
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.core.internal.coroutines.DispatcherProvider
import io.getstream.chat.android.models.Attachment
import io.getstream.chat.android.models.AttachmentType
Expand Down Expand Up @@ -117,6 +118,11 @@ public class AttachmentGalleryActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}

binding = StreamUiActivityAttachmentGalleryBinding.inflate(streamThemeInflater)
setContentView(binding.root)
setupEdgeToEdge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.ui.R
import io.getstream.chat.android.ui.databinding.StreamUiActivityAttachmentMediaBinding
import io.getstream.chat.android.ui.utils.extensions.getColorCompat
Expand All @@ -52,6 +53,12 @@ public class AttachmentMediaActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}

binding = StreamUiActivityAttachmentMediaBinding.inflate(streamThemeInflater)
setContentView(binding.root)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.ui.R
import io.getstream.chat.android.ui.databinding.StreamUiFragmentContainerBinding

Expand All @@ -35,6 +36,11 @@ public open class MessageListActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (ChatClient.isInitialized.not()) {
finish()
return
}
binding = StreamUiFragmentContainerBinding.inflate(layoutInflater)
setContentView(binding.root)
setupEdgeToEdge()
Expand Down

0 comments on commit 47f7df2

Please sign in to comment.