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
e5ed1f44
Commit
e5ed1f44
authored
Nov 11, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix MethodCall's paramJson to set JSONArray for accepting multiple params.
parent
feb65d69
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
44 deletions
+49
-44
MethodCallHelper.java
...ain/java/chat/rocket/android/helper/MethodCallHelper.java
+48
-42
RocketChatWebSocketAPI.java
...n/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
+1
-2
No files found.
app/src/main/java/chat/rocket/android/helper/MethodCallHelper.java
View file @
e5ed1f44
...
@@ -57,7 +57,7 @@ public class MethodCallHelper {
...
@@ -57,7 +57,7 @@ public class MethodCallHelper {
}
}
private
interface
ParamBuilder
{
private
interface
ParamBuilder
{
void
buildParam
(
JSON
Object
param
)
throws
JSONException
;
void
buildParam
(
JSON
Array
param
)
throws
JSONException
;
}
}
private
<
T
>
Task
<
T
>
call
(
String
methodName
,
private
<
T
>
Task
<
T
>
call
(
String
methodName
,
...
@@ -68,15 +68,15 @@ public class MethodCallHelper {
...
@@ -68,15 +68,15 @@ public class MethodCallHelper {
private
<
T
>
Task
<
T
>
call
(
String
methodName
,
ParamBuilder
paramBuilder
,
private
<
T
>
Task
<
T
>
call
(
String
methodName
,
ParamBuilder
paramBuilder
,
Continuation
<
JSONObject
,
Task
<
T
>>
onSuccess
)
{
Continuation
<
JSONObject
,
Task
<
T
>>
onSuccess
)
{
JSON
Object
param
=
new
JSONObject
();
JSON
Array
params
=
new
JSONArray
();
try
{
try
{
paramBuilder
.
buildParam
(
param
);
paramBuilder
.
buildParam
(
param
s
);
}
catch
(
JSONException
exception
)
{
}
catch
(
JSONException
exception
)
{
return
Task
.
forError
(
exception
);
return
Task
.
forError
(
exception
);
}
}
return
injectErrorHandler
(
executeMethodCall
(
methodName
,
param
.
toString
()))
return
injectErrorHandler
(
executeMethodCall
(
methodName
,
param
s
.
toString
()))
.
onSuccessTask
(
onSuccess
);
.
onSuccessTask
(
onSuccess
);
}
}
...
@@ -85,11 +85,11 @@ public class MethodCallHelper {
...
@@ -85,11 +85,11 @@ public class MethodCallHelper {
*/
*/
public
Task
<
Void
>
registerUser
(
final
String
name
,
final
String
email
,
public
Task
<
Void
>
registerUser
(
final
String
name
,
final
String
email
,
final
String
password
,
final
String
confirmPassword
)
{
final
String
password
,
final
String
confirmPassword
)
{
return
call
(
"registerUser"
,
param
->
param
return
call
(
"registerUser"
,
param
s
->
params
.
put
(
new
JSONObject
()
.
put
(
"name"
,
name
)
.
put
(
"name"
,
name
)
.
put
(
"email"
,
email
)
.
put
(
"email"
,
email
)
.
put
(
"pass"
,
password
)
.
put
(
"pass"
,
password
)
.
put
(
"confirm-pass"
,
confirmPassword
),
.
put
(
"confirm-pass"
,
confirmPassword
)
)
,
task
->
Task
.
forResult
(
null
));
// nothing to do.
task
->
Task
.
forResult
(
null
));
// nothing to do.
}
}
...
@@ -105,7 +105,8 @@ public class MethodCallHelper {
...
@@ -105,7 +105,8 @@ public class MethodCallHelper {
* Login with username/email and password.
* Login with username/email and password.
*/
*/
public
Task
<
Void
>
loginWithEmail
(
final
String
usernameOrEmail
,
final
String
password
)
{
public
Task
<
Void
>
loginWithEmail
(
final
String
usernameOrEmail
,
final
String
password
)
{
return
call
(
"login"
,
param
->
{
return
call
(
"login"
,
params
->
{
JSONObject
param
=
new
JSONObject
();
if
(
Patterns
.
EMAIL_ADDRESS
.
matcher
(
usernameOrEmail
).
matches
())
{
if
(
Patterns
.
EMAIL_ADDRESS
.
matcher
(
usernameOrEmail
).
matches
())
{
param
.
put
(
"user"
,
new
JSONObject
().
put
(
"email"
,
usernameOrEmail
));
param
.
put
(
"user"
,
new
JSONObject
().
put
(
"email"
,
usernameOrEmail
));
}
else
{
}
else
{
...
@@ -114,6 +115,7 @@ public class MethodCallHelper {
...
@@ -114,6 +115,7 @@ public class MethodCallHelper {
param
.
put
(
"password"
,
new
JSONObject
()
param
.
put
(
"password"
,
new
JSONObject
()
.
put
(
"digest"
,
CheckSum
.
sha256
(
password
))
.
put
(
"digest"
,
CheckSum
.
sha256
(
password
))
.
put
(
"algorithm"
,
"sha-256"
));
.
put
(
"algorithm"
,
"sha-256"
));
params
.
put
(
param
);
},
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
},
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
}
}
...
@@ -122,18 +124,18 @@ public class MethodCallHelper {
...
@@ -122,18 +124,18 @@ public class MethodCallHelper {
*/
*/
public
Task
<
Void
>
loginWithGitHub
(
final
String
credentialToken
,
public
Task
<
Void
>
loginWithGitHub
(
final
String
credentialToken
,
final
String
credentialSecret
)
{
final
String
credentialSecret
)
{
return
call
(
"login"
,
param
->
param
return
call
(
"login"
,
param
s
->
params
.
put
(
new
JSONObject
()
.
put
(
"oauth"
,
new
JSONObject
()
.
put
(
"oauth"
,
new
JSONObject
()
.
put
(
"credentialToken"
,
credentialToken
)
.
put
(
"credentialToken"
,
credentialToken
)
.
put
(
"credentialSecret"
,
credentialSecret
)),
.
put
(
"credentialSecret"
,
credentialSecret
))
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
),
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
}
}
/**
/**
* Login with token.
* Login with token.
*/
*/
public
Task
<
Void
>
loginWithToken
(
final
String
token
)
{
public
Task
<
Void
>
loginWithToken
(
final
String
token
)
{
return
call
(
"login"
,
param
->
param
.
put
(
"resume"
,
token
),
return
call
(
"login"
,
param
->
param
.
put
(
new
JSONObject
().
put
(
"resume"
,
token
)
),
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
task
->
Task
.
forResult
(
task
.
getResult
().
getString
(
"token"
))).
onSuccessTask
(
this
::
saveToken
);
}
}
...
@@ -178,35 +180,39 @@ public class MethodCallHelper {
...
@@ -178,35 +180,39 @@ public class MethodCallHelper {
}
}
private
Task
<
Long
>
getObjectRecursive
(
String
objName
,
Customizer
customizer
,
long
timestamp
)
{
private
Task
<
Long
>
getObjectRecursive
(
String
objName
,
Customizer
customizer
,
long
timestamp
)
{
return
call
(
objName
+
"/get"
,
param
->
param
.
put
(
"$date"
,
timestamp
),
task
->
{
return
call
(
objName
+
"/get"
,
JSONObject
result
=
task
.
getResult
();
params
->
params
.
put
(
new
JSONObject
().
put
(
"$date"
,
timestamp
)),
task
->
{
long
nextTimestamp
=
0
;
JSONObject
result
=
task
.
getResult
();
try
{
nextTimestamp
=
result
.
getJSONArray
(
"remove"
)
long
nextTimestamp
=
0
;
.
getJSONObject
(
0
).
getJSONObject
(
"_deletedAt"
).
getLong
(
"$date"
);
try
{
}
catch
(
JSONException
exception
)
{
nextTimestamp
=
result
.
getJSONArray
(
"remove"
)
// keep nextTimestamp = 0
.
getJSONObject
(
0
).
getJSONObject
(
"_deletedAt"
).
getLong
(
"$date"
);
}
}
catch
(
JSONException
exception
)
{
// keep nextTimestamp = 0
try
{
}
JSONArray
updatedRooms
=
result
.
getJSONArray
(
"update"
);
customizer
.
customizeResult
(
updatedRooms
);
try
{
JSONArray
updatedRooms
=
result
.
getJSONArray
(
"update"
);
Task
<
Void
>
saveToDB
=
RealmHelperBolts
.
executeTransaction
(
realm
->
{
customizer
.
customizeResult
(
updatedRooms
);
realm
.
createOrUpdateAllFromJson
(
RoomSubscription
.
class
,
result
.
getJSONArray
(
"update"
));
return
null
;
Task
<
Void
>
saveToDB
=
RealmHelperBolts
.
executeTransaction
(
realm
->
{
realm
.
createOrUpdateAllFromJson
(
RoomSubscription
.
class
,
result
.
getJSONArray
(
"update"
));
return
null
;
});
if
(
nextTimestamp
>
0
&&
(
timestamp
==
0
||
nextTimestamp
<
timestamp
))
{
final
long
_next
=
nextTimestamp
;
return
saveToDB
.
onSuccessTask
(
_task
->
getObjectRecursive
(
objName
,
customizer
,
_next
));
}
else
{
return
saveToDB
.
onSuccessTask
(
_task
->
Task
.
forResult
(
0L
));
}
}
catch
(
JSONException
exception
)
{
return
Task
.
forError
(
exception
);
}
});
});
if
(
nextTimestamp
>
0
&&
(
timestamp
==
0
||
nextTimestamp
<
timestamp
))
{
final
long
_next
=
nextTimestamp
;
return
saveToDB
.
onSuccessTask
(
_task
->
getObjectRecursive
(
objName
,
customizer
,
_next
));
}
else
{
return
saveToDB
.
onSuccessTask
(
_task
->
Task
.
forResult
(
0L
));
}
}
catch
(
JSONException
exception
)
{
return
Task
.
forError
(
exception
);
}
});
}
}
}
}
app/src/main/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
View file @
e5ed1f44
...
@@ -10,7 +10,6 @@ import chat.rocket.android_ddp.DDPSubscription;
...
@@ -10,7 +10,6 @@ import chat.rocket.android_ddp.DDPSubscription;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
rx.Observable
;
import
rx.Observable
;
/**
/**
...
@@ -87,7 +86,7 @@ public class RocketChatWebSocketAPI {
...
@@ -87,7 +86,7 @@ public class RocketChatWebSocketAPI {
}
}
try
{
try
{
return
ddpClient
.
rpc
(
methodName
,
new
JSONArray
(
).
put
(
new
JSONObject
(
params
)
),
methodCallId
);
return
ddpClient
.
rpc
(
methodName
,
new
JSONArray
(
params
),
methodCallId
);
}
catch
(
JSONException
exception
)
{
}
catch
(
JSONException
exception
)
{
return
Task
.
forError
(
exception
);
return
Task
.
forError
(
exception
);
}
}
...
...
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