mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +01:00
Fix available actions for groups, owners and self-joined users
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
596772c5c6
commit
4ad96cc347
@ -700,46 +700,14 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(view: View?, position: Int): Boolean {
|
fun toggleModeratorStatus(apiVersion: Int, participant: Participant) {
|
||||||
val userItem = adapter?.getItem(position) as UserItem
|
|
||||||
val participant = userItem.model
|
|
||||||
|
|
||||||
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
|
||||||
|
|
||||||
if (participant.userId != conversationUser!!.userId) {
|
|
||||||
var items = mutableListOf(
|
|
||||||
BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_promote)),
|
|
||||||
BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_demote)),
|
|
||||||
BasicListItemWithImage(
|
|
||||||
R.drawable.ic_delete_grey600_24dp,
|
|
||||||
context.getString(R.string.nc_remove_participant)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!conversation!!.canModerate(conversationUser)) {
|
|
||||||
items = mutableListOf()
|
|
||||||
} else {
|
|
||||||
if (participant.type == Participant.ParticipantType.MODERATOR || participant.type == Participant.ParticipantType.OWNER) {
|
|
||||||
items.removeAt(0)
|
|
||||||
} else if (participant.type == Participant.ParticipantType.USER) {
|
|
||||||
items.removeAt(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items.isNotEmpty()) {
|
|
||||||
MaterialDialog(activity!!, BottomSheet(WRAP_CONTENT)).show {
|
|
||||||
cornerRadius(res = R.dimen.corner_radius)
|
|
||||||
|
|
||||||
title(text = participant.displayName)
|
|
||||||
listItemsWithImage(items = items) { dialog, index, _ ->
|
|
||||||
if (index == 0) {
|
|
||||||
if (apiVersion >= ApiUtils.APIv4) {
|
if (apiVersion >= ApiUtils.APIv4) {
|
||||||
if (participant.type == Participant.ParticipantType.MODERATOR) {
|
if (participant.type == Participant.ParticipantType.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
|
||||||
@ -767,7 +735,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRoomModerators(
|
ApiUtils.getUrlForRoomModerators(
|
||||||
apiVersion,
|
apiVersion,
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token
|
conversation!!.token
|
||||||
),
|
),
|
||||||
participant.attendeeId
|
participant.attendeeId
|
||||||
@ -797,40 +765,68 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRoomModerators(
|
ApiUtils.getUrlForRoomModerators(
|
||||||
apiVersion,
|
apiVersion,
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token
|
conversation!!.token
|
||||||
),
|
),
|
||||||
participant.userId
|
participant.userId
|
||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe {
|
.subscribe(object : Observer<GenericOverall> {
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(genericOverall: GenericOverall) {
|
||||||
getListOfParticipants()
|
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,
|
||||||
ApiUtils.getUrlForRoomModerators(
|
ApiUtils.getUrlForRoomModerators(
|
||||||
apiVersion,
|
apiVersion,
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token
|
conversation!!.token
|
||||||
),
|
),
|
||||||
participant.userId
|
participant.userId
|
||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe {
|
.subscribe(object : Observer<GenericOverall> {
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(genericOverall: GenericOverall) {
|
||||||
getListOfParticipants()
|
getListOfParticipants()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("LongLogTag")
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.e(TAG, "Error promoting a user to moderators", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onComplete() {
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (index == 1) {
|
}
|
||||||
|
|
||||||
|
fun removeAttendeeFromConversation(apiVersion: Int, participant: Participant) {
|
||||||
if (apiVersion >= ApiUtils.APIv4) {
|
if (apiVersion >= ApiUtils.APIv4) {
|
||||||
ncApi.removeAttendeeFromConversation(
|
ncApi.removeAttendeeFromConversation(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForAttendees(
|
ApiUtils.getUrlForAttendees(
|
||||||
apiVersion,
|
apiVersion,
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token
|
conversation!!.token
|
||||||
),
|
),
|
||||||
participant.attendeeId
|
participant.attendeeId
|
||||||
@ -860,7 +856,7 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
ncApi.removeParticipantFromConversation(
|
ncApi.removeParticipantFromConversation(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRemovingParticipantFromConversation(
|
ApiUtils.getUrlForRemovingParticipantFromConversation(
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token,
|
conversation!!.token,
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
@ -868,14 +864,27 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe {
|
.subscribe(object : Observer<GenericOverall> {
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(genericOverall: GenericOverall) {
|
||||||
getListOfParticipants()
|
getListOfParticipants()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("LongLogTag")
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.e(TAG, "Error removing guest from conversation", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onComplete() {
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
ncApi.removeParticipantFromConversation(
|
ncApi.removeParticipantFromConversation(
|
||||||
credentials,
|
credentials,
|
||||||
ApiUtils.getUrlForRemovingParticipantFromConversation(
|
ApiUtils.getUrlForRemovingParticipantFromConversation(
|
||||||
conversationUser.baseUrl,
|
conversationUser!!.baseUrl,
|
||||||
conversation!!.token,
|
conversation!!.token,
|
||||||
false
|
false
|
||||||
),
|
),
|
||||||
@ -883,18 +892,101 @@ class ConversationInfoController(args: Bundle) : BaseController(args), FlexibleA
|
|||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe {
|
.subscribe(object : Observer<GenericOverall> {
|
||||||
|
override fun onSubscribe(d: Disposable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNext(genericOverall: GenericOverall) {
|
||||||
getListOfParticipants()
|
getListOfParticipants()
|
||||||
// get participants again
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("LongLogTag")
|
||||||
|
override fun onError(e: Throwable) {
|
||||||
|
Log.e(TAG, "Error removing user from conversation", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onComplete() {
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onItemClick(view: View?, position: Int): Boolean {
|
||||||
|
if (!conversation!!.canModerate(conversationUser)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val userItem = adapter?.getItem(position) as UserItem
|
||||||
|
val participant = userItem.model
|
||||||
|
|
||||||
|
val apiVersion = ApiUtils.getConversationApiVersion(conversationUser, intArrayOf(ApiUtils.APIv4, 1))
|
||||||
|
|
||||||
|
if (participant.getUserId() == conversationUser!!.userId
|
||||||
|
|| participant.type == Participant.ParticipantType.OWNER) {
|
||||||
|
// FIXME Show pin?
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (participant.getActorType() == GROUPS) {
|
||||||
|
val items = mutableListOf(
|
||||||
|
BasicListItemWithImage(
|
||||||
|
R.drawable.ic_delete_grey600_24dp,
|
||||||
|
context.getString(R.string.nc_remove_group_and_members)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
MaterialDialog(activity!!, BottomSheet(WRAP_CONTENT)).show {
|
||||||
|
cornerRadius(res = R.dimen.corner_radius)
|
||||||
|
|
||||||
|
title(text = participant.displayName)
|
||||||
|
listItemsWithImage(items = items) { dialog, index, _ ->
|
||||||
|
if (index == 0) {
|
||||||
|
removeAttendeeFromConversation(apiVersion, participant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var items = mutableListOf(
|
||||||
|
BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_promote)),
|
||||||
|
BasicListItemWithImage(R.drawable.ic_pencil_grey600_24dp, context.getString(R.string.nc_demote)),
|
||||||
|
BasicListItemWithImage(
|
||||||
|
R.drawable.ic_delete_grey600_24dp,
|
||||||
|
context.getString(R.string.nc_remove_participant)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (participant.type == Participant.ParticipantType.MODERATOR
|
||||||
|
|| participant.type == Participant.ParticipantType.GUEST_MODERATOR) {
|
||||||
|
items.removeAt(0)
|
||||||
|
} else if (participant.type == Participant.ParticipantType.USER
|
||||||
|
|| participant.type == Participant.ParticipantType.GUEST) {
|
||||||
|
items.removeAt(1)
|
||||||
|
} else {
|
||||||
|
// Self joined users can not be promoted nor demoted
|
||||||
|
items.removeAt(0)
|
||||||
|
items.removeAt(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items.isNotEmpty()) {
|
||||||
|
MaterialDialog(activity!!, BottomSheet(WRAP_CONTENT)).show {
|
||||||
|
cornerRadius(res = R.dimen.corner_radius)
|
||||||
|
|
||||||
|
title(text = participant.displayName)
|
||||||
|
listItemsWithImage(items = items) { dialog, index, _ ->
|
||||||
|
if (index == 0) {
|
||||||
|
if (participant.type == Participant.ParticipantType.USER_FOLLOWING_LINK) {
|
||||||
|
removeAttendeeFromConversation(apiVersion, participant)
|
||||||
|
} else {
|
||||||
|
toggleModeratorStatus(apiVersion, participant)
|
||||||
|
}
|
||||||
|
} else if (index == 1) {
|
||||||
|
removeAttendeeFromConversation(apiVersion, participant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +255,7 @@
|
|||||||
<string name="nc_demote">Demote from moderator</string>
|
<string name="nc_demote">Demote from moderator</string>
|
||||||
<string name="nc_promote">Promote to moderator</string>
|
<string name="nc_promote">Promote to moderator</string>
|
||||||
<string name="nc_remove_participant">Remove participant</string>
|
<string name="nc_remove_participant">Remove participant</string>
|
||||||
|
<string name="nc_remove_group_and_members">Remove group and members</string>
|
||||||
|
|
||||||
<!-- Chat -->
|
<!-- Chat -->
|
||||||
<string name="nc_hint_enter_a_message">Enter a message…</string>
|
<string name="nc_hint_enter_a_message">Enter a message…</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user