Skip to content
Snippets Groups Projects
Unverified Commit 89f1b826 authored by Sumner Evans's avatar Sumner Evans
Browse files

connector: implement sending other media

parent 8e1da614
No related branches found
No related tags found
No related merge requests found
Pipeline #16466 passed
......@@ -63,7 +63,8 @@ var fileCaps = event.FileFeatureMap{
event.MsgImage: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"image/jpeg": event.CapLevelFullySupported,
"image/png": event.CapLevelPartialSupport,
"image/png": event.CapLevelFullySupported,
"image/webp": event.CapLevelFullySupported,
},
Caption: event.CapLevelFullySupported,
MaxCaptionLength: MaxCaptionLength,
......
......@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"strings"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
......@@ -22,15 +21,6 @@ func getMediaFilename(content *event.MessageEventContent) (filename string) {
} else {
filename = content.Body
}
if filename == "" {
return "image.jpg" // Assume it's a JPEG image
}
if content.MsgType == event.MsgImage && (!strings.HasSuffix(filename, ".jpg") && !strings.HasSuffix(filename, ".jpeg") && !strings.HasSuffix(filename, ".png")) {
if content.Info != nil && content.Info.MimeType != "" {
return filename + strings.TrimPrefix(content.Info.MimeType, "image/")
}
return filename + ".jpg" // Assume it's a JPEG
}
return filename
}
......@@ -49,10 +39,13 @@ func (l *LinkedInClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.
}
var renderContent []linkedingo.SendRenderContent
switch msg.Content.MsgType {
case event.MsgImage:
if msg.Content.MsgType.IsMedia() {
err := l.main.Bridge.Bot.DownloadMediaToFile(ctx, msg.Content.URL, msg.Content.File, false, func(f *os.File) error {
attachmentType := linkedingo.MediaUploadTypePhotoAttachment
if msg.Content.MsgType != event.MsgImage {
attachmentType = linkedingo.MediaUploadTypeFileAttachment
}
filename := getMediaFilename(msg.Content)
urn, err := l.client.UploadMedia(ctx, attachmentType, filename, msg.Content.Info.MimeType, msg.Content.Info.Size, f)
if err != nil {
......@@ -73,45 +66,6 @@ func (l *LinkedInClient) HandleMatrixMessage(ctx context.Context, msg *bridgev2.
}
}
// content := msg.Content
//
// switch content.MsgType {
// case event.MsgText:
// break
// case event.MsgVideo, event.MsgImage:
// if content.Body == content.FileName {
// sendMessagePayload.Message.Body.Text = ""
// }
//
// file := content.GetFile()
// data, err := lc.connector.br.Bot.DownloadMedia(ctx, file.URL, file)
// if err != nil {
// return nil, err
// }
//
// attachmentType := payloadold.MediaUploadFileAttachment
// if content.MsgType == event.MsgImage {
// attachmentType = payloadold.MediaUploadTypePhotoAttachment
// }
//
// mediaMetadata, err := lc.client.UploadMedia(attachmentType, content.FileName, data, typesold.ContentTypeJSONPlaintextUTF8)
// if err != nil {
// return nil, err
// }
//
// lc.client.Logger.Debug().Any("media_metadata", mediaMetadata).Msg("Successfully uploaded media to LinkedIn's servers")
// sendMessagePayload.Message.RenderContentUnions = append(sendMessagePayload.Message.RenderContentUnions, payloadold.RenderContent{
// File: &payloadold.File{
// AssetUrn: mediaMetadata.Urn,
// Name: content.FileName,
// MediaType: typesold.ContentType(content.Info.MimeType),
// ByteSize: len(data),
// },
// })
// default:
// return nil, fmt.Errorf("%w %s", bridgev2.ErrUnsupportedMessageType, content.MsgType)
// }
resp, err := l.client.SendMessage(ctx, conversationURN, matrixfmt.Parse(ctx, l.matrixParser, msg.Content), renderContent)
if err != nil {
return nil, err
......
......@@ -8,6 +8,7 @@ import (
"net/url"
"github.com/google/uuid"
"go.mau.fi/util/jsontime"
"go.mau.fi/util/random"
"go.mau.fi/mautrix-linkedin/pkg/linkedingo/types"
......@@ -45,7 +46,14 @@ type AttributeType struct {
}
type SendRenderContent struct {
File *SendFile `json:"file,omitempty"`
Audio *SendAudio `json:"audio,omitempty"`
File *SendFile `json:"file,omitempty"`
}
type SendAudio struct {
AssetURN types.URN `json:"assetUrn,omitempty"`
ByteSize int `json:"byteSize,omitempty"`
Duration jsontime.Milliseconds `json:"duration,omitempty"`
}
type SendFile struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment