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
7c37ce2a
Commit
7c37ce2a
authored
Aug 09, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add searchSpotlight method (for both users and rooms).
parent
d71490b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
7 deletions
+39
-7
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+39
-7
No files found.
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
7c37ce2a
package
chat
.
rocket
.
android
.
api
;
import
android.content.Context
;
import
android.util.Log
;
import
android.util.Patterns
;
import
chat.rocket.persistence.realm.RealmHelper.Transaction
;
import
chat.rocket.persistence.realm.models.ddp.RealmSpotlight
;
import
io.realm.Realm
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -462,15 +466,43 @@ public class MethodCallHelper {
}
public
Task
<
Void
>
searchSpotlightUsers
(
String
term
)
{
return
searchSpotlight
(
RealmSpotlightUser
.
class
,
"users"
,
term
);
return
searchSpotlight
(
RealmSpotlightUser
.
class
,
"users"
,
term
);
}
public
Task
<
Void
>
searchSpotlightRooms
(
String
term
)
{
return
searchSpotlight
(
RealmSpotlightRoom
.
class
,
"rooms"
,
term
);
return
searchSpotlight
(
RealmSpotlightRoom
.
class
,
"rooms"
,
term
);
}
public
Task
<
Void
>
searchSpotlight
(
String
term
)
{
return
call
(
"spotlight"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
term
)
.
put
(
JSONObject
.
NULL
)
.
put
(
new
JSONObject
().
put
(
"rooms"
,
true
).
put
(
"users"
,
true
))
).
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
)
.
onSuccessTask
(
task
->
{
final
JSONObject
result
=
task
.
getResult
();
if
(
result
.
has
(
"rooms"
)
&&
result
.
has
(
"users"
))
{
JSONArray
jsonRoomArray
=
(
JSONArray
)
result
.
get
(
"rooms"
);
JSONArray
jsonUserArray
=
(
JSONArray
)
result
.
get
(
"users"
);
String
roomJsonString
=
jsonRoomArray
.
toString
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
String
userJsonString
=
jsonUserArray
.
toString
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
String
jsonString
=
"["
+
roomJsonString
+
","
+
userJsonString
+
"]"
;
Log
.
i
(
"JSON"
,
jsonString
);
realmHelper
.
executeTransaction
(
new
Transaction
()
{
@Override
public
Object
execute
(
Realm
realm
)
throws
JSONException
{
realm
.
delete
(
RealmSpotlight
.
class
);
realm
.
createOrUpdateAllFromJson
(
RealmSpotlight
.
class
,
jsonString
);
return
null
;
}
});
}
return
null
;
});
}
private
Task
<
Void
>
searchSpotlight
(
Class
clazz
,
String
key
,
String
term
)
{
...
...
@@ -501,4 +533,4 @@ public class MethodCallHelper {
protected
interface
ParamBuilder
{
JSONArray
buildParam
()
throws
JSONException
;
}
}
}
\ No newline at end of file
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