Skip to content

Commit

Permalink
Properly convert signal long text messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Apr 23, 2024
1 parent 703beca commit 1c64c3b
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 1c64c3b

Please sign in to comment.