From ccc4af6aa00987abe7135fa0b7cea97c8cfb3d26 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:51:02 +0000 Subject: [PATCH] Add RoomModeration event. (#91) * Add RoomModeration event. * Add ResetPermissions action. * Add a role property so we can track when a particular power level is involved. --- schemas/RoomModeration.json | 40 +++++++++ types/kotlin/RoomModeration.kt | 23 ++++++ types/kotlin2/RoomModeration.kt | 137 +++++++++++++++++++++++++++++++ types/swift/RoomModeration.swift | 84 +++++++++++++++++++ 4 files changed, 284 insertions(+) create mode 100644 schemas/RoomModeration.json create mode 100644 types/kotlin/RoomModeration.kt create mode 100644 types/kotlin2/RoomModeration.kt create mode 100644 types/swift/RoomModeration.swift diff --git a/schemas/RoomModeration.json b/schemas/RoomModeration.json new file mode 100644 index 0000000..3b03b45 --- /dev/null +++ b/schemas/RoomModeration.json @@ -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 +} diff --git a/types/kotlin/RoomModeration.kt b/types/kotlin/RoomModeration.kt new file mode 100644 index 0000000..d278792 --- /dev/null +++ b/types/kotlin/RoomModeration.kt @@ -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 +} diff --git a/types/kotlin2/RoomModeration.kt b/types/kotlin2/RoomModeration.kt new file mode 100644 index 0000000..7dd03ca --- /dev/null +++ b/types/kotlin2/RoomModeration.kt @@ -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? { + return mutableMapOf().apply { + put("action", action.name) + role?.let { put("role", it.name) } + }.takeIf { it.isNotEmpty() } + } +} diff --git a/types/swift/RoomModeration.swift b/types/swift/RoomModeration.swift new file mode 100644 index 0000000..ed26d9a --- /dev/null +++ b/types/swift/RoomModeration.swift @@ -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 + ] + } + } +}