Deduplicate the subscriber to make the method shorter

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-05-08 14:14:56 +02:00 committed by Andy Scherzinger
parent eba6fe0829
commit 9596e298f2
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -696,7 +696,24 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
} }
} }
fun toggleModeratorStatus(apiVersion: Int, participant: Participant) { private fun toggleModeratorStatus(apiVersion: Int, participant: Participant) {
val subscriber = object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
}
override fun onNext(genericOverall: GenericOverall) {
getListOfParticipants()
}
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error toggling moderator status", e)
}
override fun onComplete() {
}
}
if (apiVersion >= ApiUtils.APIv4) { if (apiVersion >= ApiUtils.APIv4) {
if (participant.type == Participant.ParticipantType.MODERATOR) { if (participant.type == Participant.ParticipantType.MODERATOR) {
ncApi.demoteAttendeeFromModerator( ncApi.demoteAttendeeFromModerator(
@ -710,22 +727,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { .subscribe(subscriber)
override fun onSubscribe(d: Disposable) {
}
override fun onNext(genericOverall: GenericOverall) {
getListOfParticipants()
}
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error demoting an attendee from moderators", e)
}
override fun onComplete() {
}
})
} else if (participant.type == Participant.ParticipantType.USER) { } else if (participant.type == Participant.ParticipantType.USER) {
ncApi.promoteAttendeeToModerator( ncApi.promoteAttendeeToModerator(
credentials, credentials,
@ -738,22 +740,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { .subscribe(subscriber)
override fun onSubscribe(d: Disposable) {
}
override fun onNext(genericOverall: GenericOverall) {
getListOfParticipants()
}
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error promoting an attendee to moderators", e)
}
override fun onComplete() {
}
})
} }
} else { } else {
if (participant.type == Participant.ParticipantType.MODERATOR) { if (participant.type == Participant.ParticipantType.MODERATOR) {
@ -768,22 +755,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { .subscribe(subscriber)
override fun onSubscribe(d: Disposable) {
}
override fun onNext(genericOverall: GenericOverall) {
getListOfParticipants()
}
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error demoting a user from moderators", e)
}
override fun onComplete() {
}
})
} else if (participant.type == Participant.ParticipantType.USER) { } else if (participant.type == Participant.ParticipantType.USER) {
ncApi.promoteUserToModerator( ncApi.promoteUserToModerator(
credentials, credentials,
@ -796,22 +768,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<GenericOverall> { .subscribe(subscriber)
override fun onSubscribe(d: Disposable) {
}
override fun onNext(genericOverall: GenericOverall) {
getListOfParticipants()
}
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error promoting a user to moderators", e)
}
override fun onComplete() {
}
})
} }
} }
} }