Fix joining public chat crashing.

This commit is contained in:
Mikunj Varsani 2020-03-13 10:22:59 +11:00
parent e484a95fcb
commit a30d90ed29

View File

@ -18,9 +18,9 @@ import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi import nl.komponents.kovenant.ui.successUi
import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.loki.redesign.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragment import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragment
import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragmentDelegate import org.thoughtcrime.securesms.loki.redesign.fragments.ScanQRCodeWrapperFragmentDelegate
import org.thoughtcrime.securesms.loki.redesign.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.sms.MessageSender import org.thoughtcrime.securesms.sms.MessageSender
class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperFragmentDelegate { class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperFragmentDelegate {
@ -62,19 +62,22 @@ class JoinPublicChatActivity : PassphraseRequiredActionBarActivity(), ScanQRCode
} }
fun joinPublicChatIfPossible(url: String) { fun joinPublicChatIfPossible(url: String) {
if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) { runOnUiThread {
return Toast.makeText(this, "Invalid URL", Toast.LENGTH_SHORT).show() if (!Patterns.WEB_URL.matcher(url).matches() || !url.startsWith("https://")) {
} Toast.makeText(this, "Invalid URL", Toast.LENGTH_SHORT).show()
showLoader() return@runOnUiThread
}
showLoader()
val channel: Long = 1 val channel: Long = 1
OpenGroupUtilities.addGroup(this, url, channel).success { OpenGroupUtilities.addGroup(this, url, channel).success {
MessageSender.syncAllOpenGroups(this) MessageSender.syncAllOpenGroups(this)
}.successUi { }.successUi {
finish() finish()
}.failUi { }.failUi {
hideLoader() hideLoader()
Toast.makeText(this, "Couldn't join channel", Toast.LENGTH_SHORT).show() Toast.makeText(this, "Couldn't join channel", Toast.LENGTH_SHORT).show()
}
} }
} }
// endregion // endregion