Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
linkedin
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mautrix
linkedin
Commits
89f1b826
Unverified
Commit
89f1b826
authored
4 weeks ago
by
Sumner Evans
Browse files
Options
Downloads
Patches
Plain Diff
connector: implement sending other media
Signed-off-by:
Sumner Evans
<
sumner.evans@automattic.com
>
parent
8e1da614
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#16466
passed
4 weeks ago
Stage: build
Stage: build docker
Stage: manifest
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/connector/capabilities.go
+2
-1
2 additions, 1 deletion
pkg/connector/capabilities.go
pkg/connector/matrix.go
+5
-51
5 additions, 51 deletions
pkg/connector/matrix.go
pkg/linkedingo/messages.go
+9
-1
9 additions, 1 deletion
pkg/linkedingo/messages.go
with
16 additions
and
53 deletions
pkg/connector/capabilities.go
+
2
−
1
View file @
89f1b826
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
pkg/connector/matrix.go
+
5
−
51
View file @
89f1b826
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
pkg/linkedingo/messages.go
+
9
−
1
View file @
89f1b826
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment