mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
unify return + linkify ban target
This commit is contained in:
parent
aab32231a6
commit
b7520e986a
1 changed files with 45 additions and 15 deletions
|
@ -1,27 +1,57 @@
|
||||||
|
// gomuks - A Matrix client written in Go.
|
||||||
|
// Copyright (C) 2024 Tulir Asokan
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
import { use } from "react"
|
||||||
import { PolicyRuleContent } from "@/api/types"
|
import { PolicyRuleContent } from "@/api/types"
|
||||||
|
import MainScreenContext from "@/ui/MainScreenContext.ts"
|
||||||
import EventContentProps from "./props.ts"
|
import EventContentProps from "./props.ts"
|
||||||
|
|
||||||
const BanPolicyBody = ({ event, sender }: EventContentProps) => {
|
const BanPolicyBody = ({ event, sender }: EventContentProps) => {
|
||||||
const content = event.content as PolicyRuleContent
|
const content = event.content as PolicyRuleContent
|
||||||
const prevContent = event.unsigned.prev_content as PolicyRuleContent | undefined
|
const prevContent = event.unsigned.prev_content as PolicyRuleContent | undefined
|
||||||
|
const mainScreen = use(MainScreenContext)
|
||||||
|
|
||||||
if (prevContent !== undefined) {
|
let entity = <span>content.entity || prevContent?.entity</span>
|
||||||
// all fields for content are missing (this is against spec?) so we need to use the prev event's content
|
if(event.type === "m.policy.rule.user" && !content.entity?.includes("*") && !content.entity?.includes("?")) {
|
||||||
if (content.entity === undefined) {
|
// Is user policy, and does not include the glob chars * and ?
|
||||||
// unban
|
entity = (
|
||||||
return <div className="policy-body">
|
<a
|
||||||
{sender?.content.displayname ?? event.sender} Removed the policy rule banning {prevContent.entity}
|
className="hicli-matrix-uri hicli-matrix-uri-user"
|
||||||
</div>
|
href={`matrix:u/${content.entity.slice(1)}`}
|
||||||
}
|
onClick={mainScreen.clickRightPanelOpener}
|
||||||
// update
|
data-target-panel="user"
|
||||||
return <div className="policy-body">
|
data-target-user={content.entity}
|
||||||
{sender?.content.displayname ?? event.sender} Updated a policy rule banning {content.entity} for
|
>
|
||||||
{content.reason}
|
{content.entity}
|
||||||
</div>
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// add
|
|
||||||
return <div className="policy-body">
|
return <div className="policy-body">
|
||||||
{sender?.content.displayname ?? event.sender} Added a policy rule banning {content.entity} for {content.reason}
|
{sender?.content.displayname ?? event.sender} {action} a policy rule
|
||||||
|
{action === "removed" ? "un" : null}banning {entity} for {content.reason}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue