Skip to content
Snippets Groups Projects
Commit 6d137dae authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Automatically switch to newly created networks

parent 7bdec405
Branches
Tags
No related merge requests found
Pipeline #
...@@ -28,6 +28,7 @@ import de.kuschku.libquassel.protocol.Message ...@@ -28,6 +28,7 @@ import de.kuschku.libquassel.protocol.Message
import de.kuschku.libquassel.protocol.Message_Type import de.kuschku.libquassel.protocol.Message_Type
import de.kuschku.libquassel.protocol.message.HandshakeMessage import de.kuschku.libquassel.protocol.message.HandshakeMessage
import de.kuschku.libquassel.session.Error import de.kuschku.libquassel.session.Error
import de.kuschku.libquassel.util.Optional
import de.kuschku.libquassel.util.flag.and import de.kuschku.libquassel.util.flag.and
import de.kuschku.libquassel.util.flag.hasFlag import de.kuschku.libquassel.util.flag.hasFlag
import de.kuschku.libquassel.util.flag.or import de.kuschku.libquassel.util.flag.or
...@@ -85,6 +86,8 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -85,6 +86,8 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
@Inject @Inject
lateinit var autoCompleteAdapter: AutoCompleteAdapter lateinit var autoCompleteAdapter: AutoCompleteAdapter
private val dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)
private lateinit var drawerToggle: ActionBarDrawerToggle private lateinit var drawerToggle: ActionBarDrawerToggle
private var chatlineFragment: ChatlineFragment? = null private var chatlineFragment: ChatlineFragment? = null
...@@ -159,8 +162,20 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -159,8 +162,20 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
} }
} }
val dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM) // If we connect to a new network without statusbuffer, the bufferid may be -networkId.
// In that case, once we’re connected (and a status buffer exists), we want to switch to it.
combineLatest(viewModel.allBuffers, viewModel.buffer).map { (buffers, current) ->
if (current > 0) Optional.empty()
else Optional.ofNullable(buffers.firstOrNull {
it.networkId == -current && it.type.hasFlag(Buffer_Type.StatusBuffer)
})
}.toLiveData().observe(this, Observer { info ->
info?.orNull()?.let {
viewModel.buffer.onNext(it.bufferId)
}
})
// User-actionable errors that require immediate action, and should show up as dialog
viewModel.errors.toLiveData().observe(this, Observer { error -> viewModel.errors.toLiveData().observe(this, Observer { error ->
error?.let { error?.let {
when (it) { when (it) {
...@@ -246,6 +261,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -246,6 +261,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
it.exception.let { it.exception.let {
val leafCertificate = it.certificateChain?.firstOrNull() val leafCertificate = it.certificateChain?.firstOrNull()
if (leafCertificate == null) { if (leafCertificate == null) {
// No certificate exists in the chain
MaterialDialog.Builder(this) MaterialDialog.Builder(this)
.title(R.string.label_error_certificate) .title(R.string.label_error_certificate)
.content(R.string.label_error_certificate_no_certificate) .content(R.string.label_error_certificate_no_certificate)
...@@ -257,6 +273,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -257,6 +273,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
.show() .show()
} else { } else {
when { when {
// Certificate has expired
it is QuasselSecurityException.Certificate && it is QuasselSecurityException.Certificate &&
(it.cause is CertificateNotYetValidException || (it.cause is CertificateNotYetValidException ||
it.cause is CertificateExpiredException) -> { it.cause is CertificateExpiredException) -> {
...@@ -299,6 +316,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -299,6 +316,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
.build() .build()
.show() .show()
} }
// Certificate is in any other way invalid
it is QuasselSecurityException.Certificate -> { it is QuasselSecurityException.Certificate -> {
MaterialDialog.Builder(this) MaterialDialog.Builder(this)
.title(R.string.label_error_certificate) .title(R.string.label_error_certificate)
...@@ -343,6 +361,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -343,6 +361,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
.build() .build()
.show() .show()
} }
// Certificate not valid for this hostname
it is QuasselSecurityException.Hostname -> { it is QuasselSecurityException.Hostname -> {
MaterialDialog.Builder(this) MaterialDialog.Builder(this)
.title(R.string.label_error_certificate) .title(R.string.label_error_certificate)
...@@ -388,16 +407,20 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -388,16 +407,20 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
} }
}) })
// After initial connect, open the drawer
var isInitialConnect = true
viewModel.connectionProgress viewModel.connectionProgress
.filter { (it, _, _) -> it == ConnectionState.CONNECTED } .filter { (it, _, _) -> it == ConnectionState.CONNECTED }
.firstElement() .firstElement()
.toLiveData() .toLiveData()
.observe(this, Observer { .observe(this, Observer {
if (resources.getBoolean(R.bool.buffer_drawer_exists) && viewModel.buffer.value == -1) { if (resources.getBoolean(R.bool.buffer_drawer_exists) && viewModel.buffer.value == -1 && isInitialConnect) {
drawerLayout.openDrawer(Gravity.START) drawerLayout.openDrawer(Gravity.START)
isInitialConnect = true
} }
}) })
// Show Connection Progress Bar
viewModel.connectionProgress.toLiveData().observe(this, Observer { viewModel.connectionProgress.toLiveData().observe(this, Observer {
val (state, progress, max) = it ?: Triple(ConnectionState.DISCONNECTED, 0, 0) val (state, progress, max) = it ?: Triple(ConnectionState.DISCONNECTED, 0, 0)
when (state) { when (state) {
...@@ -422,6 +445,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc ...@@ -422,6 +445,7 @@ class ChatActivity : ServiceBoundActivity(), SharedPreferences.OnSharedPreferenc
} }
}) })
// Only show nick list when we’re in a channel buffer
viewModel.bufferData.distinctUntilChanged().toLiveData().observe(this, Observer { viewModel.bufferData.distinctUntilChanged().toLiveData().observe(this, Observer {
bufferData = it bufferData = it
if (bufferData?.info?.type?.hasFlag(Buffer_Type.ChannelBuffer) == true) { if (bufferData?.info?.type?.hasFlag(Buffer_Type.ChannelBuffer) == true) {
......
...@@ -77,7 +77,7 @@ class NetworkServerFragment : SettingsFragment(), SettingsFragment.Savable, ...@@ -77,7 +77,7 @@ class NetworkServerFragment : SettingsFragment(), SettingsFragment.Savable,
)) ))
proxyType.adapter = typeAdapter proxyType.adapter = typeAdapter
item?.let { data -> (item ?: INetwork.Server()).let { data ->
host.setText(data.host) host.setText(data.host)
port.setText(data.port.toString()) port.setText(data.port.toString())
sslEnabled.isChecked = data.useSsl sslEnabled.isChecked = data.useSsl
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment