mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 12:16:55 +01:00
Mutualize code
This commit is contained in:
parent
30774957ba
commit
cec79fed44
@ -35,4 +35,18 @@ data class PowerLevelsContent(
|
||||
@Json(name = "users") val users: MutableMap<String, Int> = HashMap(),
|
||||
@Json(name = "state_default") val stateDefault: Int = Role.Moderator.value,
|
||||
@Json(name = "notifications") val notifications: Map<String, Any> = HashMap()
|
||||
)
|
||||
) {
|
||||
/**
|
||||
* Alter this content with a new power level for the specified user
|
||||
*
|
||||
* @param userId the userId to alter the power level of
|
||||
* @param powerLevel the new power level, or null to set the default value.
|
||||
*/
|
||||
fun setUserPowerLevel(userId: String, powerLevel: Int?) {
|
||||
if (powerLevel == null || powerLevel == usersDefault) {
|
||||
users.remove(userId)
|
||||
} else {
|
||||
users[userId] = powerLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) {
|
||||
*/
|
||||
fun getUserRole(userId: String): Role {
|
||||
val value = getUserPowerLevelValue(userId)
|
||||
// I think we should use powerLevelsContent.usersDefault, but Ganfra told me that it was like that on riot-Web
|
||||
return Role.fromValue(value, powerLevelsContent.eventsDefault)
|
||||
}
|
||||
|
||||
|
@ -675,12 +675,7 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||
?.toModel<PowerLevelsContent>() ?: return
|
||||
|
||||
launchSlashCommandFlow {
|
||||
if (setUserPowerLevel.powerLevel == null) {
|
||||
currentPowerLevelsContent.users.remove(setUserPowerLevel.userId)
|
||||
} else {
|
||||
currentPowerLevelsContent.users[setUserPowerLevel.userId] = setUserPowerLevel.powerLevel
|
||||
}
|
||||
|
||||
currentPowerLevelsContent.setUserPowerLevel(setUserPowerLevel.userId, setUserPowerLevel.powerLevel)
|
||||
room.sendStateEvent(EventType.STATE_ROOM_POWER_LEVELS, null, currentPowerLevelsContent.toContent(), it)
|
||||
}
|
||||
}
|
||||
|
@ -162,11 +162,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
|
||||
} else if (action.askForValidation && state.isMine) {
|
||||
_viewEvents.post(RoomMemberProfileViewEvents.ShowPowerLevelDemoteWarning(action.previousValue, action.newValue))
|
||||
} else {
|
||||
if (action.newValue == currentPowerLevelsContent.usersDefault) {
|
||||
currentPowerLevelsContent.users.remove(state.userId)
|
||||
} else {
|
||||
currentPowerLevelsContent.users[state.userId] = action.newValue
|
||||
}
|
||||
currentPowerLevelsContent.setUserPowerLevel(state.userId, action.newValue)
|
||||
viewModelScope.launch {
|
||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user