Add a display for the m.room.tombstone event

This commit is contained in:
nexy7574 2025-03-17 00:58:59 +00:00
parent 295d1f156e
commit 43fa495821
No known key found for this signature in database
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,36 @@
// gomuks - A Matrix client written in Go.
// Copyright (C) 2024 Nexus Nicholson
//
// 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 { TombstoneEventContent } from "@/api/types"
import EventContentProps from "./props.ts"
const RoomTombstoneBody = ({ event, sender }: EventContentProps) => {
const content = event.content as TombstoneEventContent
const end = content.body.length > 0 ? ` with the message: ${content.body}` : "."
const onClick = () => window.mainScreenContext.setActiveRoom(content.replacement_room)
const description = (
<span>
replaced this room with&nbsp;
<a onClick={onClick} className="hicli-matrix-uri hicli-matrix-uri-room-alias">
<span className="room-id">{content.replacement_room}</span>
</a>{end}
</span>
)
return <div className="room-avatar-body">
{sender?.content.displayname ?? event.sender} {description}
</div>
}
export default RoomTombstoneBody

View file

@ -12,6 +12,7 @@ import PowerLevelBody from "./PowerLevelBody.tsx"
import RedactedBody from "./RedactedBody.tsx" import RedactedBody from "./RedactedBody.tsx"
import RoomAvatarBody from "./RoomAvatarBody.tsx" import RoomAvatarBody from "./RoomAvatarBody.tsx"
import RoomNameBody from "./RoomNameBody.tsx" import RoomNameBody from "./RoomNameBody.tsx"
import RoomTombstoneBody from "./RoomTombstoneBody.tsx"
import TextMessageBody from "./TextMessageBody.tsx" import TextMessageBody from "./TextMessageBody.tsx"
import UnknownMessageBody from "./UnknownMessageBody.tsx" import UnknownMessageBody from "./UnknownMessageBody.tsx"
import EventContentProps from "./props.ts" import EventContentProps from "./props.ts"
@ -31,6 +32,7 @@ export { default as RedactedBody } from "./RedactedBody.tsx"
export { default as RoomAvatarBody } from "./RoomAvatarBody.tsx" export { default as RoomAvatarBody } from "./RoomAvatarBody.tsx"
export { default as RoomNameBody } from "./RoomNameBody.tsx" export { default as RoomNameBody } from "./RoomNameBody.tsx"
export { default as TextMessageBody } from "./TextMessageBody.tsx" export { default as TextMessageBody } from "./TextMessageBody.tsx"
export { default as RoomTombstoneBody } from "./RoomTombstoneBody.tsx"
export { default as UnknownMessageBody } from "./UnknownMessageBody.tsx" export { default as UnknownMessageBody } from "./UnknownMessageBody.tsx"
export type { default as EventContentProps } from "./props.ts" export type { default as EventContentProps } from "./props.ts"
@ -51,6 +53,8 @@ export function getBodyType(evt: MemDBEvent, forReply = false): React.FunctionCo
return PinnedEventsBody return PinnedEventsBody
case "m.room.power_levels": case "m.room.power_levels":
return PowerLevelBody return PowerLevelBody
case "m.room.tombstone":
return RoomTombstoneBody
} }
} else if (evt.state_key !== undefined) { } else if (evt.state_key !== undefined) {
// State events which must have a non-empty state key // State events which must have a non-empty state key
@ -120,6 +124,7 @@ export function isSmallEvent(bodyType: React.FunctionComponent<EventContentProps
case PolicyRuleBody: case PolicyRuleBody:
case PinnedEventsBody: case PinnedEventsBody:
case PowerLevelBody: case PowerLevelBody:
case RoomTombstoneBody:
return true return true
default: default:
return false return false