Commit 7694ff8a authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #216 from RocketChat/fix/resend-crashes

Fix resend crash
parents 994b32c3 c8630df4
...@@ -114,7 +114,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -114,7 +114,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override @Override
public void resendMessage(Message message) { public void resendMessage(Message message) {
final Disposable subscription = messageInteractor.resend(message) final Disposable subscription = getCurrentUser()
.flatMap(user -> messageInteractor.resend(message, user))
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(); .subscribe();
...@@ -204,11 +205,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -204,11 +205,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
private Single<Pair<Room, User>> getRoomUserPair() { private Single<Pair<Room, User>> getRoomUserPair() {
return Single.zip( return Single.zip(
getSingleRoom(), getSingleRoom(),
userRepository.getCurrent() getCurrentUser(),
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle(),
Pair::new Pair::new
); );
} }
...@@ -218,4 +215,12 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -218,4 +215,12 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.firstElement() .firstElement()
.toSingle(); .toSingle();
} }
private Single<User> getCurrentUser() {
return userRepository.getCurrent()
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle();
}
} }
...@@ -63,9 +63,10 @@ public class MessageInteractor { ...@@ -63,9 +63,10 @@ public class MessageInteractor {
return messageRepository.save(message); return messageRepository.save(message);
} }
public Single<Boolean> resend(Message message) { public Single<Boolean> resend(Message message, User sender) {
return messageRepository.save( return messageRepository.save(
message.withSyncState(SyncState.NOT_SYNCED)); message.withSyncState(SyncState.NOT_SYNCED)
.withUser(sender));
} }
public Single<Boolean> delete(Message message) { public Single<Boolean> delete(Message message) {
......
...@@ -40,6 +40,8 @@ public abstract class Message { ...@@ -40,6 +40,8 @@ public abstract class Message {
public abstract Message withSyncState(int syncState); public abstract Message withSyncState(int syncState);
public abstract Message withUser(User user);
public static Builder builder() { public static Builder builder() {
return new AutoValue_Message.Builder(); return new AutoValue_Message.Builder();
} }
......
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