Commit 174d5d12 authored by Tiago Cunha's avatar Tiago Cunha

Fix resend crash

parent 93333f70
......@@ -114,7 +114,8 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override
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()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe();
......@@ -204,11 +205,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
private Single<Pair<Room, User>> getRoomUserPair() {
return Single.zip(
getSingleRoom(),
userRepository.getCurrent()
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle(),
getCurrentUser(),
Pair::new
);
}
......@@ -218,4 +215,12 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.firstElement()
.toSingle();
}
private Single<User> getCurrentUser() {
return userRepository.getCurrent()
.filter(Optional::isPresent)
.map(Optional::get)
.firstElement()
.toSingle();
}
}
......@@ -63,9 +63,10 @@ public class MessageInteractor {
return messageRepository.save(message);
}
public Single<Boolean> resend(Message message) {
public Single<Boolean> resend(Message message, User sender) {
return messageRepository.save(
message.withSyncState(SyncState.NOT_SYNCED));
message.withSyncState(SyncState.NOT_SYNCED)
.withUser(sender));
}
public Single<Boolean> delete(Message message) {
......
......@@ -40,6 +40,8 @@ public abstract class Message {
public abstract Message withSyncState(int syncState);
public abstract Message withUser(User user);
public static Builder 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