ensure replies are removed before sending email

This commit is contained in:
Aine 2024-08-21 14:15:10 +03:00
parent 7d482a83a5
commit fd94406649
No known key found for this signature in database
GPG key ID: 34969C908CCA2804

View file

@ -343,6 +343,7 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
ctx = threadIDToContext(ctx, meta.ThreadID) ctx = threadIDToContext(ctx, meta.ThreadID)
} }
content := evt.Content.AsMessage() content := evt.Content.AsMessage()
b.clearReply(content)
if meta.Subject == "" { if meta.Subject == "" {
meta.Subject = strings.SplitN(content.Body, "\n", 1)[0] meta.Subject = strings.SplitN(content.Body, "\n", 1)[0]
} }
@ -648,3 +649,19 @@ func (b *Bot) setLastEventID(ctx context.Context, roomID id.RoomID, threadID, ev
b.log.Error().Err(err).Str("key", key).Msg("cannot save thread ID") b.log.Error().Err(err).Str("key", key).Msg("cannot save thread ID")
} }
} }
// clearReply removes quotation of previous message in reply message, to avoid confusion
func (b *Bot) clearReply(content *event.MessageEventContent) {
index := strings.Index(content.Body, "> <@")
formattedIndex := strings.Index(content.FormattedBody, "</mx-reply>")
if index >= 0 {
index = strings.Index(content.Body, "\n\n")
// 2 is length of "\n\n"
content.Body = content.Body[index+2:]
}
if formattedIndex >= 0 {
// 11 is length of "</mx-reply>"
content.FormattedBody = content.FormattedBody[formattedIndex+11:]
}
}