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
df8e10b2
Commit
df8e10b2
authored
Nov 07, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set login request thread appropriately
parent
b17f6049
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
10 deletions
+33
-10
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+30
-8
LoginPresenter.java
...rocket/android/fragment/server_config/LoginPresenter.java
+1
-1
TwoStepAuthPresenter.java
.../android/fragment/server_config/TwoStepAuthPresenter.java
+2
-1
No files found.
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
df8e10b2
...
...
@@ -74,7 +74,13 @@ public class MethodCallHelper {
private
Task
<
String
>
executeMethodCall
(
String
methodName
,
String
param
,
long
timeout
)
{
if
(
DDPClient
.
get
()
!=
null
)
{
return
DDPClient
.
get
().
rpc
(
UUID
.
randomUUID
().
toString
(),
methodName
,
param
,
timeout
)
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
result
));
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
result
))
.
continueWithTask
(
task_
->
{
if
(
task_
.
isFaulted
())
{
return
Task
.
forError
(
task_
.
getError
());
}
return
Task
.
forResult
(
task_
.
getResult
());
});
}
else
{
return
MethodCall
.
execute
(
realmHelper
,
methodName
,
param
,
timeout
)
.
onSuccessTask
(
task
->
{
...
...
@@ -89,8 +95,13 @@ public class MethodCallHelper {
return
task
.
continueWithTask
(
_task
->
{
if
(
_task
.
isFaulted
())
{
Exception
exception
=
_task
.
getError
();
if
(
exception
instanceof
MethodCall
.
Error
)
{
String
errMessageJson
=
exception
.
getMessage
();
if
(
exception
instanceof
MethodCall
.
Error
||
exception
instanceof
DDPClientCallback
.
RPC
.
Error
)
{
String
errMessageJson
;
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Error
)
{
errMessageJson
=
((
DDPClientCallback
.
RPC
.
Error
)
exception
).
error
.
toString
();
}
else
{
errMessageJson
=
exception
.
getMessage
();
}
if
(
TextUtils
.
isEmpty
(
errMessageJson
))
{
return
Task
.
forError
(
exception
);
}
...
...
@@ -101,9 +112,6 @@ public class MethodCallHelper {
return
Task
.
forError
(
new
TwoStepAuthException
(
errMessage
));
}
return
Task
.
forError
(
new
Exception
(
errMessage
));
}
else
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Error
)
{
String
errMessage
=
((
DDPClientCallback
.
RPC
.
Error
)
exception
).
error
.
getString
(
"message"
);
return
Task
.
forError
(
new
Exception
(
errMessage
));
}
else
if
(
exception
instanceof
DDPClientCallback
.
RPC
.
Timeout
)
{
return
Task
.
forError
(
new
MethodCall
.
Timeout
());
}
else
{
...
...
@@ -115,6 +123,20 @@ public class MethodCallHelper {
});
}
private
Task
<
Exception
>
extractError
(
Exception
exception
)
throws
JSONException
{
String
errMessageJson
=
exception
.
getMessage
();
if
(
TextUtils
.
isEmpty
(
errMessageJson
))
{
return
Task
.
forError
(
exception
);
}
String
errType
=
new
JSONObject
(
errMessageJson
).
optString
(
"error"
);
String
errMessage
=
new
JSONObject
(
errMessageJson
).
getString
(
"message"
);
if
(
TwoStepAuthException
.
TYPE
.
equals
(
errType
))
{
return
Task
.
forError
(
new
TwoStepAuthException
(
errMessage
));
}
return
Task
.
forError
(
new
Exception
(
errMessage
));
}
protected
final
Task
<
String
>
call
(
String
methodName
,
long
timeout
)
{
return
injectErrorHandler
(
executeMethodCall
(
methodName
,
null
,
timeout
));
}
...
...
@@ -184,8 +206,8 @@ public class MethodCallHelper {
.
put
(
"algorithm"
,
"sha-256"
));
return
new
JSONArray
().
put
(
param
);
}).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
)
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
)))
.
onSuccessTask
(
this
::
saveToken
);
.
onSuccessTask
(
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
)))
.
onSuccessTask
(
this
::
saveToken
);
}
public
Task
<
Void
>
loginWithLdap
(
final
String
username
,
final
String
password
)
{
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/LoginPresenter.java
View file @
df8e10b2
...
...
@@ -85,7 +85,7 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
}
}
return
null
;
});
}
,
Task
.
UI_THREAD_EXECUTOR
);
}
private
Task
<
Void
>
call
(
String
username
,
String
password
,
Optional
<
PublicSetting
>
optional
)
{
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/TwoStepAuthPresenter.java
View file @
df8e10b2
package
chat
.
rocket
.
android
.
fragment
.
server_config
;
import
bolts.Task
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.shared.BasePresenter
;
...
...
@@ -29,6 +30,6 @@ public class TwoStepAuthPresenter extends BasePresenter<TwoStepAuthContract.View
view
.
showError
(
task
.
getError
().
getMessage
());
}
return
null
;
});
}
,
Task
.
UI_THREAD_EXECUTOR
);
}
}
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