diff --git a/web/src/ui/MainScreen.tsx b/web/src/ui/MainScreen.tsx index e3220a6..13edde4 100644 --- a/web/src/ui/MainScreen.tsx +++ b/web/src/ui/MainScreen.tsx @@ -217,6 +217,7 @@ class ContextFields implements MainScreenContextFields { } clickRightPanelOpener = (evt: React.MouseEvent) => { + evt.preventDefault() const type = evt.currentTarget.getAttribute("data-target-panel") if (type === "pinned-messages" || type === "members") { this.setRightPanel({ type }) diff --git a/web/src/ui/timeline/content/PolicyRuleBody.tsx b/web/src/ui/timeline/content/PolicyRuleBody.tsx index e1e4430..8da2217 100644 --- a/web/src/ui/timeline/content/PolicyRuleBody.tsx +++ b/web/src/ui/timeline/content/PolicyRuleBody.tsx @@ -13,46 +13,49 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import { use } from "react" +import { JSX, use } from "react" import { PolicyRuleContent } from "@/api/types" -import MainScreenContext from "@/ui/MainScreenContext.ts" +import { getDisplayname } from "@/util/validation.ts" +import MainScreenContext from "../../MainScreenContext.ts" import EventContentProps from "./props.ts" -const BanPolicyBody = ({ event, sender }: EventContentProps) => { +const PolicyRuleBody = ({ event, sender }: EventContentProps) => { const content = event.content as PolicyRuleContent const prevContent = event.unsigned.prev_content as PolicyRuleContent | undefined const mainScreen = use(MainScreenContext) - let entity = {content.entity || prevContent?.entity} - if(event.type === "m.policy.rule.user" && !content.entity?.includes("*") && !content.entity?.includes("?")) { - // Is user policy, and does not include the glob chars * and ? - entity = ( + const entity = content.entity ?? prevContent?.entity + const recommendation = content.recommendation ?? prevContent?.recommendation + if (!entity || !recommendation) { + return
+ {getDisplayname(event.sender, sender?.content)} sent an invalid policy rule +
+ } + let entityElement = <>{entity} + if(event.type === "m.policy.rule.user" && !entity?.includes("*") && !entity?.includes("?")) { + entityElement = ( - {content.entity} + {entity} ) } - - let action = "added" - if (prevContent) { - if (!content) { - // If the content is empty, the ban is revoked. - action = "removed" - } else { - // There is still content, so the policy was updated - action = "updated" - } + let recommendationElement: JSX.Element | string = {recommendation} + if (recommendation === "m.ban") { + recommendationElement = "ban" } + const action = prevContent ? ((content.entity && content.recommendation) ? "updated" : "removed") : "added" + const target = event.type.replace(/^m\.policy\.rule\./, "") return
- {sender?.content.displayname ?? event.sender} {action} a policy - rule {action === "removed" ? "un" : null}banning {entity} for: {content.reason} + {getDisplayname(event.sender, sender?.content)} {action} a {recommendationElement} rule + for {target}s matching {entityElement} + {content.reason ? <> for {content.reason} : null}
} -export default BanPolicyBody +export default PolicyRuleBody