Commit 86adbe67 authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #193 from RocketChat/fix/sync-failure-error

Fix incorrect behavior
parents d6380c71 a78c1b6c
......@@ -301,7 +301,7 @@ public class MethodCallHelper {
/**
* send message.
*/
public Task<JSONObject> sendMessage(String messageId, String roomId, String msg) {
public Task<Void> sendMessage(String messageId, String roomId, String msg) {
try {
return sendMessage(new JSONObject()
.put("_id", messageId)
......@@ -315,10 +315,9 @@ public class MethodCallHelper {
/**
* Send message object.
*/
private Task<JSONObject> sendMessage(final JSONObject messageJson) {
private Task<Void> sendMessage(final JSONObject messageJson) {
return call("sendMessage", TIMEOUT_MS, () -> new JSONArray().put(messageJson))
.onSuccessTask(CONVERT_TO_JSON_OBJECT)
.onSuccessTask(task -> Task.forResult(Message.customizeJson(task.getResult())));
.onSuccessTask(task -> Task.forResult(null));
}
/**
......
......@@ -53,7 +53,7 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
return;
}
Message message = results.get(0);
final Message message = results.get(0);
final String messageId = message.getId();
final String roomId = message.getRoomId();
final String msg = message.getMessage();
......@@ -63,13 +63,7 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
.put(Message.ID, messageId)
.put(Message.SYNC_STATE, SyncState.SYNCING)
)
).onSuccessTask(task ->
methodCall.sendMessage(messageId, roomId, msg).onSuccessTask(_task -> {
JSONObject messageJson = _task.getResult();
messageJson.put("syncstate", SyncState.SYNCED);
return realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(Message.class, messageJson));
})
).onSuccessTask(task -> methodCall.sendMessage(messageId, roomId, msg)
).continueWith(task -> {
if (task.isFaulted()) {
RCLog.w(task.getError());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment