diff --git a/go.mod b/go.mod index c5862b48..d5f40d64 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 golang.org/x/net v0.26.0 google.golang.org/protobuf v1.34.2 - maunium.net/go/mautrix v0.19.0-beta.1.0.20240620142853-7b6f3ba0541d + maunium.net/go/mautrix v0.19.0-beta.1.0.20240621171215-921240d99bf7 nhooyr.io/websocket v1.8.11 ) diff --git a/go.sum b/go.sum index bbb191e3..3e034647 100644 --- a/go.sum +++ b/go.sum @@ -93,7 +93,7 @@ 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.19.0-beta.1.0.20240620142853-7b6f3ba0541d h1:s3wbfQ3jJOlZy0oYE/dVSTxAHDMQHwBlHVLqQZGeQX4= -maunium.net/go/mautrix v0.19.0-beta.1.0.20240620142853-7b6f3ba0541d/go.mod h1:cxv1w6+syudmEpOewHYIQT9yO7TM5UOWmf6xEBVI4H4= +maunium.net/go/mautrix v0.19.0-beta.1.0.20240621171215-921240d99bf7 h1:kdp/zZXtl0vMXa6/Vto34mQ4YhHoj4DHSffr4j101eA= +maunium.net/go/mautrix v0.19.0-beta.1.0.20240621171215-921240d99bf7/go.mod h1:cxv1w6+syudmEpOewHYIQT9yO7TM5UOWmf6xEBVI4H4= nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0= nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= diff --git a/pkg/connector/client.go b/pkg/connector/client.go index 20f3d8e2..6f1a3ec3 100644 --- a/pkg/connector/client.go +++ b/pkg/connector/client.go @@ -19,11 +19,41 @@ type SignalClient struct { Client *signalmeow.Client } -var _ bridgev2.NetworkAPI = (*SignalClient)(nil) -var _ bridgev2.PushableNetworkAPI = (*SignalClient)(nil) -var _ bridgev2.IdentifierResolvingNetworkAPI = (*SignalClient)(nil) -var _ bridgev2.GroupCreatingNetworkAPI = (*SignalClient)(nil) -var _ bridgev2.ContactListingNetworkAPI = (*SignalClient)(nil) +var signalCaps = &bridgev2.NetworkRoomCapabilities{ + FormattedText: true, + UserMentions: true, + LocationMessages: true, + Captions: true, + Replies: true, + Edits: true, + EditMaxCount: 10, + EditMaxAge: 24 * time.Hour, + Deletes: true, + DeleteMaxAge: 24 * time.Hour, + DefaultFileRestriction: &bridgev2.FileRestriction{ + MaxSize: 100 * 1024 * 1024, + }, + ReadReceipts: true, + Reactions: true, + ReactionCount: 1, +} + +func (s *SignalClient) GetCapabilities(ctx context.Context, portal *bridgev2.Portal) *bridgev2.NetworkRoomCapabilities { + return signalCaps +} + +var ( + _ bridgev2.NetworkAPI = (*SignalClient)(nil) + _ bridgev2.EditHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.ReactionHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.RedactionHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.ReadReceiptHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.ReadReceiptHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.TypingHandlingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.IdentifierResolvingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.GroupCreatingNetworkAPI = (*SignalClient)(nil) + _ bridgev2.ContactListingNetworkAPI = (*SignalClient)(nil) +) var pushCfg = &bridgev2.PushConfig{ FCM: &bridgev2.FCMPushConfig{ diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index fe594dd7..2e6d59db 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -80,7 +80,7 @@ func (s *SignalConnector) Init(bridge *bridgev2.Bridge) { return signalfmt.UserInfo{} } userInfo := signalfmt.UserInfo{ - MXID: ghost.MXID, + MXID: ghost.Intent.GetMXID(), Name: ghost.Name, } userLogin := s.Bridge.GetCachedUserLoginByID(networkid.UserLoginID(uuid.String())) @@ -124,7 +124,11 @@ func (s *SignalConnector) SetMaxFileSize(maxSize int64) { } func (s *SignalConnector) Start(ctx context.Context) error { - return s.Store.Upgrade(ctx) + err := s.Store.Upgrade(ctx) + if err != nil { + return bridgev2.DBUpgradeError{Err: err, Section: "signalmeow"} + } + return nil } func (s *SignalConnector) LoadUserLogin(ctx context.Context, login *bridgev2.UserLogin) error { diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 839c6446..30b10e67 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -122,6 +122,7 @@ func (s *SignalClient) HandleMatrixEdit(ctx context.Context, msg *bridgev2.Matri fmt.Println(res) msg.EditTarget.ID = makeMessageID(s.Client.Store.ACI, converted.GetTimestamp()) msg.EditTarget.Metadata.Extra["contains_attachments"] = len(converted.Attachments) > 0 + msg.EditTarget.Metadata.EditCount++ return nil } diff --git a/pkg/connector/handlesignal.go b/pkg/connector/handlesignal.go index bfbc7733..479ce2a6 100644 --- a/pkg/connector/handlesignal.go +++ b/pkg/connector/handlesignal.go @@ -273,6 +273,7 @@ func (evt *Bv2ChatEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Porta Content: lastPart.Content, Extra: lastPart.Extra, }) + convertedEdit.ModifiedParts[0].Part.Metadata.EditCount++ return convertedEdit, nil } diff --git a/pkg/connector/login.go b/pkg/connector/login.go index cd0aa1f3..4205f672 100644 --- a/pkg/connector/login.go +++ b/pkg/connector/login.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/google/uuid" + "maunium.net/go/mautrix/bridge/status" "maunium.net/go/mautrix/bridgev2" "maunium.net/go/mautrix/bridgev2/database" @@ -127,13 +128,13 @@ func (qr *QRLogin) Wait(ctx context.Context) (*bridgev2.LoginStep, error) { return nil, ctx.Err() } - ul, err := qr.Main.Bridge.GetUserLoginByID(ctx, newLoginID) + ul, err := qr.Main.Bridge.GetExistingUserLoginByID(ctx, newLoginID) if err != nil { return nil, fmt.Errorf("failed to get existing login: %w", err) } - if ul.UserMXID != qr.User.MXID { - // TODO delete old user login instead of failing new login - return nil, fmt.Errorf("login ID already in use by another user") + if ul != nil && ul.UserMXID != qr.User.MXID { + ul.Delete(ctx, status.BridgeState{StateEvent: status.StateLoggedOut, Error: "overridden-by-another-user"}, false) + ul = nil } if ul == nil { ul, err = qr.User.NewLogin(ctx, &database.UserLogin{