mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 03:59:35 +01:00
Fix duplicate messages
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
86f30afe06
commit
9fa4f55bbc
@ -114,6 +114,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
|||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import okhttp3.Cache;
|
import okhttp3.Cache;
|
||||||
|
import retrofit2.HttpException;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
@ -158,10 +159,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
private Boolean startCallFromNotification;
|
private Boolean startCallFromNotification;
|
||||||
private String roomId;
|
private String roomId;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO:
|
|
||||||
- check push notifications
|
|
||||||
*/
|
|
||||||
public ChatController(Bundle args) {
|
public ChatController(Bundle args) {
|
||||||
super(args);
|
super(args);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
@ -340,7 +337,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
|
|
||||||
messageInput.getInputEditText().setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
messageInput.getInputEditText().setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||||
messageInput.setInputListener(input -> {
|
messageInput.setInputListener(input -> {
|
||||||
sendMessage(input.toString());
|
sendMessage(input.toString(), 1);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -522,46 +519,61 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String message) {
|
private void sendMessage(String message, int attempt) {
|
||||||
Map<String, String> fieldMap = new HashMap<>();
|
if (attempt < 4) {
|
||||||
fieldMap.put("message", message);
|
Map<String, String> fieldMap = new HashMap<>();
|
||||||
fieldMap.put("actorDisplayName", conversationUser.getDisplayName());
|
fieldMap.put("message", message);
|
||||||
|
fieldMap.put("actorDisplayName", conversationUser.getDisplayName());
|
||||||
|
|
||||||
|
ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap)
|
||||||
|
.subscribeOn(Schedulers.newThread())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<GenericOverall>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
ncApi.sendChatMessage(credentials, ApiUtils.getUrlForChat(baseUrl, roomToken), fieldMap)
|
|
||||||
.subscribeOn(Schedulers.newThread())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.retry(3, observable -> inChat)
|
|
||||||
.subscribe(new Observer<GenericOverall>() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(GenericOverall genericOverall) {
|
|
||||||
if (conversationUser.getUserId().equals("-1") && TextUtils.isEmpty(myFirstMessage)) {
|
|
||||||
myFirstMessage = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getActivity().runOnUiThread(() -> {
|
@Override
|
||||||
if (popupBubble.isShown()) {
|
public void onNext(GenericOverall genericOverall) {
|
||||||
popupBubble.hide();
|
if (conversationUser.getUserId().equals("-1") && TextUtils.isEmpty(myFirstMessage)) {
|
||||||
|
myFirstMessage = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
messagesList.smoothScrollToPosition(0);
|
getActivity().runOnUiThread(() -> {
|
||||||
});
|
if (popupBubble.isShown()) {
|
||||||
}
|
popupBubble.hide();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
messagesList.smoothScrollToPosition(0);
|
||||||
public void onError(Throwable e) {
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onError(Throwable e) {
|
||||||
|
if (e instanceof HttpException && ((HttpException) e).code() == 201) {
|
||||||
|
if (conversationUser.getUserId().equals("-1") && TextUtils.isEmpty(myFirstMessage)) {
|
||||||
|
myFirstMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
getActivity().runOnUiThread(() -> {
|
||||||
});
|
if (popupBubble.isShown()) {
|
||||||
|
popupBubble.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
messagesList.smoothScrollToPosition(0);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sendMessage(message, attempt + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pullChatMessages(int lookIntoFuture) {
|
private void pullChatMessages(int lookIntoFuture) {
|
||||||
@ -679,7 +691,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||||||
adapter.getItemCount() == 0;
|
adapter.getItemCount() == 0;
|
||||||
|
|
||||||
if (!shouldScroll) {
|
if (!shouldScroll) {
|
||||||
if (!popupBubble.isShown()) {
|
if (!popupBubble.isShown() && layoutManager.findFirstVisibleItemPosition() != 0) {
|
||||||
newMessagesCount = 1;
|
newMessagesCount = 1;
|
||||||
popupBubble.show();
|
popupBubble.show();
|
||||||
} else if (popupBubble.isShown()) {
|
} else if (popupBubble.isShown()) {
|
||||||
|
@ -27,15 +27,12 @@ import org.parceler.Parcel;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Parcel
|
@Parcel
|
||||||
@JsonObject
|
@JsonObject
|
||||||
public class ChatOCS extends GenericOCS {
|
public class ChatOCS extends GenericOCS {
|
||||||
@Nullable
|
|
||||||
@JsonField(name = "data")
|
@JsonField(name = "data")
|
||||||
List<ChatMessage> data;
|
List<ChatMessage> data;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user