Start chat from push

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-05-28 16:34:36 +02:00
parent c24ee9e910
commit 62cf45778e
2 changed files with 50 additions and 43 deletions

View File

@ -188,6 +188,13 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, ""); this.roomPassword = args.getString(BundleKeys.KEY_CONVERSATION_PASSWORD, "");
if (conversationUser.getUserId().equals("-1")) {
credentials = null;
} else {
credentials = ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken());
}
this.startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL); this.startCallFromNotification = args.getBoolean(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL);
} }
@ -325,7 +332,7 @@ public class ChatController extends BaseController implements MessagesListAdapte
if (adapterWasNull && startCallFromNotification == null) { if (adapterWasNull && startCallFromNotification == null) {
setupMentionAutocomplete(); setupMentionAutocomplete();
joinRoomWithPassword(); joinRoomWithPassword();
} else if (adapterWasNull) { } else {
handleFromNotification(); handleFromNotification();
} }
} }
@ -396,21 +403,39 @@ public class ChatController extends BaseController implements MessagesListAdapte
} }
} }
private void startPing() {
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
.takeWhile(observable -> inChat)
.retry(3, observable -> inChat)
.subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
disposableList.add(d);
}
@Override
public void onNext(GenericOverall genericOverall) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
private void joinRoomWithPassword() { private void joinRoomWithPassword() {
String password = "";
if (!TextUtils.isEmpty(roomPassword)) {
password = roomPassword;
}
if (conversationUser.getUserId().equals("-1")) {
credentials = null;
} else {
credentials = ApiUtils.getCredentials(conversationUser.getUserId(), conversationUser.getToken());
}
if (currentCall == null) { if (currentCall == null) {
ncApi.joinRoom(credentials, ApiUtils.getUrlForRoomParticipants(baseUrl, roomToken), password) ncApi.joinRoom(credentials, ApiUtils.getUrlForRoomParticipants(baseUrl, roomToken), roomPassword)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.retry(3) .retry(3)
@ -501,35 +526,6 @@ public class ChatController extends BaseController implements MessagesListAdapte
}); });
} }
private void startPing() {
ncApi.pingCall(credentials, ApiUtils.getUrlForCallPing(baseUrl, roomToken))
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.repeatWhen(observable -> observable.delay(5000, TimeUnit.MILLISECONDS))
.takeWhile(observable -> inChat)
.retry(3, observable -> inChat)
.subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
disposableList.add(d);
}
@Override
public void onNext(GenericOverall genericOverall) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
private void pullChatMessages(int lookIntoFuture) { private void pullChatMessages(int lookIntoFuture) {
if (!lookingIntoFuture && lookIntoFuture == 1) { if (!lookingIntoFuture && lookIntoFuture == 1) {
lookingIntoFuture = true; lookingIntoFuture = true;

View File

@ -57,6 +57,7 @@ import io.reactivex.schedulers.Schedulers;
import okhttp3.Authenticator; import okhttp3.Authenticator;
import okhttp3.Cache; import okhttp3.Cache;
import okhttp3.Credentials; import okhttp3.Credentials;
import okhttp3.Dispatcher;
import okhttp3.Interceptor; import okhttp3.Interceptor;
import okhttp3.JavaNetCookieJar; import okhttp3.JavaNetCookieJar;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -163,12 +164,21 @@ public class RestModule {
return new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize); return new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize);
} }
@Provides
@Singleton
Dispatcher provideDispatcher() {
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequestsPerHost(100);
dispatcher.setMaxRequests(100);
return dispatcher;
}
@Provides @Provides
@Singleton @Singleton
OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences, OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences,
MagicTrustManager magicTrustManager, MagicTrustManager magicTrustManager,
SSLSocketFactoryCompat sslSocketFactoryCompat, Cache cache, SSLSocketFactoryCompat sslSocketFactoryCompat, Cache cache,
CookieManager cookieManager) { CookieManager cookieManager, Dispatcher dispatcher) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.connectTimeout(45, TimeUnit.SECONDS); httpClient.connectTimeout(45, TimeUnit.SECONDS);
@ -189,6 +199,7 @@ public class RestModule {
httpClient.retryOnConnectionFailure(true); httpClient.retryOnConnectionFailure(true);
httpClient.hostnameVerifier(magicTrustManager.getHostnameVerifier(OkHostnameVerifier.INSTANCE)); httpClient.hostnameVerifier(magicTrustManager.getHostnameVerifier(OkHostnameVerifier.INSTANCE));
httpClient.dispatcher(dispatcher);
if (!Proxy.NO_PROXY.equals(proxy)) { if (!Proxy.NO_PROXY.equals(proxy)) {
httpClient.proxy(proxy); httpClient.proxy(proxy);