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 {
applicationId
"chat.rocket.android"
minSdkVersion
21
targetSdkVersion
versions
.
targetSdk
versionCode
20
19
versionName
"2.1.
0
"
versionCode
20
20
versionName
"2.1.
1
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled
true
}
...
...
app/src/main/java/chat/rocket/android/authentication/server/presentation/VersionCheckView.kt
View file @
1a1213da
package
chat.rocket.android.authentication.server.presentation
import
okhttp3.HttpUrl
interface
VersionCheckView
{
/**
* Alerts the user about the server version not meeting the recommended server version.
...
...
@@ -26,4 +28,9 @@ interface VersionCheckView {
* Alters the user this protocol is invalid. This is optional.
*/
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.*
import
chat.rocket.common.util.ifNull
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_authentication_server.*
import
okhttp3.HttpUrl
import
javax.inject.Inject
class
ServerFragment
:
Fragment
(),
ServerView
{
...
...
@@ -41,6 +42,7 @@ class ServerFragment : Fragment(), ServerView {
}
private
var
protocol
=
"https://"
private
var
ignoreChange
=
false
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -72,22 +74,27 @@ class ServerFragment : Fragment(), ServerView {
protocol
=
"https://"
}
1
->
{
ui
{
AlertDialog
.
Builder
(
it
)
.
setTitle
(
R
.
string
.
msg_warning
)
.
setMessage
(
R
.
string
.
msg_http_insecure
)
.
setPositiveButton
(
R
.
string
.
msg_proceed
)
{
_
,
_
->
protocol
=
"http://"
}
.
setNegativeButton
(
R
.
string
.
msg_cancel
)
{
_
,
_
->
text_server_protocol
.
setSelection
(
0
)
}
.
setCancelable
(
false
)
.
create
()
.
show
()
if
(
ignoreChange
)
{
protocol
=
"http://"
}
else
{
ui
{
AlertDialog
.
Builder
(
it
)
.
setTitle
(
R
.
string
.
msg_warning
)
.
setMessage
(
R
.
string
.
msg_http_insecure
)
.
setPositiveButton
(
R
.
string
.
msg_proceed
)
{
_
,
_
->
protocol
=
"http://"
}
.
setNegativeButton
(
R
.
string
.
msg_cancel
)
{
_
,
_
->
text_server_protocol
.
setSelection
(
0
)
}
.
setCancelable
(
false
)
.
create
()
.
show
()
}
}
}
}
ignoreChange
=
false
}
override
fun
onNothingSelected
(
parent
:
AdapterView
<
*
>?)
{
...
...
@@ -174,13 +181,23 @@ class ServerFragment : Fragment(), ServerView {
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
()
{
ui
{
deepLinkInfo
?.
let
{
presenter
.
deepLink
(
it
)
}.
ifNull
{
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(
urls
=
null
,
isTemporary
=
true
)
messagesRepository
.
save
(
newMessage
)
view
.
showNewMessage
(
mapper
.
map
(
newMessage
))
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
try
{
val
message
=
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
{
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
import
chat.rocket.android.util.extensions.launchUI
import
chat.rocket.android.util.retryIO
import
chat.rocket.common.RocketChatInvalidProtocolException
import
chat.rocket.common.model.ServerInfo
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.serverInfo
import
kotlinx.coroutines.experimental.Deferred
...
...
@@ -26,7 +27,13 @@ abstract class CheckServerPresenter constructor(private val strategy: CancelStra
try
{
currentServer
=
serverUrl
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
)
{
is
Version
.
VersionOk
->
{
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
}
}
internal
fun
checkServerVersion
(
serverUrl
:
String
):
Deferred
<
Version
>
{
currentServer
=
serverUrl
return
async
{
val
serverInfo
=
retryIO
(
description
=
"serverInfo"
,
times
=
5
)
{
client
.
serverInfo
()
}
val
thisServerVersion
=
serverInfo
.
version
val
isRequiredVersion
=
isRequiredServerVersion
(
thisServerVersion
)
val
isRecommendedVersion
=
isRecommendedServerVersion
(
thisServerVersion
)
if
(
isRequiredVersion
)
{
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
)
}
private
fun
checkServerVersion
(
serverInfo
:
ServerInfo
):
Version
{
val
thisServerVersion
=
serverInfo
.
version
val
isRequiredVersion
=
isRequiredServerVersion
(
thisServerVersion
)
val
isRecommendedVersion
=
isRecommendedServerVersion
(
thisServerVersion
)
return
if
(
isRequiredVersion
)
{
if
(
isRecommendedVersion
)
{
Timber
.
i
(
"Your version is nice! (Requires: 0.62.0, Yours: $thisServerVersion)"
)
Version
.
VersionOk
(
thisServerVersion
)
}
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