diff --git a/web/src/api/types/mxtypes.ts b/web/src/api/types/mxtypes.ts index e576127..5089e7e 100644 --- a/web/src/api/types/mxtypes.ts +++ b/web/src/api/types/mxtypes.ts @@ -116,6 +116,9 @@ export interface PolicyRuleContent { entity: string reason: string recommendation: string + "org.matrix.msc4205.hashes"?: { + sha256: string + } } export interface PowerLevelEventContent { diff --git a/web/src/ui/timeline/content/PolicyRuleBody.tsx b/web/src/ui/timeline/content/PolicyRuleBody.tsx index 8da2217..771a636 100644 --- a/web/src/ui/timeline/content/PolicyRuleBody.tsx +++ b/web/src/ui/timeline/content/PolicyRuleBody.tsx @@ -25,14 +25,21 @@ const PolicyRuleBody = ({ event, sender }: EventContentProps) => { const mainScreen = use(MainScreenContext) const entity = content.entity ?? prevContent?.entity + const hashedEntity = content["org.matrix.msc4205.hashes"]?.sha256 + ?? prevContent?.["org.matrix.msc4205.hashes"]?.sha256 const recommendation = content.recommendation ?? prevContent?.recommendation - if (!entity || !recommendation) { + if ((!entity && !hashedEntity) || !recommendation) { return
{getDisplayname(event.sender, sender?.content)} sent an invalid policy rule
} + const target = event.type.replace(/^m\.policy\.rule\./, "") let entityElement = <>{entity} - if(event.type === "m.policy.rule.user" && !entity?.includes("*") && !entity?.includes("?")) { + let matchingWord = `${target}s matching` + if (!entity && hashedEntity) { + matchingWord = `the ${target} with hash` + entityElement = <>{hashedEntity} + } else if (event.type === "m.policy.rule.user" && entity && !entity.includes("*") && !entity.includes("?")) { entityElement = ( { {entity} ) + matchingWord = "user" } let recommendationElement: JSX.Element | string = {recommendation} if (recommendation === "m.ban") { recommendationElement = "ban" + } else if (recommendation === "org.matrix.msc4204.takedown") { + recommendationElement = "takedown" } const action = prevContent ? ((content.entity && content.recommendation) ? "updated" : "removed") : "added" - const target = event.type.replace(/^m\.policy\.rule\./, "") return
{getDisplayname(event.sender, sender?.content)} {action} a {recommendationElement} rule - for {target}s matching {entityElement} + for {matchingWord} {entityElement} {content.reason ? <> for {content.reason} : null}
}