Skip to content

Commit

Permalink
capabilities: update to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 10, 2025
1 parent 4e55805 commit 71e0060
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 21 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ require (
github.com/google/uuid v1.6.0
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.10.0
go.mau.fi/util v0.8.4-0.20250106152331-30b8c95e7d7a
go.mau.fi/util v0.8.4-0.20250110124612-64d4dbbec957
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
google.golang.org/protobuf v1.36.2
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.22.2-0.20250107114437-ceb9c7b866e1
maunium.net/go/mautrix v0.22.2-0.20250110145518-285106586976
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
go.mau.fi/util v0.8.4-0.20250106152331-30b8c95e7d7a h1:D9RCHBFjxah9F/YB7amvRJjT2IEOFWcz8jpcEY8dBV0=
go.mau.fi/util v0.8.4-0.20250106152331-30b8c95e7d7a/go.mod h1:MOfGTs1CBuK6ERTcSL4lb5YU7/ujz09eOPVEDckuazY=
go.mau.fi/util v0.8.4-0.20250110124612-64d4dbbec957 h1:tsLt3t6ARc55niz+JMgJy6U4sL210Z0K/nyxF09xT0E=
go.mau.fi/util v0.8.4-0.20250110124612-64d4dbbec957/go.mod h1:MOfGTs1CBuK6ERTcSL4lb5YU7/ujz09eOPVEDckuazY=
go.mau.fi/zeroconfig v0.1.3 h1:As9wYDKmktjmNZW5i1vn8zvJlmGKHeVxHVIBMXsm4kM=
go.mau.fi/zeroconfig v0.1.3/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
Expand Down Expand Up @@ -93,5 +93,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/mautrix v0.22.2-0.20250107114437-ceb9c7b866e1 h1:ECwjKJLKKsTp/gnp0Qd5GojeZOK/MLVFF0Tf7C6gZDQ=
maunium.net/go/mautrix v0.22.2-0.20250107114437-ceb9c7b866e1/go.mod h1:FmwzK7RSzrd1OfGDgJzFWXl7nYmYm8/P0Y77sy/A1Uw=
maunium.net/go/mautrix v0.22.2-0.20250110145518-285106586976 h1:I06GGTFPiwWTMuLoZCtTg2y9Oc3Qi85MzvS+9fgyCtg=
maunium.net/go/mautrix v0.22.2-0.20250110145518-285106586976/go.mod h1:07i96D7BALyuAqxFhRzvaId8FC9NABgRQBPY5HWndf4=
156 changes: 142 additions & 14 deletions pkg/connector/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package connector
import (
"context"

"go.mau.fi/util/ffmpeg"
"go.mau.fi/util/ptr"
"maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/bridgev2/database"
"maunium.net/go/mautrix/event"

"go.mau.fi/mautrix-gmessages/pkg/libgm/gmproto"
)
Expand All @@ -34,26 +37,151 @@ func (gc *GMConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
return generalCaps
}

var rcsDMCaps = &bridgev2.NetworkRoomCapabilities{
Replies: true,
Deletes: true,
ReadReceipts: true,
Reactions: true,
func (gc *GMConnector) GetBridgeInfoVersion() (info, caps int) {
return 1, 1
}

var rcsGroupCaps = &bridgev2.NetworkRoomCapabilities{
Replies: true,
Deletes: true,
Reactions: true,
const MaxFileSizeRCS = 100 * 1024 * 1024
const MaxFileSizeMMS = 1 * 1024 * 1024

func supportedIfFFmpeg() event.CapabilitySupportLevel {
if ffmpeg.Supported() {
return event.CapLevelPartialSupport
}
return event.CapLevelRejected
}

func capID(chatType string) string {
base := "fi.mau.gmessages.capabilities.2025_01_10." + chatType
if ffmpeg.Supported() {
return base + "+ffmpeg"
}
return base
}

var imageMimes = map[string]event.CapabilitySupportLevel{
"image/png": event.CapLevelFullySupported,
"image/jpeg": event.CapLevelFullySupported,
"image/gif": event.CapLevelFullySupported,
"image/bmp": event.CapLevelFullySupported,
"image/wbmp": event.CapLevelFullySupported,
"image/webp": event.CapLevelFullySupported,
}

var audioMimes = map[string]event.CapabilitySupportLevel{
"audio/aac": event.CapLevelFullySupported,
"audio/amr": event.CapLevelFullySupported,
"audio/mp3": event.CapLevelFullySupported,
"audio/mpeg": event.CapLevelFullySupported,
"audio/mp4": event.CapLevelFullySupported,
"audio/mp4-latm": event.CapLevelFullySupported,
"audio/3gpp": event.CapLevelFullySupported,
"audio/ogg": event.CapLevelFullySupported,
}

var videoMimes = map[string]event.CapabilitySupportLevel{
"video/mp4": event.CapLevelFullySupported,
"video/3gpp": event.CapLevelFullySupported,
"video/webm": event.CapLevelFullySupported,
}

var fileMimes = map[string]event.CapabilitySupportLevel{
"application/*": event.CapLevelFullySupported,
"text/*": event.CapLevelFullySupported,
}

var voiceMimes = map[string]event.CapabilitySupportLevel{
"audio/ogg": supportedIfFFmpeg(),
"audio/mp4": event.CapLevelFullySupported,
}

var gifMimes = map[string]event.CapabilitySupportLevel{
"image/gif": event.CapLevelFullySupported,
}

var rcsDMCaps = &event.RoomFeatures{
ID: capID("rcs_dm"),
File: event.FileFeatureMap{
event.MsgImage: {
MimeTypes: imageMimes,
MaxSize: MaxFileSizeRCS,
},
event.MsgAudio: {
MimeTypes: audioMimes,
MaxSize: MaxFileSizeRCS,
},
event.MsgVideo: {
MimeTypes: videoMimes,
MaxSize: MaxFileSizeRCS,
},
event.MsgFile: {
MimeTypes: fileMimes,
MaxSize: MaxFileSizeRCS,
},
event.CapMsgVoice: {
MimeTypes: voiceMimes,
MaxSize: MaxFileSizeRCS,
},
event.CapMsgGIF: {
MimeTypes: gifMimes,
MaxSize: MaxFileSizeRCS,
},
},
Reply: event.CapLevelFullySupported,
DeleteForMe: true,
Reaction: event.CapLevelFullySupported,
ReactionCount: 1,
ReadReceipts: true,
}

var rcsGroupCaps *event.RoomFeatures

func init() {
rcsGroupCaps = ptr.Clone(rcsDMCaps)
rcsGroupCaps.ID = capID("rcs_group")
rcsGroupCaps.ReadReceipts = false
}

var smsRoomCaps = &bridgev2.NetworkRoomCapabilities{
Captions: true,
Deletes: true,
Reactions: true,
var smsRoomCaps = &event.RoomFeatures{
ID: capID("sms"),
File: event.FileFeatureMap{
event.MsgImage: {
MimeTypes: imageMimes,
Caption: event.CapLevelFullySupported,
MaxSize: MaxFileSizeMMS,
},
event.MsgAudio: {
MimeTypes: audioMimes,
Caption: event.CapLevelFullySupported,
MaxSize: MaxFileSizeMMS,
},
event.MsgVideo: {
MimeTypes: videoMimes,
Caption: event.CapLevelFullySupported,
MaxSize: MaxFileSizeMMS,
},
event.MsgFile: {
MimeTypes: fileMimes,
Caption: event.CapLevelFullySupported,
MaxSize: MaxFileSizeMMS,
},
event.CapMsgVoice: {
MimeTypes: voiceMimes,
MaxSize: MaxFileSizeRCS,
},
event.CapMsgGIF: {
MimeTypes: gifMimes,
Caption: event.CapLevelFullySupported,
MaxSize: MaxFileSizeMMS,
},
},
DeleteForMe: true,
Reaction: event.CapLevelPartialSupport,
ReactionCount: 1,
ReadReceipts: true,
}

func (gc *GMClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities {
func (gc *GMClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures {
if portal.Metadata.(*PortalMetadata).Type == gmproto.ConversationType_RCS {
if portal.RoomType == database.RoomTypeDM {
return rcsDMCaps
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (gc *GMClient) reuploadMedia(ctx context.Context, content *event.MessageEve
if content.FileName != "" {
fileName = content.FileName
}
if content.MSC3245Voice != nil {
if content.MSC3245Voice != nil && content.Info.MimeType != "audio/mp4" && ffmpeg.Supported() {
data, err = ffmpeg.ConvertBytes(ctx, data, ".m4a", []string{}, []string{"-c:a", "aac"}, content.Info.MimeType)
if err != nil {
return nil, fmt.Errorf("%w (ogg to m4a): %w", bridgev2.ErrMediaConvertFailed, err)
Expand Down

0 comments on commit 71e0060

Please sign in to comment.