Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/events/eventBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export type RedactedEvent = EventBase & {

export const isRedactedEvent = (
event: Pdu,
): event is PduForType<'m.room.redaction'> & {} => {
return event.type === 'm.room.redaction';
): event is PduForType<'m.room.redaction'> => {
return event.type === 'm.room.redaction' && 'redacts' in event;
Comment thread
ricardogarim marked this conversation as resolved.
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

export interface Events {}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/events/m.room.redaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ test('redactionEvent', async () => {
prev_events: ['$8ftnUd9WTPTQGbdPgfOPea8bOEQ21qPvbcGqeOApQxA'],
depth: 4,
content: {
redacts: '$8ftnUd9WTPTQGbdPgfOPea8bOEQ21qPvbcGqeOApQxA',
reason: 'Inappropriate content',
},
redacts: '$8ftnUd9WTPTQGbdPgfOPea8bOEQ21qPvbcGqeOApQxA',
origin: 'rc1',
ts: 1747837631863,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/events/m.room.redaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const redactionEvent = ({
prev_events,
depth,
content,
redacts,
origin,
ts = Date.now(),
unsigned,
Expand All @@ -51,15 +52,14 @@ export const redactionEvent = ({
prev_events: EventID[];
depth: number;
content: {
redacts: EventID;
reason?: string;
};
redacts: EventID;
origin?: string;
ts?: number;
unsigned?: { age_ts?: number };
}): RedactionEvent => {
// Extract redacts from content - it must be at top level only
const { redacts } = content;
const { reason } = content;

const baseEvent = createEventBase('m.room.redaction', {
Expand Down
12 changes: 8 additions & 4 deletions packages/federation-sdk/src/services/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ export class MessageService {
type: 'm.room.redaction',
content: {
reason: 'Unsetting reaction',
redacts: eventIdReactedTo,
},
redacts: eventIdReactedTo,
room_id: roomId,
auth_events: [],
depth: 0,
Expand Down Expand Up @@ -422,7 +422,6 @@ export class MessageService {
async redactMessage(
roomId: string,
eventIdToRedact: EventID,
senderUserId: string,
): Promise<string> {
const isTombstoned = await this.roomService.isRoomTombstoned(roomId);
if (isTombstoned) {
Expand All @@ -434,20 +433,25 @@ export class MessageService {

const roomInfo = await this.stateService.getRoomInformation(roomId);

const senderUserId = await this.eventService.getEventById(eventIdToRedact);
if (!senderUserId?.event.sender) {
throw new Error(`Sender user ID not found for event ${eventIdToRedact}`);
}

const redactionEvent =
await this.stateService.buildEvent<'m.room.redaction'>(
{
type: 'm.room.redaction',
content: {
reason: `Deleting message: ${eventIdToRedact}`,
redacts: eventIdToRedact,
},
redacts: eventIdToRedact,
room_id: roomId,
auth_events: [],
depth: 0,
prev_events: [],
origin_server_ts: Date.now(),
sender: senderUserId,
sender: senderUserId.event.sender,
},
Comment thread
ricardogarim marked this conversation as resolved.
roomInfo.room_version,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class StagingAreaService {
room_id: roomId,
sender: event.event.sender,
origin_server_ts: event.event.origin_server_ts,
redacts: event.event.content.redacts,
redacts: event.event.redacts as EventID,
content: {
reason: event.event.content?.reason as string | undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,10 @@ export const internalMessagePlugin = (app: Elysia) => {
params,
body,
}): Promise<InternalRedactMessageResponse | ErrorResponse> => {
const { roomId, senderUserId } = body;
const { roomId } = body;
const eventId = await messageService.redactMessage(
roomId,
params.messageId as EventID,
senderUserId,
);

return {
Expand Down
1 change: 0 additions & 1 deletion packages/homeserver/src/dtos/internal/message.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const InternalRedactMessageParamsDto = t.Object({

export const InternalRedactMessageBodyDto = t.Object({
roomId: RoomIdDto,
senderUserId: UsernameDto,
});

export const InternalRedactMessageResponseDto = InternalMessageResponseDto;
Expand Down
1 change: 0 additions & 1 deletion packages/room/src/types/v3-11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export type PduRoomTopicEventContent = z.infer<

export const PduRoomRedactionContentSchema = z.object({
reason: z.string().optional(),
redacts: eventIdSchema.describe('event id'),
});

export type PduRoomRedactionContent = z.infer<
Expand Down