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 d183e67 commit 3d04feb
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 62 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ require (
github.com/tidwall/gjson v1.18.0
github.com/zyedidia/clipboard v1.0.4
go.mau.fi/libsignal v0.1.1
go.mau.fi/util v0.8.3
go.mau.fi/whatsmeow v0.0.0-20241215104421-68b0856cce22
golang.org/x/crypto v0.31.0
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e
go.mau.fi/util v0.8.4-0.20250110124612-64d4dbbec957
go.mau.fi/whatsmeow v0.0.0-20250104105216-918c879fcd19
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329
golang.org/x/image v0.23.0
golang.org/x/net v0.32.0
google.golang.org/protobuf v1.35.2
golang.org/x/net v0.33.0
google.golang.org/protobuf v1.36.1
gopkg.in/yaml.v3 v3.0.1
maunium.net/go/mautrix v0.22.1
maunium.net/go/mautrix v0.22.2-0.20250110154103-bbcb1904e268
)

require (
Expand All @@ -41,7 +41,7 @@ require (
github.com/yuin/goldmark v1.7.8 // indirect
go.mau.fi/zeroconfig v0.1.3 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
maunium.net/go/mauflag v1.0.0 // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,32 @@ github.com/zyedidia/clipboard v1.0.4 h1:r6GUQOyPtIaApRLeD56/U+2uJbXis6ANGbKWCljU
github.com/zyedidia/clipboard v1.0.4/go.mod h1:zykFnZUXX0ErxqvYLUFEq7QDJKId8rmh2FgD0/Y8cjA=
go.mau.fi/libsignal v0.1.1 h1:m/0PGBh4QKP/I1MQ44ti4C0fMbLMuHb95cmDw01FIpI=
go.mau.fi/libsignal v0.1.1/go.mod h1:QLs89F/OA3ThdSL2Wz2p+o+fi8uuQUz0e1BRa6ExdBw=
go.mau.fi/util v0.8.3 h1:sulhXtfquMrQjsOP67x9CzWVBYUwhYeoo8hNQIpCWZ4=
go.mau.fi/util v0.8.3/go.mod h1:c00Db8xog70JeIsEvhdHooylTkTkakgnAOsZ04hplQY=
go.mau.fi/whatsmeow v0.0.0-20241215104421-68b0856cce22 h1:0jqmWhJeVvCnIFcMqETqqHwmlgPSDZKYbeLPhCqeHE0=
go.mau.fi/whatsmeow v0.0.0-20241215104421-68b0856cce22/go.mod h1:56ExppHW+lqAZA4AGmCg0+qHrP5TZuIN8oiubTULSVA=
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/whatsmeow v0.0.0-20250104105216-918c879fcd19 h1:uVS+Zct5fF8rSXV9lfs87zoXdge0JXTzVGNkjmZ61UU=
go.mau.fi/whatsmeow v0.0.0-20250104105216-918c879fcd19/go.mod h1:TLzm2XkwgufONEmiVAsFny+9uBqyEZnUoPrQAfMyuSU=
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.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e h1:4qufH0hlUYs6AO6XmZC3GqfDPGSXHVXUFR6OND+iJX4=
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 h1:9kj3STMvgqy3YA4VQXBrN7925ICMxD5wzMRcgA30588=
golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
Expand All @@ -94,5 +94,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.1 h1:2lCM37vmVzZGE0tWD7UOySMtAuC5hq6Pw33KlY2VU/c=
maunium.net/go/mautrix v0.22.1/go.mod h1:1rhqwH34Rz54ZqzdQYkmNW6rQUymNeTdaLA4l9LK6AI=
maunium.net/go/mautrix v0.22.2-0.20250110154103-bbcb1904e268 h1:p+3TofdhqiVYIkLjgzidayg2XriGUEbj+nbWs3/UQbk=
maunium.net/go/mautrix v0.22.2-0.20250110154103-bbcb1904e268/go.mod h1:07i96D7BALyuAqxFhRzvaId8FC9NABgRQBPY5HWndf4=
165 changes: 165 additions & 0 deletions pkg/connector/capabilities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// mautrix-meta - A Matrix-Facebook Messenger and Instagram DM puppeting bridge.
// Copyright (C) 2025 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package connector

import (
"context"
"time"

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

"go.mau.fi/mautrix-meta/pkg/messagix/table"
"go.mau.fi/mautrix-meta/pkg/metaid"
)

var metaGeneralCaps = &bridgev2.NetworkGeneralCapabilities{
DisappearingMessages: false,
AggressiveUpdateInfo: false,
}

func (m *MetaConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
return metaGeneralCaps
}

func (m *MetaConnector) GetBridgeInfoVersion() (info, caps int) {
return 1, 1
}

const MaxTextLength = 20000
const MaxFileSize = 25 * 1000 * 1000
const MaxImageSize = 8 * 1000 * 1000

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

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

var metaCaps = &event.RoomFeatures{
ID: capID(),
Formatting: event.FormattingFeatureMap{
event.FmtUserLink: event.CapLevelFullySupported,
},
File: event.FileFeatureMap{
event.MsgImage: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"image/jpeg": event.CapLevelFullySupported,
"image/png": event.CapLevelFullySupported,
"image/gif": event.CapLevelFullySupported,
"image/webp": event.CapLevelFullySupported,
},
Caption: event.CapLevelFullySupported,
MaxCaptionLength: MaxTextLength,
MaxSize: MaxImageSize,
},
event.MsgVideo: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"video/mp4": event.CapLevelFullySupported,
"video/quicktime": event.CapLevelFullySupported,
"video/webm": event.CapLevelFullySupported,
"video/ogg": event.CapLevelFullySupported,
},
Caption: event.CapLevelFullySupported,
MaxCaptionLength: MaxTextLength,
MaxSize: MaxFileSize,
},
event.MsgAudio: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"audio/m4a": event.CapLevelFullySupported,
"audio/mp3": event.CapLevelFullySupported,
"audio/mp4": event.CapLevelFullySupported,
"audio/wav": event.CapLevelFullySupported,
},
Caption: event.CapLevelDropped,
MaxSize: MaxFileSize,
},
event.MsgFile: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"*/*": event.CapLevelFullySupported,
},
Caption: event.CapLevelFullySupported,
MaxCaptionLength: MaxTextLength,
MaxSize: MaxFileSize,
},
event.CapMsgGIF: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"image/gif": event.CapLevelFullySupported,
},
Caption: event.CapLevelFullySupported,
MaxCaptionLength: MaxTextLength,
MaxSize: MaxImageSize,
},
event.CapMsgSticker: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"image/png": event.CapLevelFullySupported,
"image/webp": event.CapLevelFullySupported,
},
Caption: event.CapLevelDropped,
MaxSize: MaxImageSize,
},
event.CapMsgVoice: {
MimeTypes: map[string]event.CapabilitySupportLevel{
"audio/mp4": event.CapLevelFullySupported,
"audio/ogg": supportedIfFFmpeg(),
},
Caption: event.CapLevelDropped,
MaxSize: MaxFileSize,
},
},
MaxTextLength: MaxTextLength,
Reply: event.CapLevelFullySupported,
Edit: event.CapLevelFullySupported,
EditMaxCount: 10,
EditMaxAge: ptr.Ptr(jsontime.S(24 * time.Hour)),
Reaction: event.CapLevelFullySupported,
ReactionCount: 1,
//LocationMessage: event.CapLevelPartialSupport,
}

