Skip to content

Commit

Permalink
Add RoomModeration event. (#91)
Browse files Browse the repository at this point in the history
* Add RoomModeration event.

* Add ResetPermissions action.

* Add a role property so we can track when a particular power level is involved.
  • Loading branch information
pixlwave authored Mar 14, 2024
1 parent 3875b30 commit ccc4af6
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 0 deletions.
40 changes: 40 additions & 0 deletions schemas/RoomModeration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"type": "object",
"description": "Triggered when a moderation action is performed within a room.",
"properties": {
"eventName": {
"enum": ["RoomModeration"]
},
"action": {
"description": "The action that was performed.",
"type": "string",
"oneOf": [
{"const": "ChangeMemberRole", "description": "Changed a room member's power level."},
{"const": "KickMember", "description": "Kicked a room member."},
{"const": "BanMember", "description": "Banned a room member."},
{"const": "UnbanMember", "description": "Unbanned a room member."},
{"const": "ChangePermissionsRoomName", "description": "Changed the power level required to set the room's name."},
{"const": "ChangePermissionsRoomAvatar", "description": "Changed the power level required to set the room's avatar."},
{"const": "ChangePermissionsRoomTopic", "description": "Changed the power level required to set the room's topic."},
{"const": "ChangePermissionsSendMessages", "description": "Changed the power level required to send messages in the room."},
{"const": "ChangePermissionsRedactMessages", "description": "Changed the power level required to redact messages in the room."},
{"const": "ChangePermissionsInviteUsers", "description": "Changed the power level required to invite users to the room."},
{"const": "ChangePermissionsKickMembers", "description": "Changed the power level required to kick room members."},
{"const": "ChangePermissionsBanMembers", "description": "Changed the power level required to ban room members."},
{"const": "ResetPermissions", "description": "Reset all of the room permissions back to their default values."}
]
},
"role": {
"description": "When the action sets a particular power level, this is the suggested role for that the power level.",
"type": "string",
"oneOf": [
{"const": "Administrator", "description": "A power level of 100."},
{"const": "Moderator", "description": "A power level of 50."},
{"const": "User", "description": "A power level of 0."},
{"const": "Other", "description": "Any other power level."}
]
}
},
"required": ["action", "eventName"],
"additionalProperties": false
}
23 changes: 23 additions & 0 deletions types/kotlin/RoomModeration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package quicktype

/**
* Triggered when a moderation action is performed within a room.
*/
data class RoomModeration (
/**
* The action that was performed.
*/
val action: String,

val eventName: EventName,

/**
* When the action sets a particular power level, this is the suggested role for that the
* power level.
*/
val role: String? = null
)

enum class EventName {
RoomModeration
}
137 changes: 137 additions & 0 deletions types/kotlin2/RoomModeration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package im.vector.app.features.analytics.plan

import im.vector.app.features.analytics.itf.VectorAnalyticsEvent

// GENERATED FILE, DO NOT EDIT. FOR MORE INFORMATION VISIT
// https://github.com/matrix-org/matrix-analytics-events/

/**
* Triggered when a moderation action is performed within a room.
*/
data class RoomModeration(
/**
* The action that was performed.
*/
val action: Action,
/**
* When the action sets a particular power level, this is the suggested
* role for that the power level.
*/
val role: Role? = null,
) : VectorAnalyticsEvent {

enum class Action {
/**
* Banned a room member.
*/
BanMember,

/**
* Changed a room member's power level.
*/
ChangeMemberRole,

/**
* Changed the power level required to ban room members.
*/
ChangePermissionsBanMembers,

/**
* Changed the power level required to invite users to the room.
*/
ChangePermissionsInviteUsers,

/**
* Changed the power level required to kick room members.
*/
ChangePermissionsKickMembers,

/**
* Changed the power level required to redact messages in the room.
*/
ChangePermissionsRedactMessages,

/**
* Changed the power level required to set the room's avatar.
*/
ChangePermissionsRoomAvatar,

/**
* Changed the power level required to set the room's name.
*/
ChangePermissionsRoomName,

/**
* Changed the power level required to set the room's topic.
*/
ChangePermissionsRoomTopic,

/**
* Changed the power level required to send messages in the room.
*/
ChangePermissionsSendMessages,

/**
* Kicked a room member.
*/
KickMember,

/**
* Reset all of the room permissions back to their default values.
*/
ResetPermissions,

/**
* Unbanned a room member.
*/
UnbanMember,
}

enum class Role {

/**
* A power level of 100.
*/
Administrator,

/**
* A power level of 50.
*/
Moderator,

/**
* Any other power level.
*/
Other,

/**
* A power level of 0.
*/
User,
}

override fun getName() = "RoomModeration"

override fun getProperties(): Map<String, Any>? {
return mutableMapOf<String, Any>().apply {
put("action", action.name)
role?.let { put("role", it.name) }
}.takeIf { it.isNotEmpty() }
}
}
84 changes: 84 additions & 0 deletions types/swift/RoomModeration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

// GENERATED FILE, DO NOT EDIT. FOR MORE INFORMATION VISIT
// https://github.com/matrix-org/matrix-analytics-events/

/// Triggered when a moderation action is performed within a room.
extension AnalyticsEvent {
public struct RoomModeration: AnalyticsEventProtocol {
public let eventName = "RoomModeration"

/// The action that was performed.
public let action: Action
/// When the action sets a particular power level, this is the suggested role for that the power level.
public let role: Role?

public init(action: Action, role: Role?) {
self.action = action
self.role = role
}

public enum Action: String {
/// Banned a room member.
case BanMember
/// Changed a room member's power level.
case ChangeMemberRole
/// Changed the power level required to ban room members.
case ChangePermissionsBanMembers
/// Changed the power level required to invite users to the room.
case ChangePermissionsInviteUsers
/// Changed the power level required to kick room members.
case ChangePermissionsKickMembers
/// Changed the power level required to redact messages in the room.
case ChangePermissionsRedactMessages
/// Changed the power level required to set the room's avatar.
case ChangePermissionsRoomAvatar
/// Changed the power level required to set the room's name.
case ChangePermissionsRoomName
/// Changed the power level required to set the room's topic.
case ChangePermissionsRoomTopic
/// Changed the power level required to send messages in the room.
case ChangePermissionsSendMessages
/// Kicked a room member.
case KickMember
/// Reset all of the room permissions back to their default values.
case ResetPermissions
/// Unbanned a room member.
case UnbanMember
}

public enum Role: String {
/// A power level of 100.
case Administrator
/// A power level of 50.
case Moderator
/// Any other power level.
case Other
/// A power level of 0.
case User
}

public var properties: [String: Any] {
return [
"action": action.rawValue,
"role": role?.rawValue as Any
]
}
}
}

0 comments on commit ccc4af6

Please sign in to comment.