@@ -238,41 +238,54 @@ class ConversationInfoActivity :
238
238
initObservers()
239
239
}
240
240
241
- @Suppress(" Detekt.LongMethod" )
242
241
private fun initObservers () {
243
242
initViewStateObserver()
243
+ initCapabilitiesObersver()
244
+ initRoomOberserver()
245
+ initBanActorObserver()
246
+ initConversationReadOnlyObserver()
247
+ initClearChatHistoryObserver()
248
+ }
244
249
245
- viewModel.getCapabilitiesViewState.observe(this ) { state ->
246
- when (state) {
247
- is ConversationInfoViewModel .GetCapabilitiesSuccessState -> {
248
- spreedCapabilities = state.spreedCapabilities
250
+ private fun initClearChatHistoryObserver () {
251
+ viewModel.clearChatHistoryViewState.observe(this ) { uiState ->
252
+ when (uiState) {
253
+ is ConversationInfoViewModel .ClearChatHistoryViewState .None -> {
254
+ }
249
255
250
- handleConversation()
256
+ is ConversationInfoViewModel .ClearChatHistoryViewState .Success -> {
257
+ Snackbar .make(
258
+ binding.root,
259
+ context.getString(R .string.nc_clear_history_success),
260
+ Snackbar .LENGTH_LONG
261
+ ).show()
251
262
}
252
263
253
- else -> {}
264
+ is ConversationInfoViewModel .ClearChatHistoryViewState .Error -> {
265
+ Snackbar .make(binding.root, R .string.nc_common_error_sorry, Snackbar .LENGTH_LONG ).show()
266
+ Log .e(TAG , " failed to clear chat history" , uiState.exception)
267
+ }
254
268
}
255
269
}
270
+ }
256
271
257
- viewModel.createRoomViewState.observe(this ) { state ->
272
+ private fun initConversationReadOnlyObserver () {
273
+ viewModel.getConversationReadOnlyState.observe(this ) { state ->
258
274
when (state) {
259
- is ConversationInfoViewModel .CreateRoomUIState .Success -> {
260
- state.room.ocs?.data?.token?.let { token ->
261
- val chatIntent = Intent (context, ChatActivity ::class .java).apply {
262
- putExtra(KEY_ROOM_TOKEN , token)
263
- }
264
- startActivity(chatIntent)
265
- }
275
+ is ConversationInfoViewModel .SetConversationReadOnlyViewState .Success -> {
266
276
}
267
277
268
- is ConversationInfoViewModel .CreateRoomUIState .Error -> {
269
- Snackbar .make(binding.root, R .string.nc_common_error_sorry , Snackbar .LENGTH_LONG ).show()
278
+ is ConversationInfoViewModel .SetConversationReadOnlyViewState .Error -> {
279
+ Snackbar .make(binding.root, R .string.conversation_read_only_failed , Snackbar .LENGTH_LONG ).show()
270
280
}
271
281
272
- else -> {}
282
+ is ConversationInfoViewModel .SetConversationReadOnlyViewState .None -> {
283
+ }
273
284
}
274
285
}
286
+ }
275
287
288
+ private fun initBanActorObserver () {
276
289
viewModel.getBanActorState.observe(this ) { state ->
277
290
when (state) {
278
291
is ConversationInfoViewModel .BanActorSuccessState -> {
@@ -286,38 +299,39 @@ class ConversationInfoActivity :
286
299
else -> {}
287
300
}
288
301
}
302
+ }
289
303
290
- viewModel.getConversationReadOnlyState.observe(this ) { state ->
304
+ private fun initRoomOberserver () {
305
+ viewModel.createRoomViewState.observe(this ) { state ->
291
306
when (state) {
292
- is ConversationInfoViewModel .SetConversationReadOnlyViewState .Success -> {
307
+ is ConversationInfoViewModel .CreateRoomUIState .Success -> {
308
+ state.room.ocs?.data?.token?.let { token ->
309
+ val chatIntent = Intent (context, ChatActivity ::class .java).apply {
310
+ putExtra(KEY_ROOM_TOKEN , token)
311
+ }
312
+ startActivity(chatIntent)
313
+ }
293
314
}
294
315
295
- is ConversationInfoViewModel .SetConversationReadOnlyViewState .Error -> {
296
- Snackbar .make(binding.root, R .string.conversation_read_only_failed , Snackbar .LENGTH_LONG ).show()
316
+ is ConversationInfoViewModel .CreateRoomUIState .Error -> {
317
+ Snackbar .make(binding.root, R .string.nc_common_error_sorry , Snackbar .LENGTH_LONG ).show()
297
318
}
298
319
299
- is ConversationInfoViewModel .SetConversationReadOnlyViewState .None -> {
300
- }
320
+ else -> {}
301
321
}
302
322
}
323
+ }
303
324
304
- viewModel.clearChatHistoryViewState.observe(this ) { uiState ->
305
- when (uiState) {
306
- is ConversationInfoViewModel .ClearChatHistoryViewState .None -> {
307
- }
325
+ private fun initCapabilitiesObersver () {
326
+ viewModel.getCapabilitiesViewState.observe(this ) { state ->
327
+ when (state) {
328
+ is ConversationInfoViewModel .GetCapabilitiesSuccessState -> {
329
+ spreedCapabilities = state.spreedCapabilities
308
330
309
- is ConversationInfoViewModel .ClearChatHistoryViewState .Success -> {
310
- Snackbar .make(
311
- binding.root,
312
- context.getString(R .string.nc_clear_history_success),
313
- Snackbar .LENGTH_LONG
314
- ).show()
331
+ handleConversation()
315
332
}
316
333
317
- is ConversationInfoViewModel .ClearChatHistoryViewState .Error -> {
318
- Snackbar .make(binding.root, R .string.nc_common_error_sorry, Snackbar .LENGTH_LONG ).show()
319
- Log .e(TAG , " failed to clear chat history" , uiState.exception)
320
- }
334
+ else -> {}
321
335
}
322
336
}
323
337
}
0 commit comments