Because long polling may have to be informed that the scopep was cancelled, the isActive checks are added so it can't happen that messages are added when they shouldn't.
I could not reproduce the scenario, anyway the checks should make sense in my opinion.
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This is necessary especially to cancel the long polling when configuration change was made, e.g. screen was rotated. Otherwise multiple long polling requests would be running after configuration changes.
Because it not possible to launch a new coroutine in a scope that was canceled, it is necessary to re-initialize the scope.
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
By using
networkMonitor.isOnline.first()
the function
unregisterNetworkCallback
was triggered, which sometimes causes the ConnectivityManager$TooManyRequestsException.
So each time isOnline.first() was called, the callbackFlow would:
- Register a new NetworkCallback.
- Emit a value and cancel the flow.
- Unregister the NetworkCallback.
The exception was:
Exception android.net.ConnectivityManager$TooManyRequestsException:
at android.net.ConnectivityManager.convertServiceException (ConnectivityManager.java:3771)
at android.net.ConnectivityManager.sendRequestForNetwork (ConnectivityManager.java:3960)
at android.net.ConnectivityManager.sendRequestForNetwork (ConnectivityManager.java:3967)
at android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:4349)
at android.net.ConnectivityManager.registerNetworkCallback (ConnectivityManager.java:4319)
at com.nextcloud.talk.data.network.NetworkMonitorImpl$isOnline$1.invokeSuspend (NetworkMonitorImpl.kt:61)
To fix this, the cold flow from callbackFlow is converted to a StateFlow.
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
It seems there could have been a race condition because currentUser was initialized too late.
I was not able to reproduce but hopefully this fixes it:
- initialize currentUser earlier (moved from onResume to onCreate)
- use currentUserProvider instead userManager
NPEs were reported via gplay:
1)
Exception java.lang.NullPointerException:
at com.nextcloud.talk.conversationlist.ConversationsListActivity.addToConversationItems (ConversationsListActivity.kt:851)
at com.nextcloud.talk.conversationlist.ConversationsListActivity.access$addToConversationItems (ConversationsListActivity.kt:151)
at com.nextcloud.talk.conversationlist.ConversationsListActivity$initObservers$5$1.invokeSuspend (ConversationsListActivity.kt:394)
at com.nextcloud.talk.conversationlist.ConversationsListActivity$initObservers$5$1.invoke (Unknown Source:8)
at com.nextcloud.talk.conversationlist.ConversationsListActivity$initObservers$5$1.invoke (Unknown Source:4)
2)
Exception java.lang.RuntimeException:
at android.app.ActivityThread.performResumeActivity (ActivityThread.java:5427)
at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:5508)
...
Caused by java.lang.NullPointerException:
at com.nextcloud.talk.conversationlist.ConversationsListActivity.shouldShowNotificationWarning (ConversationsListActivity.kt:1557)
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
by moving networkMonitor.isOnline to separate check and by setting
binding.checkMark.visibility = View.INVISIBLE
binding.sendingProgress.visibility = View.GONE
before setting the status icons
to to handle recyclerview behavior
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
If user sent a message as a first message in today's chat, the temp message will be deleted when messages are retrieved from server, but also the date has to be deleted as it will be added again when the chat messages are added from server. Otherwise date "Today" would be shown twice.
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>