Skip to content

Commit

Permalink
Move NotificationConfig into ChatClientConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Oct 3, 2023
1 parent 5438374 commit 375dfd5
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 27 deletions.
7 changes: 4 additions & 3 deletions stream-chat-android-client/api/stream-chat-android-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,16 @@ public final class io/getstream/chat/android/client/ClientExtensionsKt {
}

public final class io/getstream/chat/android/client/api/ChatClientConfig {
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;Z)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;ZZ)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;ZLio/getstream/chat/android/client/notifications/handler/NotificationConfig;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;ZZLio/getstream/chat/android/client/notifications/handler/NotificationConfig;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLio/getstream/chat/android/client/logger/ChatLoggerConfig;ZZLio/getstream/chat/android/client/notifications/handler/NotificationConfig;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getApiKey ()Ljava/lang/String;
public final fun getCdnHttpUrl ()Ljava/lang/String;
public final fun getDebugRequests ()Z
public final fun getDistinctApiCalls ()Z
public final fun getHttpUrl ()Ljava/lang/String;
public final fun getLoggerConfig ()Lio/getstream/chat/android/client/logger/ChatLoggerConfig;
public final fun getNotificationConfig ()Lio/getstream/chat/android/client/notifications/handler/NotificationConfig;
public final fun getWarmUp ()Z
public final fun getWssUrl ()Ljava/lang/String;
public final fun isAnonymous ()Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.getstream.chat.android.client.di
import android.content.Context
import androidx.lifecycle.Lifecycle
import io.getstream.chat.android.client.api.ChatClientConfig
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.notifications.handler.NotificationHandler
import io.getstream.chat.android.client.parser.ChatParser
import io.getstream.chat.android.client.scope.ClientScope
Expand All @@ -40,7 +39,6 @@ internal class ChatModule(
userScope: UserScope,
config: ChatClientConfig,
notificationsHandler: NotificationHandler,
notificationConfig: NotificationConfig,
uploader: FileUploader?,
tokenManager: TokenManager,
customOkHttpClient: OkHttpClient?,
Expand All @@ -51,7 +49,6 @@ internal class ChatModule(
userScope,
config,
notificationsHandler,
notificationConfig,
uploader,
tokenManager,
customOkHttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ public class ChatClient
@Suppress("LongParameterList")
internal constructor(
public val config: ChatClientConfig,
internal val notificationConfig: NotificationConfig,
private val api: ChatApi,
private val socket: ChatSocket,
@property:InternalStreamChatApi public val notifications: ChatNotifications,
Expand Down Expand Up @@ -3148,7 +3147,8 @@ internal constructor(
warmUp = warmUp,
loggerConfig = ChatLoggerConfigImpl(logLevel, loggerHandler),
distinctApiCalls = distinctApiCalls,
debugRequests
debugRequests,
notificationConfig,
)
setupStreamLog()

Expand All @@ -3164,7 +3164,6 @@ internal constructor(
userScope,
config,
notificationsHandler ?: NotificationHandlerFactory.createNotificationHandler(appContext),
notificationConfig,
fileUploader,
tokenManager,
customOkHttpClient,
Expand All @@ -3175,7 +3174,6 @@ internal constructor(

return ChatClient(
config,
notificationConfig,
module.api(),
module.socket(),
module.notifications(),
Expand Down Expand Up @@ -3294,7 +3292,7 @@ internal constructor(
@JvmStatic
public fun handlePushMessage(pushMessage: PushMessage) {
ensureClientInitialized().run {
if (!notificationConfig.ignorePushMessagesWhenUserOnline || !isSocketConnected()) {
if (!config.notificationConfig.ignorePushMessagesWhenUserOnline || !isSocketConnected()) {
clientScope.launch {
setUserWithoutConnectingIfNeeded()
notifications.onPushMessage(pushMessage, pushNotificationReceivedListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.chat.android.client.api
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.api.internal.DistinctChatApi
import io.getstream.chat.android.client.logger.ChatLoggerConfig
import io.getstream.chat.android.client.notifications.handler.NotificationConfig

/**
* A config to setup the [ChatClient] behavior.
Expand All @@ -32,6 +33,7 @@ import io.getstream.chat.android.client.logger.ChatLoggerConfig
* @param loggerConfig A logging config to be used by the client.
* @param distinctApiCalls Controls whether [DistinctChatApi] is enabled or not.
* @param debugRequests Controls whether requests can be recorded or not.
* @param notificationConfig A notification config to be used by the client.
*/
@Suppress("LongParameterList")
public class ChatClientConfig @JvmOverloads constructor(
Expand All @@ -42,7 +44,8 @@ public class ChatClientConfig @JvmOverloads constructor(
public val warmUp: Boolean,
public val loggerConfig: ChatLoggerConfig,
public var distinctApiCalls: Boolean = true,
public val debugRequests: Boolean
public val debugRequests: Boolean,
public val notificationConfig: NotificationConfig
) {
public var isAnonymous: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ internal open class BaseChatModule(
private val userScope: UserScope,
private val config: ChatClientConfig,
private val notificationsHandler: NotificationHandler,
private val notificationConfig: NotificationConfig,
private val fileUploader: FileUploader? = null,
private val tokenManager: TokenManager = TokenManagerImpl(),
private val customOkHttpClient: OkHttpClient? = null,
Expand All @@ -93,7 +92,7 @@ internal open class BaseChatModule(

private val moshiParser: ChatParser by lazy { MoshiChatParser() }
private val socketFactory: SocketFactory by lazy { SocketFactory(moshiParser, tokenManager) }
private val defaultNotifications by lazy { buildNotification(notificationsHandler, notificationConfig) }
private val defaultNotifications by lazy { buildNotification(notificationsHandler, config.notificationConfig) }
private val defaultApi by lazy { buildApi(config) }
private val defaultSocket by lazy {
buildSocket(config, moshiParser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.getstream.chat.android.client.di
import android.content.Context
import androidx.lifecycle.Lifecycle
import io.getstream.chat.android.client.api.ChatClientConfig
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.notifications.handler.NotificationHandler
import io.getstream.chat.android.client.scope.ClientScope
import io.getstream.chat.android.client.scope.UserScope
Expand All @@ -36,7 +35,6 @@ internal class ChatModule(
userScope: UserScope,
config: ChatClientConfig,
notificationsHandler: NotificationHandler,
notificationConfig: NotificationConfig,
uploader: FileUploader?,
tokenManager: TokenManager,
customOkHttpClient: OkHttpClient?,
Expand All @@ -47,7 +45,6 @@ internal class ChatModule(
userScope,
config,
notificationsHandler,
notificationConfig,
uploader,
tokenManager,
customOkHttpClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.getstream.chat.android.client.events.UnknownEvent
import io.getstream.chat.android.client.models.EventType
import io.getstream.chat.android.client.models.Message
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.parser2.adapters.internal.StreamDateFormatter
import io.getstream.chat.android.client.persistance.repository.noop.NoOpRepositoryFactory
import io.getstream.chat.android.client.plugin.factory.PluginFactory
Expand Down Expand Up @@ -110,7 +111,8 @@ internal class ChatClientTest {
false,
Mother.chatLoggerConfig(),
false,
false
false,
NotificationConfig(),
)
whenever(tokenUtils.getUserId(token)) doReturn userId
api = mock()
Expand Down Expand Up @@ -140,7 +142,6 @@ internal class ChatClientTest {
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = Mother.mockedClientState(),
currentUserFetcher = mock(),
notificationConfig = mock(),
).apply {
connectUser(user, token).enqueue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ internal class ConnectUserTest {
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = clientState,
currentUserFetcher = mock(),
notificationConfig = mock(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.getstream.chat.android.client.events.ConnectedEvent
import io.getstream.chat.android.client.models.EventType
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.notifications.ChatNotifications
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.parser2.adapters.internal.StreamDateFormatter
import io.getstream.chat.android.client.persistance.repository.noop.NoOpRepositoryFactory
import io.getstream.chat.android.client.scope.ClientTestScope
Expand Down Expand Up @@ -86,7 +87,8 @@ internal class MockClientBuilder(
false,
Mother.chatLoggerConfig(),
false,
false
false,
NotificationConfig(),
)

val lifecycleOwner = TestLifecycleOwner(coroutineDispatcher = testCoroutineExtension.dispatcher)
Expand Down Expand Up @@ -123,7 +125,6 @@ internal class MockClientBuilder(
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = mock(),
currentUserFetcher = mock(),
notificationConfig = mock(),
)

client.connectUser(user, token).enqueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.getstream.chat.android.client.models.ConnectionData
import io.getstream.chat.android.client.models.EventType
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.notifications.ChatNotifications
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.parser2.adapters.internal.StreamDateFormatter
import io.getstream.chat.android.client.persistance.repository.noop.NoOpRepositoryFactory
import io.getstream.chat.android.client.scope.ClientTestScope
Expand Down Expand Up @@ -88,7 +89,8 @@ internal class ClientConnectionTests {
false,
Mother.chatLoggerConfig(),
false,
false
false,
NotificationConfig(),
)

private val connectedEvent = ConnectedEvent(
Expand Down Expand Up @@ -151,7 +153,6 @@ internal class ClientConnectionTests {
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = clientState,
currentUserFetcher = mock(),
notificationConfig = mock(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ internal open class BaseChatClientTest {
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = clientState,
currentUserFetcher = currentUserFetcher,
notificationConfig = mock(),
)

Mockito.reset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.getstream.chat.android.client.clientstate.UserStateService
import io.getstream.chat.android.client.events.ChatEvent
import io.getstream.chat.android.client.interceptor.SendMessageInterceptor
import io.getstream.chat.android.client.models.Message
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.persistance.repository.noop.NoOpRepositoryFactory
import io.getstream.chat.android.client.plugin.factory.PluginFactory
import io.getstream.chat.android.client.scope.ClientTestScope
Expand Down Expand Up @@ -86,7 +87,8 @@ internal class ChatClientDebuggerTest {
false,
Mother.chatLoggerConfig(),
false,
false
false,
NotificationConfig(),
)
whenever(tokenUtils.getUserId(token)) doReturn userId
api = mock()
Expand Down Expand Up @@ -138,7 +140,6 @@ internal class ChatClientDebuggerTest {
repositoryFactoryProvider = NoOpRepositoryFactory.Provider,
clientState = Mother.mockedClientState(),
currentUserFetcher = mock(),
notificationConfig = mock(),
).apply {
addInterceptor(sendMessageInterceptor)
connectUser(user, token).enqueue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import io.getstream.chat.android.client.errors.ChatErrorCode
import io.getstream.chat.android.client.errors.ChatNetworkError
import io.getstream.chat.android.client.events.ChatEvent
import io.getstream.chat.android.client.network.NetworkStateProvider
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.parser.ChatParser
import io.getstream.chat.android.client.scope.UserScope
import io.getstream.chat.android.client.scope.UserTestScope
Expand Down Expand Up @@ -90,6 +91,7 @@ internal class CurrentUserFetcherTests {
warmUp = randomBoolean(),
loggerConfig = mock(),
debugRequests = randomBoolean(),
notificationConfig = NotificationConfig(),
).apply { isAnonymous = randomBoolean() }
)
}
Expand Down

0 comments on commit 375dfd5

Please sign in to comment.