Skip to content

Commit

Permalink
feat: include user and room in report
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Dec 20, 2024
1 parent b538664 commit d5e8811
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func redactMessage(client *mautrix.Client, ctx context.Context, evt *event.Event
if !config.mngtRoomReports {
return
}
message := fmt.Sprintf("Message redacted - %s:<br/><blockquote>%s</blockquote>", reason, evt.Content.AsMessage().Body)
rawMessage := fmt.Sprintf("Message redacted - %s:%s", reason, evt.Content.AsMessage().Body)
message := getRedactNotice(reason, evt)
rawMessage := getRawRedactNotice(reason, evt)
contentJson := &event.MessageEventContent{
MsgType: event.MsgNotice,
Format: event.FormatHTML,
Expand All @@ -207,6 +207,22 @@ func redactMessage(client *mautrix.Client, ctx context.Context, evt *event.Event
}
}

func getRedactNotice(reason string, evt *event.Event) string {
roomId := evt.RoomID.String()
userId := evt.Sender.String()
template := "Message redacted - %s;<br/>" +
"User <a href='https://matrix.to/#/%s'>%s</a> in room <a href='https://matrix.to/#/%s'>%s</a> :<br/>" +
"<blockquote>%s</blockquote>"
return fmt.Sprintf(template, reason, userId, userId, roomId, roomId, evt.Content.AsMessage().Body)
}

func getRawRedactNotice(reason string, evt *event.Event) string {
roomId := evt.RoomID.String()
userId := evt.Sender.String()
template := "Message redacted - %s; User '%s' in room '%s': %s"
return fmt.Sprintf(template, reason, userId, roomId, evt.Content.AsMessage().Body)
}

func onRoomInvite(ctx context.Context, evt *event.Event) {
if evt.GetStateKey() == client.UserID.String() && evt.Content.AsMember().Membership == event.MembershipInvite {
_, err := client.JoinRoomByID(ctx, evt.RoomID)
Expand Down

0 comments on commit d5e8811

Please sign in to comment.