var metaCapsWithThreads *event.RoomFeatures
var igCaps *event.RoomFeatures

func init() {
metaCapsWithThreads = ptr.Clone(metaCaps)
metaCapsWithThreads.ID += "+communitygroup"
metaCapsWithThreads.Thread = event.CapLevelFullySupported

igCaps = ptr.Clone(metaCaps)
igCaps.ID += "+instagram"
delete(igCaps.File, event.MsgFile)
}

func (m *MetaClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *event.RoomFeatures {
switch portal.Metadata.(*metaid.PortalMetadata).ThreadType {
case table.COMMUNITY_GROUP:
return metaCapsWithThreads
}
return metaCaps
}
29 changes: 0 additions & 29 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/rs/zerolog"
"go.mau.fi/util/exsync"
"go.mau.fi/util/ptr"
"go.mau.fi/whatsmeow"
"go.mau.fi/whatsmeow/store"
waTypes "go.mau.fi/whatsmeow/types"
Expand Down Expand Up @@ -345,34 +344,6 @@ func (m *MetaClient) Disconnect() {
}
}

var metaCaps = &bridgev2.NetworkRoomCapabilities{
FormattedText: true,
UserMentions: true,
Replies: true,
Edits: true,
EditMaxCount: 10,
EditMaxAge: 24 * time.Hour,
Reactions: true,
ReactionCount: 1,
LocationMessages: true,
Captions: true,
}

var metaCapsWithThreads *bridgev2.NetworkRoomCapabilities

func init() {
metaCapsWithThreads = ptr.Clone(metaCaps)
metaCapsWithThreads.Threads = true
}

func (m *MetaClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities {
switch portal.Metadata.(*metaid.PortalMetadata).ThreadType {
case table.COMMUNITY_GROUP:
return metaCapsWithThreads
}
return metaCaps
}

func (m *MetaClient) IsLoggedIn() bool {
return m.Client != nil && m.Client.SyncManager != nil
}
Expand Down
9 changes: 0 additions & 9 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ func (m *MetaConnector) SetMaxFileSize(maxSize int64) {
m.MsgConv.MaxFileSize = maxSize
}

var metaGeneralCaps = &bridgev2.NetworkGeneralCapabilities{
DisappearingMessages: false,
AggressiveUpdateInfo: false,
}

func (m *MetaConnector) GetCapabilities() *bridgev2.NetworkGeneralCapabilities {
return metaGeneralCaps
}

func (m *MetaConnector) GetName() bridgev2.BridgeName {
switch m.Config.Mode {
case types.Facebook, types.FacebookTor, types.Messenger:
Expand Down

0 comments on commit 3d04feb

Please sign in to comment.