Skip to content

Commit df309c0

Browse files
authored
Prevent default notification channel creation if notifications are disabled (#6054)
* Prevent default notification channel created before it is required. * Prevent default notification channel created before it is required. * Update CHANGELOG.
1 parent 704fc94 commit df309c0

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
## stream-chat-android-client
1414
### 🐞 Fixed
15+
- Fix default notification channel created even if SDK notifications are disabled. [#6054](https://github.com/GetStream/stream-chat-android/pull/6054)
1516

1617
### ⬆️ Improved
1718

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,10 +5000,7 @@ internal constructor(
50005000
clientScope = clientScope,
50015001
userScope = userScope,
50025002
config = config,
5003-
notificationsHandler = notificationsHandler ?: NotificationHandlerFactory.createNotificationHandler(
5004-
context = appContext,
5005-
notificationConfig = notificationConfig,
5006-
),
5003+
notificationsHandler = notificationsHandler,
50075004
apiModelTransformers = apiModelTransformers,
50085005
fileTransformer = fileTransformer,
50095006
fileUploader = fileUploader,

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/di/ChatModule.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import io.getstream.chat.android.client.notifications.ChatNotificationsImpl
6767
import io.getstream.chat.android.client.notifications.NoOpChatNotifications
6868
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
6969
import io.getstream.chat.android.client.notifications.handler.NotificationHandler
70+
import io.getstream.chat.android.client.notifications.handler.NotificationHandlerFactory
7071
import io.getstream.chat.android.client.parser.ChatParser
7172
import io.getstream.chat.android.client.parser2.MoshiChatParser
7273
import io.getstream.chat.android.client.plugins.requests.ApiRequestsAnalyser
@@ -124,7 +125,7 @@ constructor(
124125
private val clientScope: ClientScope,
125126
private val userScope: UserScope,
126127
private val config: ChatClientConfig,
127-
private val notificationsHandler: NotificationHandler,
128+
private val notificationsHandler: NotificationHandler?,
128129
private val apiModelTransformers: ApiModelTransformers,
129130
private val fileTransformer: FileTransformer,
130131
private val fileUploader: FileUploader?,
@@ -164,7 +165,7 @@ constructor(
164165
}
165166
private val socketFactory: SocketFactory by lazy { SocketFactory(moshiParser, tokenManager, headersUtil) }
166167

167-
private val defaultNotifications by lazy { buildNotification(notificationsHandler, config.notificationConfig) }
168+
private val defaultNotifications by lazy { buildChatNotifications(notificationsHandler, config.notificationConfig) }
168169
private val defaultApi by lazy { buildApi(config) }
169170
internal val chatSocket: ChatSocket by lazy { buildChatSocket(config) }
170171
private val defaultFileUploader by lazy {
@@ -203,15 +204,26 @@ constructor(
203204

204205
//endregion
205206

206-
private fun buildNotification(
207-
handler: NotificationHandler,
207+
private fun buildChatNotifications(
208+
handler: NotificationHandler?,
208209
notificationConfig: NotificationConfig,
209210
): ChatNotifications = if (notificationConfig.pushNotificationsEnabled) {
210-
ChatNotificationsImpl(handler, notificationConfig, appContext, defaultApi)
211+
ChatNotificationsImpl(
212+
handler = handler ?: defaultNotificationHandler(notificationConfig),
213+
notificationConfig = notificationConfig,
214+
context = appContext,
215+
api = defaultApi,
216+
)
211217
} else {
212218
NoOpChatNotifications
213219
}
214220

221+
private fun defaultNotificationHandler(notificationConfig: NotificationConfig): NotificationHandler =
222+
NotificationHandlerFactory.createNotificationHandler(
223+
context = appContext,
224+
notificationConfig = notificationConfig,
225+
)
226+
215227
private fun buildRetrofit(
216228
endpoint: String,
217229
timeout: Long,

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/notifications/handler/MessagingStyleNotificationHandler.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,18 @@ internal class MessagingStyleNotificationHandler(
6969
}
7070
}
7171

72-
private val factory: MessagingStyleNotificationFactory = MessagingStyleNotificationFactory(
73-
context = context,
74-
notificationManager = notificationManager,
75-
notificationChannelId = getNotificationChannelId(),
76-
userIconBuilder = userIconBuilder,
77-
newMessageIntent = newMessageIntent,
78-
notificationTextFormatter = notificationTextFormatter,
79-
actionsProvider = actionsProvider,
80-
notificationBuilderTransformer = notificationBuilderTransformer,
81-
)
72+
private val factory: MessagingStyleNotificationFactory by lazy {
73+
MessagingStyleNotificationFactory(
74+
context = context,
75+
notificationManager = notificationManager,
76+
notificationChannelId = getNotificationChannelId(),
77+
userIconBuilder = userIconBuilder,
78+
newMessageIntent = newMessageIntent,
79+
notificationTextFormatter = notificationTextFormatter,
80+
actionsProvider = actionsProvider,
81+
notificationBuilderTransformer = notificationBuilderTransformer,
82+
)
83+
}
8284

8385
override fun onNotificationPermissionStatus(status: NotificationPermissionStatus) {
8486
when (status) {

0 commit comments

Comments
 (0)