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>
<bytecodeTargetLevel>
<module name="app" target="1.8" />
<module name="talk-android.app" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

View File

@ -4,9 +4,9 @@
<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/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" group="talk-android" />
<module fileurl="file://$PROJECT_DIR$/talk-android.iml" filepath="$PROJECT_DIR$/talk-android.iml" />
<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>
</component>
</project>

View File

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

View File

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

View File

@ -29,7 +29,11 @@ import android.graphics.drawable.ColorDrawable;
import android.media.AudioAttributes;
import android.media.MediaPlayer;
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.text.TextUtils;
import android.util.Log;
@ -39,11 +43,10 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import autodagger.AutoInjector;
import butterknife.BindView;
import butterknife.OnClick;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
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.models.RingtoneSettings;
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.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.DisplayUtils;
import com.nextcloud.talk.utils.DoNotDisturbUtils;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.preferences.AppPreferences;
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.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.michaelevans.colorart.library.ColorArt;
import org.parceler.Parcels;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
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)
public class CallNotificationController extends BaseController {
@ -195,11 +204,10 @@ public class CallNotificationController extends BaseController {
}
private void checkIfAnyParticipantsRemainInRoom() {
ncApi.getPeersForCall(credentials, ApiUtils.getUrlForParticipants(userBeingCalled.getBaseUrl(),
ncApi.getPeersForCall(credentials, ApiUtils.getUrlForCall(userBeingCalled.getBaseUrl(),
currentConversation.getToken()))
.subscribeOn(Schedulers.io())
.takeWhile(observable -> !leavingScreen)
.retry(3)
.subscribe(new Observer<ParticipantsOverall>() {
@Override
public void onSubscribe(Disposable d) {
@ -211,10 +219,10 @@ public class CallNotificationController extends BaseController {
boolean hasParticipantsInCall = false;
boolean inCallOnDifferentDevice = false;
List<Participant> participantList = participantsOverall.getOcs().getData();
for (Participant participant : participantList) {
if (participant.getParticipantFlags() != Participant.ParticipantFlags.NOT_IN_CALL) {
hasParticipantsInCall = true;
hasParticipantsInCall = participantList.size() > 0;
if (hasParticipantsInCall) {
for (Participant participant : participantList) {
if (participant.getUserId().equals(userBeingCalled.getUserId())) {
inCallOnDifferentDevice = true;
break;
@ -237,7 +245,7 @@ public class CallNotificationController extends BaseController {
@Override
public void onComplete() {
if (!leavingScreen) {
checkIfAnyParticipantsRemainInRoom();
handler.postDelayed(() -> checkIfAnyParticipantsRemainInRoom(), 5000);
}
}
});