mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-28 23:00:45 +00:00
Renderers for UserConsequence UsersInRoom.
This commit is contained in:
@@ -8,10 +8,10 @@
|
||||
// https://github.com/matrix-org/mjolnir
|
||||
// </text>
|
||||
|
||||
import { ActionError, ActionException, ActionResult, DescriptionMeta, MatrixRoomReference, RoomSetResult, StringRoomID, isOk } from "matrix-protection-suite";
|
||||
import { ActionError, ActionException, ActionResult, DescriptionMeta, MatrixRoomReference, ResultForUsersInRoom, RoomSetResult, StringRoomID, StringUserID, isOk } from "matrix-protection-suite";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
import { renderMentionPill, renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
|
||||
export function renderElaborationTrail(error: ActionError): DocumentNode {
|
||||
return <details><summary>Elaboration trail</summary>
|
||||
@@ -68,10 +68,15 @@ export function renderOutcome(isOutcomeOk: boolean): DocumentNode {
|
||||
function renderRoomOutcomeOk(roomID: StringRoomID): DocumentNode {
|
||||
return <span>{renderRoomPill(MatrixRoomReference.fromRoomID(roomID))} - {renderOutcome(true)}</span>
|
||||
}
|
||||
function renderRoomOutcomeError(roomID: StringRoomID, error: ActionError): DocumentNode {
|
||||
|
||||
function renderUserOutcomeOk(userID: StringUserID, result: ActionResult<unknown>): DocumentNode {
|
||||
return <span>{renderMentionPill(userID, userID)} - {renderOutcome(true)}</span>
|
||||
}
|
||||
|
||||
function renderOutcomeError(summary: DocumentNode, error: ActionError): DocumentNode {
|
||||
return <fragment>
|
||||
<details>
|
||||
<summary>{renderRoomPill(MatrixRoomReference.fromRoomID(roomID))} - {renderOutcome(false)}: {error.mostRelevantElaboration}</summary>
|
||||
<summary>{summary}</summary>
|
||||
{renderDetailsNotice(error)}
|
||||
{renderElaborationTrail(error)}
|
||||
{renderExceptionTrail(error)}
|
||||
@@ -79,6 +84,21 @@ function renderRoomOutcomeError(roomID: StringRoomID, error: ActionError): Docum
|
||||
</fragment>
|
||||
}
|
||||
|
||||
function renderRoomOutcomeError(roomID: StringRoomID, error: ActionError): DocumentNode {
|
||||
return renderOutcomeError(
|
||||
<fragment>{renderRoomPill(MatrixRoomReference.fromRoomID(roomID))} - {renderOutcome(false)}: {error.mostRelevantElaboration}</fragment>,
|
||||
error
|
||||
)
|
||||
}
|
||||
|
||||
function renderUserOutcomeError(userID: StringUserID, error: ActionError): DocumentNode {
|
||||
return renderOutcomeError(
|
||||
<fragment>{renderMentionPill(userID, userID)} - {renderOutcome(false)}</fragment>,
|
||||
error
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export function renderRoomOutcome(roomID: StringRoomID, result: ActionResult<unknown>): DocumentNode {
|
||||
if (isOk(result)) {
|
||||
return renderRoomOutcomeOk(roomID);
|
||||
@@ -87,6 +107,14 @@ export function renderRoomOutcome(roomID: StringRoomID, result: ActionResult<unk
|
||||
}
|
||||
}
|
||||
|
||||
export function renderUserOutcome(userID: StringUserID, result: ActionResult<unknown>): DocumentNode {
|
||||
if (isOk(result)) {
|
||||
return renderUserOutcomeOk(userID, result);
|
||||
} else {
|
||||
return renderUserOutcomeError(userID, result.error);
|
||||
}
|
||||
}
|
||||
|
||||
export function renderRoomSetResult(roomResults: RoomSetResult, { summary }: { summary: DocumentNode }): DocumentNode {
|
||||
return <details>
|
||||
<summary>{summary}</summary>
|
||||
@@ -95,3 +123,14 @@ export function renderRoomSetResult(roomResults: RoomSetResult, { summary }: { s
|
||||
})}</ul>
|
||||
</details>
|
||||
}
|
||||
|
||||
export function renderResultForUsersInRoom(results: ResultForUsersInRoom, { summary }: { summary: DocumentNode}): DocumentNode {
|
||||
return <details>
|
||||
<summary>{summary}</summary>
|
||||
<ul>
|
||||
{[...results.map.entries()].map(([userID, outcome]) => {
|
||||
<li>{renderUserOutcome(userID, outcome)}</li>
|
||||
})}
|
||||
</ul>
|
||||
</details>
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class StandardServerConsequencesRenderer implements ServerConsequences {
|
||||
public readonly requiredEventPermissions = this.capability.requiredEventPermissions;
|
||||
public readonly requiredPermissions = this.capability.requiredPermissions;
|
||||
public readonly requiredStatePermissions = this.capability.requiredStatePermissions;
|
||||
public async consequenceForServerInRoom(roomID: StringRoomID, revision: PolicyListRevision): Promise<ActionResult<void>> {
|
||||
const capabilityResult = await this.capability.consequenceForServerInRoom(roomID, revision);
|
||||
public async consequenceForServersInRoom(roomID: StringRoomID, revision: PolicyListRevision): Promise<ActionResult<void>> {
|
||||
const capabilityResult = await this.capability.consequenceForServersInRoom(roomID, revision);
|
||||
const title = <fragment>
|
||||
Setting server ACL in {Permalinks.forRoom(roomID)} as it is out of sync with watched policies.
|
||||
</fragment>;
|
||||
@@ -37,8 +37,8 @@ class StandardServerConsequencesRenderer implements ServerConsequences {
|
||||
this.messageCollector.addOneliner(this.description, title);
|
||||
return Ok(undefined);
|
||||
}
|
||||
public async consequenceForServerInRoomSet(revision: PolicyListRevision): Promise<ActionResult<RoomSetResult>> {
|
||||
const capabilityResult = await this.capability.consequenceForServerInRoomSet(revision);
|
||||
public async consequenceForServersInRoomSet(revision: PolicyListRevision): Promise<ActionResult<RoomSetResult>> {
|
||||
const capabilityResult = await this.capability.consequenceForServersInRoomSet(revision);
|
||||
const title = <fragment>Updating server ACL in protected rooms.</fragment>;
|
||||
if (isError(capabilityResult)) {
|
||||
this.messageCollector.addMessage(this.description, renderFailedSingularConsequence(this.description, title, capabilityResult.error))
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
// </text>
|
||||
|
||||
import { JSXFactory } from "../commands/interface-manager/JSXFactory";
|
||||
import { ActionResult, Capability, DescriptionMeta, Ok, Permalinks, PolicyListRevision, ResultForUsersInSet, RoomSetResult, StandardUserConsequencesContext, StringRoomID, StringUserID, UserConsequences, describeCapabilityContextGlue, describeCapabilityRenderer, isError } from "matrix-protection-suite";
|
||||
import { ActionResult, Capability, DescriptionMeta, MatrixRoomReference, Ok, Permalinks, PolicyListRevision, ResultForUsersInRoom, ResultForUsersInSet, RoomSetResult, StandardUserConsequencesContext, StringRoomID, StringUserID, UserConsequences, describeCapabilityContextGlue, describeCapabilityRenderer, isError } from "matrix-protection-suite";
|
||||
import { RendererMessageCollector } from "./RendererMessageCollector";
|
||||
import { renderFailedSingularConsequence, renderOutcome, renderRoomSetResult } from "./CommonRenderers";
|
||||
import { renderFailedSingularConsequence, renderOutcome, renderResultForUsersInRoom, renderRoomSetResult } from "./CommonRenderers";
|
||||
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
|
||||
|
||||
// yeah i know this is a bit insane but whatever, it can be our secret.
|
||||
function renderResultForUserInSetMap(usersInSetMap: ResultForUsersInSet, {
|
||||
@@ -54,7 +55,6 @@ function renderRoomSetResultForUser(
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class StandardUserConsequencesRenderer implements UserConsequences {
|
||||
constructor(
|
||||
private readonly description: DescriptionMeta,
|
||||
@@ -80,8 +80,8 @@ class StandardUserConsequencesRenderer implements UserConsequences {
|
||||
return Ok(undefined);
|
||||
|
||||
}
|
||||
public async consequenceForUserInRoomSet(revision: PolicyListRevision): Promise<ActionResult<ResultForUsersInSet>> {
|
||||
const capabilityResult = await this.capability.consequenceForUserInRoomSet(revision);
|
||||
public async consequenceForUsersInRoomSet(revision: PolicyListRevision): Promise<ActionResult<ResultForUsersInSet>> {
|
||||
const capabilityResult = await this.capability.consequenceForUsersInRoomSet(revision);
|
||||
if (isError(capabilityResult)) {
|
||||
const title = <fragment>Applying policy revision to protected rooms</fragment>
|
||||
this.messageCollector.addMessage(this.description, renderFailedSingularConsequence(this.description, title, capabilityResult.error))
|
||||
@@ -99,6 +99,28 @@ class StandardUserConsequencesRenderer implements UserConsequences {
|
||||
return capabilityResult;
|
||||
|
||||
}
|
||||
public async consequenceForUsersInRoom(roomID: StringRoomID, revision: PolicyListRevision): Promise<ActionResult<ResultForUsersInRoom>> {
|
||||
const capabilityResult = await this.capability.consequenceForUsersInRoom(roomID, revision);
|
||||
if (isError(capabilityResult)) {
|
||||
const title = <fragment>Applying policy revision to {renderRoomPill(MatrixRoomReference.fromRoomID(roomID, []))}</fragment>
|
||||
this.messageCollector.addMessage(this.description, renderFailedSingularConsequence(this.description, title, capabilityResult.error));
|
||||
return capabilityResult;
|
||||
}
|
||||
const resultMap = capabilityResult.ok;
|
||||
if (resultMap.map.size === 0) {
|
||||
return capabilityResult;
|
||||
}
|
||||
this.messageCollector.addMessage(this.description, renderResultForUsersInRoom(resultMap,
|
||||
{
|
||||
summary: <fragment>
|
||||
{this.description === undefined ? '' : <fragment><code>{this.description.name}</code>:</fragment>}
|
||||
{resultMap.map.size} will be banned from {renderRoomPill(MatrixRoomReference.fromRoomID(roomID))} -  
|
||||
{renderOutcome(resultMap.isEveryResultOk)}.
|
||||
</fragment>
|
||||
}
|
||||
));
|
||||
return capabilityResult;
|
||||
}
|
||||
public async unbanUserFromRoomSet(userID: StringUserID, reason: string): Promise<ActionResult<RoomSetResult>> {
|
||||
const capabilityResult = await this.capability.unbanUserFromRoomSet(userID, reason);
|
||||
if (isError(capabilityResult)) {
|
||||
|
||||
Reference in New Issue
Block a user