Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
1a1213da
Unverified
Commit
1a1213da
authored
May 08, 2018
by
Rafael Kellermann Streit
Committed by
GitHub
May 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1258 from RocketChat/feature/detect-redirect-on-server-info
[NEW] Detect redirect on server info
parents
20d8fdb9
db371a22
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
35 deletions
+77
-35
build.gradle
app/build.gradle
+2
-2
VersionCheckView.kt
...id/authentication/server/presentation/VersionCheckView.kt
+7
-0
ServerFragment.kt
...rocket/android/authentication/server/ui/ServerFragment.kt
+31
-14
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+18
-3
CheckServerPresenter.kt
...ocket/android/server/presentation/CheckServerPresenter.kt
+19
-16
No files found.
app/build.gradle
View file @
1a1213da
...
@@ -13,8 +13,8 @@ android {
...
@@ -13,8 +13,8 @@ android {
applicationId
"chat.rocket.android"
applicationId
"chat.rocket.android"
minSdkVersion
21
minSdkVersion
21
targetSdkVersion
versions
.
targetSdk
targetSdkVersion
versions
.
targetSdk
versionCode
20
19
versionCode
20
20
versionName
"2.1.
0
"
versionName
"2.1.
1
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled
true
multiDexEnabled
true
}
}
...
...
app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt
View file @
1a1213da
package
chat.rocket.android.authentication.server.presentation
package
chat.rocket.android.authentication.server.presentation
import
okhttp3.HttpUrl
interface
VersionCheckView
{
interface
VersionCheckView
{
/**
/**
* Alerts the user about the server version not meeting the recommended server version.
* Alerts the user about the server version not meeting the recommended server version.
...
@@ -26,4 +28,9 @@ interface VersionCheckView {
...
@@ -26,4 +28,9 @@ interface VersionCheckView {
* Alters the user this protocol is invalid. This is optional.
* Alters the user this protocol is invalid. This is optional.
*/
*/
fun
errorInvalidProtocol
()
{}
fun
errorInvalidProtocol
()
{}
/**
* Updates the server URL after a URL redirection
*/
fun
updateServerUrl
(
url
:
HttpUrl
)
{}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/authentication/server/ui/ServerFragment.kt
View file @
1a1213da
...
@@ -20,6 +20,7 @@ import chat.rocket.android.util.extensions.*
...
@@ -20,6 +20,7 @@ import chat.rocket.android.util.extensions.*
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_server.*
import
kotlinx.android.synthetic.main.fragment_authentication_server.*
import
okhttp3.HttpUrl
import
javax.inject.Inject
import
javax.inject.Inject
class
ServerFragment
:
Fragment
(),
ServerView
{
class
ServerFragment
:
Fragment
(),
ServerView
{
...
@@ -41,6 +42,7 @@ class ServerFragment : Fragment(), ServerView {
...
@@ -41,6 +42,7 @@ class ServerFragment : Fragment(), ServerView {
}
}
private
var
protocol
=
"https://"
private
var
protocol
=
"https://"
private
var
ignoreChange
=
false
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -72,22 +74,27 @@ class ServerFragment : Fragment(), ServerView {
...
@@ -72,22 +74,27 @@ class ServerFragment : Fragment(), ServerView {
protocol
=
"https://"
protocol
=
"https://"
}
}
1
->
{
1
->
{
ui
{
if
(
ignoreChange
)
{
AlertDialog
.
Builder
(
it
)
protocol
=
"http://"
.
setTitle
(
R
.
string
.
msg_warning
)
}
else
{
.
setMessage
(
R
.
string
.
msg_http_insecure
)
ui
{
.
setPositiveButton
(
R
.
string
.
msg_proceed
)
{
_
,
_
->
AlertDialog
.
Builder
(
it
)
protocol
=
"http://"
.
setTitle
(
R
.
string
.
msg_warning
)
}
.
setMessage
(
R
.
string
.
msg_http_insecure
)
.
setNegativeButton
(
R
.
string
.
msg_cancel
)
{
_
,
_
->
.
setPositiveButton
(
R
.
string
.
msg_proceed
)
{
_
,
_
->
text_server_protocol
.
setSelection
(
0
)
protocol
=
"http://"
}
}
.
setCancelable
(
false
)
.
setNegativeButton
(
R
.
string
.
msg_cancel
)
{
_
,
_
->
.
create
()
text_server_protocol
.
setSelection
(
0
)
.
show
()
}
.
setCancelable
(
false
)
.
create
()
.
show
()
}
}
}
}
}
}
}
ignoreChange
=
false
}
}
override
fun
onNothingSelected
(
parent
:
AdapterView
<
*
>?)
{
override
fun
onNothingSelected
(
parent
:
AdapterView
<
*
>?)
{
...
@@ -174,13 +181,23 @@ class ServerFragment : Fragment(), ServerView {
...
@@ -174,13 +181,23 @@ class ServerFragment : Fragment(), ServerView {
showMessage
(
R
.
string
.
msg_invalid_server_protocol
)
showMessage
(
R
.
string
.
msg_invalid_server_protocol
)
}
}
override
fun
updateServerUrl
(
url
:
HttpUrl
)
{
if
(
activity
!=
null
&&
view
!=
null
)
{
if
(
url
.
scheme
()
==
"https"
)
text_server_protocol
.
setSelection
(
0
)
else
text_server_protocol
.
setSelection
(
1
)
protocol
=
"${url.scheme()}://"
val
serverUrl
=
url
.
toString
().
removePrefix
(
"${url.scheme()}://"
)
text_server_url
.
textContent
=
serverUrl
}
}
private
fun
performConnect
()
{
private
fun
performConnect
()
{
ui
{
ui
{
deepLinkInfo
?.
let
{
deepLinkInfo
?.
let
{
presenter
.
deepLink
(
it
)
presenter
.
deepLink
(
it
)
}.
ifNull
{
}.
ifNull
{
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
val
url
=
text_server_url
.
textContent
.
ifEmpty
(
text_server_url
.
hintContent
)
presenter
.
connect
(
"$
{protocol}
${url.sanitize()}"
)
presenter
.
connect
(
"$
protocol
${url.sanitize()}"
)
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
1a1213da
...
@@ -150,9 +150,24 @@ class ChatRoomPresenter @Inject constructor(
...
@@ -150,9 +150,24 @@ class ChatRoomPresenter @Inject constructor(
urls
=
null
,
urls
=
null
,
isTemporary
=
true
isTemporary
=
true
)
)
messagesRepository
.
save
(
newMessage
)
try
{
view
.
showNewMessage
(
mapper
.
map
(
newMessage
))
val
message
=
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
messagesRepository
.
save
(
newMessage
)
view
.
showNewMessage
(
mapper
.
map
(
newMessage
))
message
}
catch
(
ex
:
Exception
)
{
// Ok, not very beautiful, but the backend sends us a not valid response
// When someone sends a message on a read-only channel, so we just ignore it
// and show a generic error message
// TODO - remove the generic message when we implement :userId:/message subscription
if
(
ex
is
IllegalStateException
)
{
Timber
.
d
(
ex
,
"Probably a read-only problem..."
)
view
.
showGenericErrorMessage
()
}
else
{
// some other error, just rethrow it...
throw
ex
}
}
}
else
{
}
else
{
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
}
}
...
...
app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt
View file @
1a1213da
...
@@ -8,6 +8,7 @@ import chat.rocket.android.util.VersionInfo
...
@@ -8,6 +8,7 @@ import chat.rocket.android.util.VersionInfo
import
chat.rocket.android.util.extensions.launchUI
import
chat.rocket.android.util.extensions.launchUI
import
chat.rocket.android.util.retryIO
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatInvalidProtocolException
import
chat.rocket.common.RocketChatInvalidProtocolException
import
chat.rocket.common.model.ServerInfo
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.serverInfo
import
chat.rocket.core.internal.rest.serverInfo
import
kotlinx.coroutines.experimental.Deferred
import
kotlinx.coroutines.experimental.Deferred
...
@@ -26,7 +27,13 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
...
@@ -26,7 +27,13 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
try
{
try
{
currentServer
=
serverUrl
currentServer
=
serverUrl
client
=
factory
.
create
(
currentServer
)
client
=
factory
.
create
(
currentServer
)
val
version
=
checkServerVersion
(
serverUrl
).
await
()
val
serverInfo
=
retryIO
(
description
=
"serverInfo"
,
times
=
5
)
{
client
.
serverInfo
()
}
if
(
serverInfo
.
redirected
)
{
view
.
updateServerUrl
(
serverInfo
.
url
)
}
val
version
=
checkServerVersion
(
serverInfo
)
when
(
version
)
{
when
(
version
)
{
is
Version
.
VersionOk
->
{
is
Version
.
VersionOk
->
{
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: ${version.version})"
)
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: ${version.version})"
)
...
@@ -55,23 +62,19 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
...
@@ -55,23 +62,19 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
}
}
}
}
internal
fun
checkServerVersion
(
serverUrl
:
String
):
Deferred
<
Version
>
{
private
fun
checkServerVersion
(
serverInfo
:
ServerInfo
):
Version
{
currentServer
=
serverUrl
val
thisServerVersion
=
serverInfo
.
version
return
async
{
val
isRequiredVersion
=
isRequiredServerVersion
(
thisServerVersion
)
val
serverInfo
=
retryIO
(
description
=
"serverInfo"
,
times
=
5
)
{
client
.
serverInfo
()
}
val
isRecommendedVersion
=
isRecommendedServerVersion
(
thisServerVersion
)
val
thisServerVersion
=
serverInfo
.
version
return
if
(
isRequiredVersion
)
{
val
isRequiredVersion
=
isRequiredServerVersion
(
thisServerVersion
)
if
(
isRecommendedVersion
)
{
val
isRecommendedVersion
=
isRecommendedServerVersion
(
thisServerVersion
)
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: $thisServerVersion)"
)
if
(
isRequiredVersion
)
{
Version
.
VersionOk
(
thisServerVersion
)
if
(
isRecommendedVersion
)
{
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: $thisServerVersion)"
)
return
@async
Version
.
VersionOk
(
thisServerVersion
)
}
else
{
return
@async
Version
.
RecommendedVersionWarning
(
thisServerVersion
)
}
}
else
{
}
else
{
return
@async
Version
.
OutOfDateError
(
thisServerVersion
)
Version
.
RecommendedVersionWarning
(
thisServerVersion
)
}
}
}
else
{
Version
.
OutOfDateError
(
thisServerVersion
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment