Skip to content

Commit

Permalink
Properly convert long text messages from Signal (#506)
Browse files Browse the repository at this point in the history
Fixes #479
  • Loading branch information
maltee1 committed May 1, 2024
1 parent 2a4b58e commit 73e7619
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion msgconv/from-signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 73e7619

Please sign in to comment.