|
@@ -37,7 +37,9 @@ import android.text.TextUtils;
|
|
import android.text.TextWatcher;
|
|
import android.text.TextWatcher;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
import android.view.*;
|
|
import android.view.*;
|
|
-import android.widget.*;
|
|
|
|
|
|
+import android.widget.AbsListView;
|
|
|
|
+import android.widget.ImageButton;
|
|
|
|
+import android.widget.ProgressBar;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
@@ -62,6 +64,7 @@ import com.nextcloud.talk.callbacks.MentionAutocompleteCallback;
|
|
import com.nextcloud.talk.components.filebrowser.controllers.BrowserController;
|
|
import com.nextcloud.talk.components.filebrowser.controllers.BrowserController;
|
|
import com.nextcloud.talk.controllers.base.BaseController;
|
|
import com.nextcloud.talk.controllers.base.BaseController;
|
|
import com.nextcloud.talk.events.UserMentionClickEvent;
|
|
import com.nextcloud.talk.events.UserMentionClickEvent;
|
|
|
|
+import com.nextcloud.talk.events.WebSocketCommunicationEvent;
|
|
import com.nextcloud.talk.models.RetrofitBucket;
|
|
import com.nextcloud.talk.models.RetrofitBucket;
|
|
import com.nextcloud.talk.models.database.UserEntity;
|
|
import com.nextcloud.talk.models.database.UserEntity;
|
|
import com.nextcloud.talk.models.json.call.Call;
|
|
import com.nextcloud.talk.models.json.call.Call;
|
|
@@ -80,6 +83,8 @@ import com.nextcloud.talk.utils.database.user.UserUtils;
|
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
|
import com.nextcloud.talk.utils.preferences.AppPreferences;
|
|
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
|
import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
|
|
import com.nextcloud.talk.utils.text.Spans;
|
|
import com.nextcloud.talk.utils.text.Spans;
|
|
|
|
+import com.nextcloud.talk.webrtc.MagicWebSocketInstance;
|
|
|
|
+import com.nextcloud.talk.webrtc.WebSocketConnectionHelper;
|
|
import com.otaliastudios.autocomplete.Autocomplete;
|
|
import com.otaliastudios.autocomplete.Autocomplete;
|
|
import com.otaliastudios.autocomplete.AutocompleteCallback;
|
|
import com.otaliastudios.autocomplete.AutocompleteCallback;
|
|
import com.otaliastudios.autocomplete.AutocompletePresenter;
|
|
import com.otaliastudios.autocomplete.AutocompletePresenter;
|
|
@@ -162,7 +167,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
private String roomId;
|
|
private String roomId;
|
|
private boolean voiceOnly;
|
|
private boolean voiceOnly;
|
|
private boolean isFirstMessagesProcessing = true;
|
|
private boolean isFirstMessagesProcessing = true;
|
|
- private boolean isHelloClicked;
|
|
|
|
private boolean isLeavingForConversation;
|
|
private boolean isLeavingForConversation;
|
|
private boolean isLinkPreviewAllowed;
|
|
private boolean isLinkPreviewAllowed;
|
|
private boolean wasDetached;
|
|
private boolean wasDetached;
|
|
@@ -176,6 +180,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
|
|
|
|
private boolean readOnlyCheckPerformed;
|
|
private boolean readOnlyCheckPerformed;
|
|
|
|
|
|
|
|
+ private MagicWebSocketInstance magicWebSocketInstance;
|
|
|
|
+
|
|
public ChatController(Bundle args) {
|
|
public ChatController(Bundle args) {
|
|
super(args);
|
|
super(args);
|
|
setHasOptionsMenu(true);
|
|
setHasOptionsMenu(true);
|
|
@@ -437,6 +443,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
private void checkReadOnlyState() {
|
|
private void checkReadOnlyState() {
|
|
if (currentConversation != null && !readOnlyCheckPerformed) {
|
|
if (currentConversation != null && !readOnlyCheckPerformed) {
|
|
|
|
|
|
@@ -561,6 +568,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
|
|
|
|
if (inChat) {
|
|
if (inChat) {
|
|
if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) {
|
|
if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) {
|
|
|
|
+ currentCall = null;
|
|
wasDetached = false;
|
|
wasDetached = false;
|
|
joinRoomWithPassword();
|
|
joinRoomWithPassword();
|
|
}
|
|
}
|
|
@@ -570,7 +578,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
private void cancelNotificationsForCurrentConversation() {
|
|
private void cancelNotificationsForCurrentConversation() {
|
|
if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
|
|
if (!conversationUser.hasSpreedFeatureCapability("no-ping") && !TextUtils.isEmpty(roomId)) {
|
|
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomId);
|
|
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomId);
|
|
- } else if (!TextUtils.isEmpty(roomToken)){
|
|
|
|
|
|
+ } else if (!TextUtils.isEmpty(roomToken)) {
|
|
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomToken);
|
|
NotificationUtils.cancelExistingNotificationsForRoom(getApplicationContext(), conversationUser, roomToken);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -679,6 +687,11 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
pullChatMessages(1);
|
|
pullChatMessages(1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ setupWebsocket();
|
|
|
|
+ if (magicWebSocketInstance != null) {
|
|
|
|
+ magicWebSocketInstance.joinRoomWithRoomTokenAndSession(roomToken,
|
|
|
|
+ currentCall.getSessionId());
|
|
|
|
+ }
|
|
if (startCallFromNotification != null && startCallFromNotification) {
|
|
if (startCallFromNotification != null && startCallFromNotification) {
|
|
startCallFromNotification = false;
|
|
startCallFromNotification = false;
|
|
startACall(voiceOnly);
|
|
startACall(voiceOnly);
|
|
@@ -698,6 +711,10 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
} else {
|
|
} else {
|
|
inChat = true;
|
|
inChat = true;
|
|
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
|
|
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
|
|
|
|
+ if (magicWebSocketInstance != null) {
|
|
|
|
+ magicWebSocketInstance.joinRoomWithRoomTokenAndSession(roomToken,
|
|
|
|
+ currentCall.getSessionId());
|
|
|
|
+ }
|
|
startPing();
|
|
startPing();
|
|
if (isFirstMessagesProcessing) {
|
|
if (isFirstMessagesProcessing) {
|
|
pullChatMessages(0);
|
|
pullChatMessages(0);
|
|
@@ -813,21 +830,37 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void setupWebsocket() {
|
|
|
|
+ if (WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.getId()) != null) {
|
|
|
|
+ magicWebSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.getId());
|
|
|
|
+ } else {
|
|
|
|
+ magicWebSocketInstance = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void pullChatMessages(int lookIntoFuture) {
|
|
private void pullChatMessages(int lookIntoFuture) {
|
|
if (!inChat) {
|
|
if (!inChat) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!lookingIntoFuture && lookIntoFuture == 1) {
|
|
|
|
|
|
+ if (lookIntoFuture == 1 && magicWebSocketInstance != null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!lookingIntoFuture && lookIntoFuture > 0) {
|
|
lookingIntoFuture = true;
|
|
lookingIntoFuture = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (lookIntoFuture > 1) {
|
|
|
|
+ lookIntoFuture = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
Map<String, Integer> fieldMap = new HashMap<>();
|
|
Map<String, Integer> fieldMap = new HashMap<>();
|
|
fieldMap.put("lookIntoFuture", lookIntoFuture);
|
|
fieldMap.put("lookIntoFuture", lookIntoFuture);
|
|
fieldMap.put("limit", 25);
|
|
fieldMap.put("limit", 25);
|
|
|
|
|
|
int lastKnown;
|
|
int lastKnown;
|
|
- if (lookIntoFuture == 1) {
|
|
|
|
|
|
+ if (lookIntoFuture > 0) {
|
|
lastKnown = globalLastKnownFutureMessageId;
|
|
lastKnown = globalLastKnownFutureMessageId;
|
|
} else {
|
|
} else {
|
|
lastKnown = globalLastKnownPastMessageId;
|
|
lastKnown = globalLastKnownPastMessageId;
|
|
@@ -838,7 +871,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
}
|
|
}
|
|
|
|
|
|
if (!wasDetached) {
|
|
if (!wasDetached) {
|
|
- if (lookIntoFuture == 1) {
|
|
|
|
|
|
+ if (lookIntoFuture > 0) {
|
|
ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(),
|
|
ncApi.pullChatMessages(credentials, ApiUtils.getUrlForChat(conversationUser.getBaseUrl(),
|
|
roomToken),
|
|
roomToken),
|
|
fieldMap)
|
|
fieldMap)
|
|
@@ -1157,6 +1190,19 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
|
|
+ public void onMessageEvent(WebSocketCommunicationEvent webSocketCommunicationEvent) {
|
|
|
|
+ switch (webSocketCommunicationEvent.getType()) {
|
|
|
|
+ case "refreshChat":
|
|
|
|
+ if (webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_INTERNAL_USER_ID).equals(Long.toString(conversationUser.getId()))) {
|
|
|
|
+ if (roomToken.equals(webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_ROOM_TOKEN))) {
|
|
|
|
+ pullChatMessages(2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
|
public void onMessageEvent(UserMentionClickEvent userMentionClickEvent) {
|
|
public void onMessageEvent(UserMentionClickEvent userMentionClickEvent) {
|