Bug fixes related to guest account

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-09-26 13:29:00 +02:00
parent 74f5616392
commit c1f9dd2ac5
7 changed files with 55 additions and 183 deletions

View File

@ -21,7 +21,6 @@
package com.nextcloud.talk.api;
import androidx.annotation.Nullable;
import com.nextcloud.talk.models.json.call.CallOverall;
import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
import com.nextcloud.talk.models.json.chat.ChatOverall;
import com.nextcloud.talk.models.json.generic.GenericOverall;
@ -153,8 +152,7 @@ public interface NcApi {
@FormUrlEncoded
@POST
Observable<CallOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url,
@Nullable @Field("password") String password);
Observable<RoomOverall> joinRoom(@Nullable @Header("Authorization") String authorization, @Url String url, @Nullable @Field("password") String password);
@DELETE
Observable<GenericOverall> leaveRoom(@Nullable @Header("Authorization") String authorization, @Url String url);

View File

@ -58,8 +58,8 @@ import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.*;
import com.nextcloud.talk.models.ExternalSignalingServer;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.call.CallOverall;
import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
import com.nextcloud.talk.models.json.conversations.RoomOverall;
import com.nextcloud.talk.models.json.generic.GenericOverall;
import com.nextcloud.talk.models.json.participants.Participant;
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
@ -1026,15 +1026,15 @@ public class CallController extends BaseController {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(3)
.subscribe(new Observer<CallOverall>() {
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(CallOverall callOverall) {
callSession = callOverall.getOcs().getData().getSessionId();
public void onNext(RoomOverall roomOverall) {
callSession = roomOverall.getOcs().getData().getSessionId();
ApplicationWideCurrentRoomHolder.getInstance().setSession(callSession);
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(roomId);
ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomToken(roomToken);

View File

@ -85,8 +85,6 @@ import com.nextcloud.talk.events.UserMentionClickEvent;
import com.nextcloud.talk.events.WebSocketCommunicationEvent;
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.call.Call;
import com.nextcloud.talk.models.json.call.CallOverall;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.models.json.chat.ChatOverall;
import com.nextcloud.talk.models.json.conversations.Conversation;
@ -188,14 +186,12 @@ public class ChatController extends BaseController implements MessagesListAdapte
@BindView(R.id.lobby_text_view)
TextView conversationLobbyText;
private List<Disposable> disposableList = new ArrayList<>();
private String conversationName;
private String roomToken;
private UserEntity conversationUser;
private String roomPassword;
private String credentials;
private Conversation currentConversation;
private Call currentCall;
private boolean inChat = false;
private boolean inConversation = false;
private boolean historyRead = false;
private int globalLastKnownFutureMessageId = -1;
private int globalLastKnownPastMessageId = -1;
@ -223,6 +219,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
private MagicWebSocketInstance magicWebSocketInstance;
private Handler lobbyTimerHandler;
private boolean roomJoined;
public ChatController(Bundle args) {
super(args);
@ -235,9 +232,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (args.containsKey(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION())) {
this.currentConversation = Parcels.unwrap(args.getParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION()));
if (currentConversation != null) {
conversationName = currentConversation.getDisplayName();
}
}
this.roomPassword = args.getString(BundleKeys.INSTANCE.getKEY_CONVERSATION_PASSWORD(), "");
@ -272,24 +266,16 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onNext(RoomOverall roomOverall) {
Conversation oldConversation = null;
if (currentConversation != null) {
oldConversation = currentConversation;
}
currentConversation = roomOverall.getOcs().getData();
loadAvatarForStatusBar();
conversationName = currentConversation.getDisplayName();
setTitle();
setupMentionAutocomplete();
checkReadOnlyState();
checkLobbyState();
if (oldConversation == null || oldConversation.getRoomId() == null) {
if (!inConversation) {
joinRoomWithPassword();
}
@ -329,19 +315,11 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (roomId.equals(conversation.getRoomId())) {
roomToken = conversation.getToken();
currentConversation = conversation;
loadAvatarForStatusBar();
checkLobbyState();
checkReadOnlyState();
conversationName = conversation.getDisplayName();
setTitle();
getRoomInfo();
break;
}
}
if (!TextUtils.isEmpty(roomToken)) {
setupMentionAutocomplete();
joinRoomWithPassword();
}
}
@Override
@ -531,17 +509,15 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (currentConversation != null && currentConversation.getRoomId() != null) {
loadAvatarForStatusBar();
checkLobbyState();
setTitle();
}
if (adapterWasNull) {
// we're starting
if (TextUtils.isEmpty(roomToken)) {
handleFromNotification();
} else if (TextUtils.isEmpty(conversationName)) {
getRoomInfo();
} else {
setupMentionAutocomplete();
joinRoomWithPassword();
getRoomInfo();
}
}
}
@ -696,9 +672,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
cancelNotificationsForCurrentConversation();
if (inChat) {
if (inConversation) {
if (wasDetached && conversationUser.hasSpreedFeatureCapability("no-ping")) {
currentCall = null;
currentConversation.setSessionId("0");
wasDetached = false;
joinRoomWithPassword();
}
@ -736,7 +712,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
protected String getTitle() {
return String.valueOf(EmojiCompat.get().process(conversationName));
return String.valueOf(EmojiCompat.get().process(currentConversation.getDisplayName()));
}
@Override
@ -752,7 +728,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
adapter = null;
inChat = false;
inConversation = false;
}
private void dispose() {
@ -770,8 +746,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
.takeWhile(observable -> inChat)
.retry(3, observable -> inChat)
.takeWhile(observable -> inConversation)
.retry(3, observable -> inConversation)
.subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
@ -801,23 +777,24 @@ public class ChatController extends BaseController implements MessagesListAdapte
private void joinRoomWithPassword() {
if (currentCall == null) {
if (currentConversation == null || TextUtils.isEmpty(currentConversation.getSessionId()) || currentConversation.getSessionId().equals("0")) {
ncApi.joinRoom(credentials,
ApiUtils.getUrlForSettingMyselfAsActiveParticipant(conversationUser.getBaseUrl(), roomToken), roomPassword)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(3)
.subscribe(new Observer<CallOverall>() {
.subscribe(new Observer<RoomOverall>() {
@Override
public void onSubscribe(Disposable d) {
disposableList.add(d);
}
@Override
public void onNext(CallOverall callOverall) {
inChat = true;
currentCall = callOverall.getOcs().getData();
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
public void onNext(RoomOverall roomOverall) {
inConversation = true;
currentConversation = roomOverall.getOcs().getData();
setTitle();
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentConversation.getSessionId());
startPing();
setupWebsocket();
@ -830,8 +807,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
if (magicWebSocketInstance != null) {
magicWebSocketInstance.joinRoomWithRoomTokenAndSession(roomToken,
currentCall.getSessionId());
magicWebSocketInstance.joinRoomWithRoomTokenAndSession(roomToken, currentConversation.getSessionId());
}
if (startCallFromNotification != null && startCallFromNotification) {
startCallFromNotification = false;
@ -850,11 +826,11 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
});
} else {
inChat = true;
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentCall.getSessionId());
inConversation = true;
ApplicationWideCurrentRoomHolder.getInstance().setSession(currentConversation.getSessionId());
if (magicWebSocketInstance != null) {
magicWebSocketInstance.joinRoomWithRoomTokenAndSession(roomToken,
currentCall.getSessionId());
currentConversation.getSessionId());
}
startPing();
if (isFirstMessagesProcessing) {
@ -885,8 +861,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
lobbyTimerHandler.removeCallbacksAndMessages(null);
}
if (magicWebSocketInstance != null && currentCall != null) {
magicWebSocketInstance.joinRoomWithRoomTokenAndSession("", currentCall.getSessionId());
if (magicWebSocketInstance != null && currentConversation != null) {
magicWebSocketInstance.joinRoomWithRoomTokenAndSession("", currentConversation.getSessionId());
}
if (!isDestroyed() && !isBeingDestroyed() && !wasDetached) {
@ -992,7 +968,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
private void pullChatMessages(int lookIntoFuture) {
if (!inChat) {
if (!inConversation) {
return;
}
@ -1031,7 +1007,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
fieldMap.put("lastKnownMessageId", lastKnown);
Log.d("MARIO-PUSH", lastKnown + " " + lookIntoFuture);
if (!wasDetached) {
if (lookIntoFuture > 0) {
int finalTimeout = timeout;
@ -1040,7 +1015,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
fieldMap)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.takeWhile(observable -> inChat && !wasDetached)
.takeWhile(observable -> inConversation && !wasDetached)
.subscribe(new Observer<Response>() {
@Override
public void onSubscribe(Disposable d) {
@ -1068,8 +1043,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
ApiUtils.getUrlForChat(conversationUser.getBaseUrl(), roomToken), fieldMap)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(3, observable -> inChat && !wasDetached)
.takeWhile(observable -> inChat && !wasDetached)
.retry(3, observable -> inConversation && !wasDetached)
.takeWhile(observable -> inConversation && !wasDetached)
.subscribe(new Observer<Response>() {
@Override
public void onSubscribe(Disposable d) {
@ -1222,7 +1197,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
}
if (inChat) {
if (inConversation) {
pullChatMessages(1);
}
} else if (response.code() == 304 && !isFromTheFuture) {
@ -1237,7 +1212,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
historyRead = true;
if (!lookingIntoFuture && inChat) {
if (!lookingIntoFuture && inConversation) {
pullChatMessages(1);
}
}
@ -1245,7 +1220,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
@Override
public void onLoadMore(int page, int totalItemsCount) {
if (!historyRead && inChat) {
if (!historyRead && inConversation) {
pullChatMessages(0);
}
}

View File

@ -35,10 +35,10 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import autodagger.AutoInjector;
import butterknife.BindView;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.logansquare.LoganSquare;
@ -50,32 +50,35 @@ import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.events.BottomSheetLockEvent;
import com.nextcloud.talk.models.RetrofitBucket;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.call.Call;
import com.nextcloud.talk.models.json.call.CallOverall;
import com.nextcloud.talk.models.json.capabilities.Capabilities;
import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
import com.nextcloud.talk.models.json.generic.GenericOverall;
import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
import com.nextcloud.talk.models.json.conversations.Conversation;
import com.nextcloud.talk.models.json.conversations.RoomOverall;
import com.nextcloud.talk.models.json.generic.GenericOverall;
import com.nextcloud.talk.models.json.participants.AddParticipantOverall;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.ConductorRemapping;
import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils;
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder;
import org.greenrobot.eventbus.EventBus;
import org.parceler.Parcels;
import java.io.IOException;
import java.util.ArrayList;
import javax.inject.Inject;
import autodagger.AutoInjector;
import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import org.greenrobot.eventbus.EventBus;
import org.parceler.Parcels;
import retrofit2.HttpException;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
@AutoInjector(NextcloudTalkApplication.class)
public class OperationsMenuController extends BaseController {
@ -111,7 +114,6 @@ public class OperationsMenuController extends BaseController {
private String callUrl;
private String baseUrl;
private Call call;
private String conversationToken;
private Disposable disposable;
@ -679,7 +681,7 @@ public class OperationsMenuController extends BaseController {
if (baseUrl != null && !baseUrl.equals(currentUser.getBaseUrl())) {
bundle.putString(BundleKeys.INSTANCE.getKEY_MODIFIED_BASE_URL(), baseUrl);
}
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(call));
bundle.putParcelable(BundleKeys.INSTANCE.getKEY_ACTIVE_CONVERSATION(), Parcels.wrap(conversation));
if (getActivity() != null) {
@ -710,8 +712,8 @@ public class OperationsMenuController extends BaseController {
if (operationCode != 99) {
showResultImage(true, false);
} else {
CallOverall callOverall = (CallOverall) o;
call = callOverall.getOcs().getData();
RoomOverall roomOverall = (RoomOverall) o;
conversation = roomOverall.getOcs().getData();
initiateConversation(true, serverCapabilities);
}
}

View File

@ -1,34 +0,0 @@
/*
*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.call;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import lombok.Data;
import org.parceler.Parcel;
@Parcel
@Data
@JsonObject
public class Call {
@JsonField(name = "sessionId")
String sessionId;
}

View File

@ -1,35 +0,0 @@
/*
*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.call;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.models.json.generic.GenericOCS;
import lombok.Data;
import org.parceler.Parcel;
@Data
@Parcel
@JsonObject
public class CallOCS extends GenericOCS {
@JsonField(name = "data")
Call data;
}

View File

@ -1,34 +0,0 @@
/*
*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.models.json.call;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import lombok.Data;
import org.parceler.Parcel;
@Data
@Parcel
@JsonObject
public class CallOverall {
@JsonField(name = "ocs")
CallOCS ocs;
}