From 73e7619312248c0abc2a64a058d1221152f6a8dc Mon Sep 17 00:00:00 2001 From: Malte E <97891689+maltee1@users.noreply.github.com> Date: Wed, 1 May 2024 10:17:07 +0200 Subject: [PATCH] Properly convert long text messages from Signal (#506) Fixes #479 --- msgconv/from-signal.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/msgconv/from-signal.go b/msgconv/from-signal.go index 9b47ccac..a5c01740 100644 --- a/msgconv/from-signal.go +++ b/msgconv/from-signal.go @@ -115,7 +115,16 @@ func (mc *MessageConverter) ToMatrix(ctx context.Context, dm *signalpb.DataMessa return cm } for i, att := range dm.GetAttachments() { - cm.Parts = append(cm.Parts, mc.convertAttachmentToMatrix(ctx, i, att)) + if att.GetContentType() != "text/x-signal-plain" { + cm.Parts = append(cm.Parts, mc.convertAttachmentToMatrix(ctx, i, att)) + } else { + longBody, err := mc.downloadSignalLongText(ctx, att) + if err == nil { + dm.Body = longBody + } else { + zerolog.Ctx(ctx).Err(err).Msg("Failed to download Signal long text") + } + } } for _, contact := range dm.GetContact() { cm.Parts = append(cm.Parts, mc.convertContactToMatrix(ctx, contact)) @@ -415,6 +424,15 @@ func (mc *MessageConverter) convertStickerToMatrix(ctx context.Context, sticker return converted } +func (mc *MessageConverter) downloadSignalLongText(ctx context.Context, att *signalpb.AttachmentPointer) (*string, error) { + data, err := signalmeow.DownloadAttachment(ctx, att) + if err != nil { + return nil, fmt.Errorf("failed to download attachment: %w", err) + } + longBody := string(data) + return &longBody, nil +} + func (mc *MessageConverter) reuploadAttachment(ctx context.Context, att *signalpb.AttachmentPointer) (*ConvertedMessagePart, error) { data, err := signalmeow.DownloadAttachment(ctx, att) if err != nil {