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
d593760b
Commit
d593760b
authored
Nov 13, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement hasNext for LoadMessageProcedure
parent
df75aae5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
7 deletions
+105
-7
MethodCallHelper.java
...ain/java/chat/rocket/android/helper/MethodCallHelper.java
+3
-1
Message.java
app/src/main/java/chat/rocket/android/model/ddp/Message.java
+84
-1
LoadMessageProcedureObserver.java
...ndroid/service/observer/LoadMessageProcedureObserver.java
+18
-5
No files found.
app/src/main/java/chat/rocket/android/helper/MethodCallHelper.java
View file @
d593760b
...
...
@@ -202,7 +202,9 @@ public class MethodCallHelper {
if
(
timestamp
==
0
)
{
realm
.
where
(
Message
.
class
).
equalTo
(
"rid"
,
roomId
).
findAll
().
deleteAllFromRealm
();
}
realm
.
createOrUpdateAllFromJson
(
Message
.
class
,
messages
);
if
(
messages
.
length
()
>
0
)
{
realm
.
createOrUpdateAllFromJson
(
Message
.
class
,
messages
);
}
return
null
;
});
});
...
...
app/src/main/java/chat/rocket/android/model/ddp/Message.java
View file @
d593760b
package
chat
.
rocket
.
android
.
model
.
ddp
;
import
chat.rocket.android.model.SyncState
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
import
io.realm.annotations.PrimaryKey
;
...
...
@@ -12,9 +13,12 @@ import org.json.JSONObject;
@SuppressWarnings
({
"PMD.ShortClassName"
,
"PMD.ShortVariable"
,
"PMD.MethodNamingConventions"
,
"PMD.VariableNamingConventions"
})
public
class
Message
extends
RealmObject
{
//ref: Rocket.Chat:packages/rocketchat-lib/lib/MessageTypes.coffee
@PrimaryKey
private
String
_id
;
private
String
t
;
//type:
private
String
rid
;
//roomId.
private
int
syncstate
;
private
long
ts
;
private
String
msg
;
private
User
u
;
...
...
@@ -22,11 +26,90 @@ public class Message extends RealmObject {
private
RealmList
<
MessageAttachment
>
attachments
;
private
RealmList
<
MessageUrl
>
urls
;
public
String
get_id
()
{
return
_id
;
}
public
void
set_id
(
String
_id
)
{
this
.
_id
=
_id
;
}
public
String
getT
()
{
return
t
;
}
public
void
setT
(
String
t
)
{
this
.
t
=
t
;
}
public
String
getRid
()
{
return
rid
;
}
public
void
setRid
(
String
rid
)
{
this
.
rid
=
rid
;
}
public
int
getSyncstate
()
{
return
syncstate
;
}
public
void
setSyncstate
(
int
syncstate
)
{
this
.
syncstate
=
syncstate
;
}
public
long
getTs
()
{
return
ts
;
}
public
void
setTs
(
long
ts
)
{
this
.
ts
=
ts
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
User
getU
()
{
return
u
;
}
public
void
setU
(
User
u
)
{
this
.
u
=
u
;
}
public
boolean
isGroupable
()
{
return
groupable
;
}
public
void
setGroupable
(
boolean
groupable
)
{
this
.
groupable
=
groupable
;
}
public
RealmList
<
MessageAttachment
>
getAttachments
()
{
return
attachments
;
}
public
void
setAttachments
(
RealmList
<
MessageAttachment
>
attachments
)
{
this
.
attachments
=
attachments
;
}
public
RealmList
<
MessageUrl
>
getUrls
()
{
return
urls
;
}
public
void
setUrls
(
RealmList
<
MessageUrl
>
urls
)
{
this
.
urls
=
urls
;
}
public
static
JSONObject
customizeJson
(
JSONObject
messageJson
)
throws
JSONException
{
long
ts
=
messageJson
.
getJSONObject
(
"ts"
).
getLong
(
"$date"
);
messageJson
.
remove
(
"ts"
);
messageJson
.
put
(
"ts"
,
ts
);
messageJson
.
put
(
"ts"
,
ts
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
;
return
messageJson
;
}
...
...
app/src/main/java/chat/rocket/android/service/observer/LoadMessageProcedureObserver.java
View file @
d593760b
...
...
@@ -5,10 +5,13 @@ import bolts.Task;
import
chat.rocket.android.helper.MethodCallHelper
;
import
chat.rocket.android.model.LoadMessageProcedure
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.ws.RocketChatWebSocketAPI
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
io.realm.Sort
;
import
java.util.List
;
import
jp.co.crowdworks.realm_java_helpers.RealmHelper
;
import
jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
...
...
@@ -51,11 +54,21 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
.
put
(
"syncstate"
,
SyncState
.
SYNCING
))
).
onSuccessTask
(
task
->
methodCall
.
loadHistory
(
roomId
,
isReset
?
0
:
timestamp
,
count
,
lastSeen
)
.
onSuccessTask
(
_task
->
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
))))
.
onSuccessTask
(
_task
->
{
Message
lastMessage
=
RealmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
"rid"
,
roomId
)
.
equalTo
(
"syncstate"
,
SyncState
.
SYNCED
)
.
findAllSorted
(
"ts"
,
Sort
.
ASCENDING
).
last
(
null
));
long
lastTs
=
lastMessage
!=
null
?
lastMessage
.
getTs
()
:
0
;
return
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
LoadMessageProcedure
.
class
,
new
JSONObject
()
.
put
(
"roomId"
,
roomId
)
.
put
(
"syncstate"
,
SyncState
.
SYNCED
)
.
put
(
"timestamp"
,
lastTs
)
.
put
(
"hasNext"
,
lastTs
>
0
))
);
})
).
continueWithTask
(
task
->
{
if
(
task
.
isFaulted
())
{
Timber
.
w
(
task
.
getError
());
...
...
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