Split the method to be short *roll eyes*

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

View File

@ -714,62 +714,81 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
} }
} }
if (apiVersion >= ApiUtils.APIv4) { if (participant.type == Participant.ParticipantType.MODERATOR ||
if (participant.type == Participant.ParticipantType.MODERATOR) { participant.type == Participant.ParticipantType.GUEST_MODERATOR) {
ncApi.demoteAttendeeFromModerator( ncApi.demoteAttendeeFromModerator(
credentials, credentials,
ApiUtils.getUrlForRoomModerators( ApiUtils.getUrlForRoomModerators(
apiVersion, apiVersion,
conversationUser!!.baseUrl, conversationUser!!.baseUrl,
conversation!!.token conversation!!.token
), ),
participant.attendeeId participant.attendeeId
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber) .subscribe(subscriber)
} else if (participant.type == Participant.ParticipantType.USER) { } else if (participant.type == Participant.ParticipantType.USER ||
ncApi.promoteAttendeeToModerator( participant.type == Participant.ParticipantType.GUEST) {
credentials, ncApi.promoteAttendeeToModerator(
ApiUtils.getUrlForRoomModerators( credentials,
apiVersion, ApiUtils.getUrlForRoomModerators(
conversationUser!!.baseUrl, apiVersion,
conversation!!.token conversationUser!!.baseUrl,
), conversation!!.token
participant.attendeeId ),
) participant.attendeeId
.subscribeOn(Schedulers.io()) )
.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io())
.subscribe(subscriber) .observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber)
}
}
private fun toggleModeratorStatusLegacy(apiVersion: Int, participant: Participant) {
val subscriber = object : Observer<GenericOverall> {
override fun onSubscribe(d: Disposable) {
} }
} else {
if (participant.type == Participant.ParticipantType.MODERATOR) { override fun onNext(genericOverall: GenericOverall) {
ncApi.demoteModeratorToUser( getListOfParticipants()
credentials,
ApiUtils.getUrlForRoomModerators(
apiVersion,
conversationUser!!.baseUrl,
conversation!!.token
),
participant.userId
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber)
} else if (participant.type == Participant.ParticipantType.USER) {
ncApi.promoteUserToModerator(
credentials,
ApiUtils.getUrlForRoomModerators(
apiVersion,
conversationUser!!.baseUrl,
conversation!!.token
),
participant.userId
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber)
} }
@SuppressLint("LongLogTag")
override fun onError(e: Throwable) {
Log.e(TAG, "Error toggling moderator status", e)
}
override fun onComplete() {
}
}
if (participant.type == Participant.ParticipantType.MODERATOR) {
ncApi.demoteModeratorToUser(
credentials,
ApiUtils.getUrlForRoomModerators(
apiVersion,
conversationUser!!.baseUrl,
conversation!!.token
),
participant.userId
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber)
} else if (participant.type == Participant.ParticipantType.USER) {
ncApi.promoteUserToModerator(
credentials,
ApiUtils.getUrlForRoomModerators(
apiVersion,
conversationUser!!.baseUrl,
conversation!!.token
),
participant.userId
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber)
} }
} }
@ -971,7 +990,11 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
// Pin, nothing to do // Pin, nothing to do
} else if (actionToTrigger == 1) { } else if (actionToTrigger == 1) {
// Promote/demote // Promote/demote
toggleModeratorStatus(apiVersion, participant) if (apiVersion >= ApiUtils.APIv4) {
toggleModeratorStatus(apiVersion, participant)
} else {
toggleModeratorStatusLegacy(apiVersion, participant)
}
} else if (actionToTrigger == 2) { } else if (actionToTrigger == 2) {
// Remove from conversation // Remove from conversation
removeAttendeeFromConversation(apiVersion, participant) removeAttendeeFromConversation(apiVersion, participant)