Fix spamming participants

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-04-15 12:02:56 +02:00
parent b14f9990b4
commit ac1bb0ecf7
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
5 changed files with 46 additions and 30 deletions

View File

@ -6,6 +6,7 @@
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="app" target="1.8" /> <module name="app" target="1.8" />
<module name="talk-android.app" target="1.8" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>

View File

@ -4,9 +4,9 @@
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/Projects-talk-android.iml" filepath="$PROJECT_DIR$/.idea/modules/Projects-talk-android.iml" group="talk-android" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/Projects-talk-android.iml" filepath="$PROJECT_DIR$/.idea/modules/Projects-talk-android.iml" group="talk-android" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Projects-talk-android-app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Projects-talk-android-app.iml" group="talk-android/app" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/Projects-talk-android-app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/Projects-talk-android-app.iml" group="talk-android/app" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" group="talk-android/app" /> <module fileurl="file://$PROJECT_DIR$/talk-android.iml" filepath="$PROJECT_DIR$/talk-android.iml" />
<module fileurl="file://$PROJECT_DIR$/talk-android.iml" filepath="$PROJECT_DIR$/talk-android.iml" group="talk-android" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/talk-android-app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/talk-android-app.iml" group="talk-android/app" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/app/talk-android-app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/talk-android-app.iml" group="talk-android/app" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/talk-android.app.iml" filepath="$PROJECT_DIR$/.idea/modules/app/talk-android.app.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -39,8 +39,8 @@ android {
targetSdkVersion 28 targetSdkVersion 28
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode 135 versionCode 136
versionName "8.0.8" versionName "8.0.9"
flavorDimensions "default" flavorDimensions "default"
renderscriptTargetApi 19 renderscriptTargetApi 19

View File

@ -26,6 +26,7 @@ import android.content.Intent
import android.media.AudioAttributes import android.media.AudioAttributes
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.text.TextUtils import android.text.TextUtils
import android.util.Base64 import android.util.Base64
import android.util.Log import android.util.Log
@ -89,6 +90,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
var isServiceInForeground: Boolean = false var isServiceInForeground: Boolean = false
private var decryptedPushMessage: DecryptedPushMessage? = null private var decryptedPushMessage: DecryptedPushMessage? = null
private var signatureVerification: SignatureVerification? = null private var signatureVerification: SignatureVerification? = null
private var handler: Handler = Handler()
@JvmField @JvmField
@Inject @Inject
@ -119,6 +121,7 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
isServiceInForeground = false isServiceInForeground = false
eventBus?.unregister(this) eventBus?.unregister(this)
stopForeground(true) stopForeground(true)
handler.removeCallbacksAndMessages(null)
super.onDestroy() super.onDestroy()
} }
@ -247,8 +250,11 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
var inCallOnDifferentDevice = false var inCallOnDifferentDevice = false
ncApi.getPeersForCall(ApiUtils.getCredentials(signatureVerification.userEntity.username, signatureVerification.userEntity.token), ncApi.getPeersForCall(ApiUtils.getCredentials(signatureVerification.userEntity.username, signatureVerification.userEntity.token),
ApiUtils.getUrlForParticipants(signatureVerification.userEntity.baseUrl, ApiUtils.getUrlForCall(signatureVerification.userEntity.baseUrl,
decryptedPushMessage.id)) decryptedPushMessage.id))
.takeWhile {
isServiceInForeground
}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.subscribe(object : Observer<ParticipantsOverall> { .subscribe(object : Observer<ParticipantsOverall> {
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
@ -256,9 +262,9 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
override fun onNext(participantsOverall: ParticipantsOverall) { override fun onNext(participantsOverall: ParticipantsOverall) {
val participantList: List<Participant> = participantsOverall.ocs.data val participantList: List<Participant> = participantsOverall.ocs.data
for (participant in participantList) { hasParticipantsInCall = participantList.isNotEmpty()
if (participant.participantFlags != Participant.ParticipantFlags.NOT_IN_CALL) { if (!hasParticipantsInCall) {
hasParticipantsInCall = true for (participant in participantList) {
if (participant.userId == signatureVerification.userEntity.userId) { if (participant.userId == signatureVerification.userEntity.userId) {
inCallOnDifferentDevice = true inCallOnDifferentDevice = true
break break
@ -268,8 +274,11 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
if (!hasParticipantsInCall || inCallOnDifferentDevice) { if (!hasParticipantsInCall || inCallOnDifferentDevice) {
stopForeground(true) stopForeground(true)
handler.removeCallbacksAndMessages(null)
} else if (isServiceInForeground) { } else if (isServiceInForeground) {
checkIfCallIsActive(signatureVerification, decryptedPushMessage) handler.postDelayed({
checkIfCallIsActive(signatureVerification, decryptedPushMessage)
}, 5000)
} }
} }
@ -277,7 +286,5 @@ class MagicFirebaseMessagingService : FirebaseMessagingService() {
override fun onComplete() { override fun onComplete() {
} }
}) })
} }
} }

View File

@ -29,7 +29,11 @@ import android.graphics.drawable.ColorDrawable;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.Uri; import android.net.Uri;
import android.os.*; import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.renderscript.RenderScript; import android.renderscript.RenderScript;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -39,11 +43,10 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.OnClick;
import com.bluelinelabs.conductor.RouterTransaction; import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler; import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.logansquare.LoganSquare; import com.bluelinelabs.logansquare.LoganSquare;
@ -65,33 +68,39 @@ import com.nextcloud.talk.events.CallNotificationClick;
import com.nextcloud.talk.events.ConfigurationChangeEvent; import com.nextcloud.talk.events.ConfigurationChangeEvent;
import com.nextcloud.talk.models.RingtoneSettings; import com.nextcloud.talk.models.RingtoneSettings;
import com.nextcloud.talk.models.database.UserEntity; import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.participants.Participant;
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
import com.nextcloud.talk.models.json.conversations.Conversation; import com.nextcloud.talk.models.json.conversations.Conversation;
import com.nextcloud.talk.models.json.conversations.RoomsOverall; import com.nextcloud.talk.models.json.conversations.RoomsOverall;
import com.nextcloud.talk.models.json.participants.Participant;
import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
import com.nextcloud.talk.utils.ApiUtils; import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.DisplayUtils; import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.DoNotDisturbUtils; import com.nextcloud.talk.utils.DoNotDisturbUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys; import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.preferences.AppPreferences; import com.nextcloud.talk.utils.preferences.AppPreferences;
import com.nextcloud.talk.utils.singletons.AvatarStatusCodeHolder; import com.nextcloud.talk.utils.singletons.AvatarStatusCodeHolder;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Cache;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import org.michaelevans.colorart.library.ColorArt; import org.michaelevans.colorart.library.ColorArt;
import org.parceler.Parcels; import org.parceler.Parcels;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.annotation.Nullable;
import javax.inject.Inject;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Cache;
@AutoInjector(NextcloudTalkApplication.class) @AutoInjector(NextcloudTalkApplication.class)
public class CallNotificationController extends BaseController { public class CallNotificationController extends BaseController {
@ -195,11 +204,10 @@ public class CallNotificationController extends BaseController {
} }
private void checkIfAnyParticipantsRemainInRoom() { private void checkIfAnyParticipantsRemainInRoom() {
ncApi.getPeersForCall(credentials, ApiUtils.getUrlForParticipants(userBeingCalled.getBaseUrl(), ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(userBeingCalled.getBaseUrl(),
currentConversation.getToken())) currentConversation.getToken()))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.takeWhile(observable -> !leavingScreen) .takeWhile(observable -> !leavingScreen)
.retry(3)
.subscribe(new Observer<ParticipantsOverall>() { .subscribe(new Observer<ParticipantsOverall>() {
@Override @Override
public void onSubscribe(Disposable d) { public void onSubscribe(Disposable d) {
@ -211,10 +219,10 @@ public class CallNotificationController extends BaseController {
boolean hasParticipantsInCall = false; boolean hasParticipantsInCall = false;
boolean inCallOnDifferentDevice = false; boolean inCallOnDifferentDevice = false;
List<Participant> participantList = participantsOverall.getOcs().getData(); List<Participant> participantList = participantsOverall.getOcs().getData();
for (Participant participant : participantList) { hasParticipantsInCall = participantList.size() > 0;
if (participant.getParticipantFlags() != Participant.ParticipantFlags.NOT_IN_CALL) {
hasParticipantsInCall = true;
if (hasParticipantsInCall) {
for (Participant participant : participantList) {
if (participant.getUserId().equals(userBeingCalled.getUserId())) { if (participant.getUserId().equals(userBeingCalled.getUserId())) {
inCallOnDifferentDevice = true; inCallOnDifferentDevice = true;
break; break;
@ -237,7 +245,7 @@ public class CallNotificationController extends BaseController {
@Override @Override
public void onComplete() { public void onComplete() {
if (!leavingScreen) { if (!leavingScreen) {
checkIfAnyParticipantsRemainInRoom(); handler.postDelayed(() -> checkIfAnyParticipantsRemainInRoom(), 5000);
} }
} }
}); });