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
ef3afda1
Commit
ef3afda1
authored
Dec 08, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat indentation and implement call to loadMissedMessages method
parent
492e3d0e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
589 additions
and
536 deletions
+589
-536
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+589
-536
No files found.
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
ef3afda1
...
...
@@ -7,13 +7,16 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.Iterator
;
import
java.util.UUID
;
import
bolts.Continuation
;
import
bolts.Task
;
import
chat.rocket.android.RocketChatApplication
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.helper.CheckSum
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android_ddp.DDPClient
;
import
chat.rocket.android_ddp.DDPClientCallback
;
...
...
@@ -32,11 +35,12 @@ import chat.rocket.persistence.realm.models.ddp.RealmSpotlightUser;
import
chat.rocket.persistence.realm.models.internal.MethodCall
;
import
chat.rocket.persistence.realm.models.internal.RealmSession
;
import
hugo.weaving.DebugLog
;
import
io.realm.RealmQuery
;
import
okhttp3.HttpUrl
;
/**
* Utility class for creating/handling MethodCall or RPC.
*
*
<p>
* TODO: separate method into several manager classes (SubscriptionManager, MessageManager, ...).
*/
public
class
MethodCallHelper
{
...
...
@@ -299,6 +303,29 @@ public class MethodCallHelper {
realm
.
delete
(
RealmRoom
.
class
);
realm
.
createOrUpdateAllFromJson
(
RealmRoom
.
class
,
result
);
Context
appContext
=
RocketChatApplication
.
getInstance
();
RocketChatCache
cache
=
new
RocketChatCache
(
appContext
);
JSONObject
openedRooms
=
cache
.
getOpenedRooms
();
RealmQuery
<
RealmRoom
>
query
=
realm
.
where
(
RealmRoom
.
class
);
Iterator
<
String
>
keys
=
openedRooms
.
keys
();
while
(
keys
.
hasNext
())
{
String
rid
=
keys
.
next
();
RealmRoom
realmRoom
=
query
.
equalTo
(
RealmRoom
.
ID
,
rid
).
findFirst
();
if
(
realmRoom
==
null
)
{
cache
.
removeOpenedRoom
(
rid
);
}
else
{
loadMissedMessages
(
rid
,
realmRoom
.
getLastSeen
())
.
continueWithTask
(
task1
->
{
if
(
task1
.
isFaulted
())
{
Exception
error
=
task1
.
getError
();
RCLog
.
e
(
error
);
}
return
null
;
});
}
}
return
null
;
});
}
catch
(
JSONException
exception
)
{
...
...
@@ -307,6 +334,32 @@ public class MethodCallHelper {
});
}
public
Task
<
JSONArray
>
loadMissedMessages
(
final
String
roomId
,
final
long
timestamp
)
{
return
call
(
"loadMissedMessages"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
roomId
)
.
put
(
timestamp
>
0
?
new
JSONObject
().
put
(
"$date"
,
timestamp
)
:
JSONObject
.
NULL
)
).
onSuccessTask
(
CONVERT_TO_JSON_ARRAY
)
.
onSuccessTask
(
task
->
{
JSONArray
result
=
task
.
getResult
();
for
(
int
i
=
0
;
i
<
result
.
length
();
i
++)
{
RealmMessage
.
customizeJson
(
result
.
getJSONObject
(
i
));
}
return
realmHelper
.
executeTransaction
(
realm
->
{
if
(
timestamp
==
0
)
{
realm
.
where
(
RealmMessage
.
class
)
.
equalTo
(
"rid"
,
roomId
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
findAll
().
deleteAllFromRealm
();
}
if
(
result
.
length
()
>
0
)
{
realm
.
createOrUpdateAllFromJson
(
RealmMessage
.
class
,
result
);
}
return
null
;
}).
onSuccessTask
(
_task
->
Task
.
forResult
(
result
));
});
}
/**
* Load messages for room.
*/
...
...
@@ -406,7 +459,7 @@ public class MethodCallHelper {
.
put
(
"_id"
,
messageID
);
return
deleteMessage
(
messageJson
);
}
catch
(
JSONException
exception
)
{
}
catch
(
JSONException
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