From 3e3acd7e08a52189a9c07fb0c1a5d396531ad5f0 Mon Sep 17 00:00:00 2001 From: Malte E Date: Thu, 1 Aug 2024 22:18:07 +0200 Subject: [PATCH 1/5] handle Membership --- go.mod | 2 +- go.sum | 4 +- pkg/connector/groupinfo.go | 4 +- pkg/connector/handlematrix.go | 106 ++++++++++++++++++++++++++++++++++ pkg/signalid/ids.go | 15 +++++ pkg/signalmeow/groups.go | 14 ++--- 6 files changed, 134 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index ac5eeba4..c49fa0ff 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/net v0.27.0 google.golang.org/protobuf v1.34.2 - maunium.net/go/mautrix v0.19.1-0.20240808174455-5edfcff2b7b6 + maunium.net/go/mautrix v0.19.1-0.20240809135320-eb84187368b7 nhooyr.io/websocket v1.8.11 ) diff --git a/go.sum b/go.sum index 11d927a6..4972d7b5 100644 --- a/go.sum +++ b/go.sum @@ -88,7 +88,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.1-0.20240808174455-5edfcff2b7b6 h1:OGskR/suV/6OGgURhucS8eH5QRyRzw7Wkpf8exrOakk= -maunium.net/go/mautrix v0.19.1-0.20240808174455-5edfcff2b7b6/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q= +maunium.net/go/mautrix v0.19.1-0.20240809135320-eb84187368b7 h1:xAq4d1rW/5WN7szBtxHNY/63EPNdji+h7FXlLGBUfJU= +maunium.net/go/mautrix v0.19.1-0.20240809135320-eb84187368b7/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q= 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/groupinfo.go b/pkg/connector/groupinfo.go index db06b957..5c25942e 100644 --- a/pkg/connector/groupinfo.go +++ b/pkg/connector/groupinfo.go @@ -345,7 +345,9 @@ func (s *SignalClient) catchUpGroup(ctx context.Context, portal *bridgev2.Portal for _, gc := range groupChanges { log.Debug().Uint32("current_rev", gc.GroupChange.Revision).Msg("Processing group change") chatInfoChange := s.groupChangeToChatInfoChange(ctx, gc.GroupChange.Revision, gc.GroupChange) - portal.ProcessChatInfoChange(ctx, s.makeEventSender(gc.GroupChange.SourceACI), s.UserLogin, chatInfoChange, time.UnixMilli(int64(ts))) + if gc.GroupChange.SourceServiceID.Type == libsignalgo.ServiceIDTypeACI { + portal.ProcessChatInfoChange(ctx, s.makeEventSender(gc.GroupChange.SourceServiceID.UUID), s.UserLogin, chatInfoChange, time.UnixMilli(int64(ts))) + } if gc.GroupChange.Revision == toRevision { break } diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 9e8c3532..e86981c6 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -25,11 +25,13 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" + "github.com/rs/zerolog/log" "go.mau.fi/util/variationselector" "google.golang.org/protobuf/proto" "maunium.net/go/mautrix/bridgev2" "maunium.net/go/mautrix/bridgev2/database" "maunium.net/go/mautrix/bridgev2/networkid" + "maunium.net/go/mautrix/event" "go.mau.fi/mautrix-signal/pkg/libsignalgo" "go.mau.fi/mautrix-signal/pkg/signalid" @@ -344,3 +346,107 @@ func (s *SignalClient) HandleMatrixRoomTopic(ctx context.Context, msg *bridgev2. ModifyDescription: &msg.Content.Topic, }, nil) } + +func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2.MatrixMembershipChange) (bool, error) { + var targetIntent bridgev2.MatrixAPI + var targetSignalID uuid.UUID + var err error + if msg.TargetGhost != nil { + targetIntent = msg.TargetGhost.Intent + targetSignalID, err = signalid.ParseUserID(msg.TargetGhost.ID) + if err != nil { + return false, fmt.Errorf("failed to parse target ghost signal id: %w", err) + } + } else if msg.TargetUserLogin != nil { + targetSignalID, err = signalid.ParseUserLoginID(msg.TargetUserLogin.ID) + if err != nil { + return false, fmt.Errorf("failed to parse target user signal id: %w", err) + } + targetIntent = msg.TargetUserLogin.User.DoublePuppet(ctx) + if targetIntent == nil { + ghost, err := s.Main.Bridge.GetGhostByID(ctx, networkid.UserID(msg.TargetUserLogin.ID)) + if err != nil { + return false, fmt.Errorf("failed to get ghost for user: %w", err) + } + targetIntent = ghost.Intent + } + } + gc := &signalmeow.GroupChange{} + role := signalmeow.GroupMember_DEFAULT + toMembership := msg.Type.GetTo() + if toMembership == event.MembershipBan { + gc.AddBannedMembers = []*signalmeow.BannedMember{{ + ServiceID: libsignalgo.NewACIServiceID(targetSignalID), + Timestamp: uint64(time.Now().UnixMilli()), + }} + } + if toMembership == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock { + levels, err := msg.Portal.Bridge.Matrix.GetPowerLevels(ctx, msg.Portal.MXID) + if err != nil { + log.Err(err).Msg("Couldn't get power levels") + if levels.GetUserLevel(targetIntent.GetMXID()) >= 50 { + role = signalmeow.GroupMember_ADMINISTRATOR + } + } + } + switch msg.Type { + case bridgev2.AcceptInvite: + gc.PromotePendingMembers = []*signalmeow.PromotePendingMember{&signalmeow.PromotePendingMember{ + ACI: targetSignalID, + }} + case bridgev2.RevokeInvite, bridgev2.RejectInvite, bridgev2.BanInvited: + deletePendingMember := libsignalgo.NewACIServiceID(targetSignalID) + gc.DeletePendingMembers = []*libsignalgo.ServiceID{&deletePendingMember} + case bridgev2.Leave, bridgev2.Kick: + gc.DeleteMembers = []*uuid.UUID{&targetSignalID} + case bridgev2.Invite: + gc.AddMembers = []*signalmeow.AddMember{{ + GroupMember: signalmeow.GroupMember{ + ACI: targetSignalID, + Role: role, + }, + }} + // TODO: joining and knocking requires a way to obtain the invite link + // because the joining/knocking member doesn't have the GroupMasterKey yet + // case bridgev2.Join: + // gc.AddMembers = []*signalmeow.AddMember{{ + // GroupMember: signalmeow.GroupMember{ + // ACI: targetSignalID, + // Role: role, + // }, + // JoinFromInviteLink: true, + // }} + // case bridgev2.Knock: + // gc.AddRequestingMembers = []*signalmeow.RequestingMember{{ + // ACI: targetSignalID, + // Timestamp: uint64(time.Now().UnixMilli()), + // }} + case bridgev2.AcceptKnock: + gc.PromoteRequestingMembers = []*signalmeow.RoleMember{{ + ACI: targetSignalID, + Role: role, + }} + case bridgev2.RetractKnock, bridgev2.RejectKnock, bridgev2.BanKnocked: + gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID} + case bridgev2.Unban: + unbanUser := libsignalgo.NewACIServiceID(targetSignalID) + gc.DeleteBannedMembers = []*libsignalgo.ServiceID{&unbanUser} + } + _, groupID, err := signalid.ParsePortalID(msg.Portal.ID) + if err != nil || groupID == "" { + return false, err + } + gc.Revision = msg.Portal.Metadata.(*signalid.PortalMetadata).Revision + 1 + revision, err := s.Client.UpdateGroup(ctx, gc, groupID) + if err != nil { + return false, err + } + if msg.Type == bridgev2.Invite { + err = targetIntent.EnsureJoined(ctx, msg.Portal.MXID) + if err != nil { + return false, err + } + } + msg.Portal.Metadata.(*signalid.PortalMetadata).Revision = revision + return true, nil +} diff --git a/pkg/signalid/ids.go b/pkg/signalid/ids.go index f99bf9d1..e9c83113 100644 --- a/pkg/signalid/ids.go +++ b/pkg/signalid/ids.go @@ -39,10 +39,25 @@ func ParseUserID(userID networkid.UserID) (uuid.UUID, error) { } } +func ParseUserLoginID(userLoginID networkid.UserLoginID) (uuid.UUID, error) { + serviceID, err := ParseUserLoginIDAsServiceID(userLoginID) + if err != nil { + return uuid.Nil, err + } else if serviceID.Type != libsignalgo.ServiceIDTypeACI { + return uuid.Nil, fmt.Errorf("invalid user ID: expected ACI type") + } else { + return serviceID.UUID, nil + } +} + func ParseUserIDAsServiceID(userID networkid.UserID) (libsignalgo.ServiceID, error) { return libsignalgo.ServiceIDFromString(string(userID)) } +func ParseUserLoginIDAsServiceID(userLoginID networkid.UserLoginID) (libsignalgo.ServiceID, error) { + return libsignalgo.ServiceIDFromString(string(userLoginID)) +} + func ParsePortalID(portalID networkid.PortalID) (userID libsignalgo.ServiceID, groupID types.GroupIdentifier, err error) { if len(portalID) == 44 { groupID = types.GroupIdentifier(portalID) diff --git a/pkg/signalmeow/groups.go b/pkg/signalmeow/groups.go index 0a67ef63..90311940 100644 --- a/pkg/signalmeow/groups.go +++ b/pkg/signalmeow/groups.go @@ -154,7 +154,7 @@ type RequestingMember struct { Timestamp uint64 } -type PromotePendingMembers struct { +type PromotePendingMember struct { ACI uuid.UUID ProfileKey libsignalgo.ProfileKey } @@ -178,7 +178,7 @@ type BannedMember struct { type GroupChange struct { groupMasterKey types.SerializedGroupMasterKey - SourceACI uuid.UUID + SourceServiceID libsignalgo.ServiceID Revision uint32 AddMembers []*AddMember DeleteMembers []*uuid.UUID @@ -186,7 +186,7 @@ type GroupChange struct { ModifyMemberProfileKeys []*ProfileKeyMember AddPendingMembers []*PendingMember DeletePendingMembers []*libsignalgo.ServiceID - PromotePendingMembers []*GroupMember + PromotePendingMembers []*PromotePendingMember ModifyTitle *string ModifyAvatar *string ModifyDisappearingMessagesDuration *uint32 @@ -862,9 +862,9 @@ func (cli *Client) decryptGroupChange(ctx context.Context, encryptedGroupChange return nil, fmt.Errorf("wrong serviceid kind: expected aci, got pni") } decryptedGroupChange := &GroupChange{ - groupMasterKey: groupMasterKey, - Revision: encryptedActions.Revision, - SourceACI: sourceServiceID.UUID, + groupMasterKey: groupMasterKey, + Revision: encryptedActions.Revision, + SourceServiceID: sourceServiceID, } if encryptedActions.ModifyTitle != nil { @@ -992,7 +992,7 @@ func (cli *Client) decryptGroupChange(ctx context.Context, encryptedGroupChange if err != nil { return nil, err } - decryptedGroupChange.PromotePendingMembers = append(decryptedGroupChange.PromotePendingMembers, &GroupMember{ + decryptedGroupChange.PromotePendingMembers = append(decryptedGroupChange.PromotePendingMembers, &PromotePendingMember{ ACI: *aci, ProfileKey: *profileKey, }) From 2f52b8f44b05e03582fa623a0d6f1e133a5cbc22 Mon Sep 17 00:00:00 2001 From: Malte E Date: Thu, 8 Aug 2024 22:46:01 +0200 Subject: [PATCH 2/5] fixes --- go.mod | 7 +++++++ go.sum | 5 +++++ pkg/connector/handlematrix.go | 32 +++++++++++++++++++++----------- pkg/signalid/ids.go | 7 ++----- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index c49fa0ff..e7b3e390 100644 --- a/go.mod +++ b/go.mod @@ -44,3 +44,10 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect maunium.net/go/mauflag v1.0.0 // indirect ) +<<<<<<< HEAD +======= + +//replace maunium.net/go/mautrix => ../mautrix-go +//replace go.mau.fi/util => ../../Go/go-util +replace maunium.net/go/mautrix => github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124 +>>>>>>> aec8c02 (fixes) diff --git a/go.sum b/go.sum index 4972d7b5..ca3f9472 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,11 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +<<<<<<< HEAD +======= +github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124 h1:zgSOHfcfq6NXuHL+mo/IexMGksBmrZcVyPjipTjEILc= +github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q= +>>>>>>> aec8c02 (fixes) github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index e86981c6..173ed278 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -373,14 +373,7 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 } gc := &signalmeow.GroupChange{} role := signalmeow.GroupMember_DEFAULT - toMembership := msg.Type.GetTo() - if toMembership == event.MembershipBan { - gc.AddBannedMembers = []*signalmeow.BannedMember{{ - ServiceID: libsignalgo.NewACIServiceID(targetSignalID), - Timestamp: uint64(time.Now().UnixMilli()), - }} - } - if toMembership == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock { + if msg.Type.To == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock { levels, err := msg.Portal.Bridge.Matrix.GetPowerLevels(ctx, msg.Portal.MXID) if err != nil { log.Err(err).Msg("Couldn't get power levels") @@ -391,10 +384,10 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 } switch msg.Type { case bridgev2.AcceptInvite: - gc.PromotePendingMembers = []*signalmeow.PromotePendingMember{&signalmeow.PromotePendingMember{ + gc.PromotePendingMembers = []*signalmeow.PromotePendingMember{{ ACI: targetSignalID, }} - case bridgev2.RevokeInvite, bridgev2.RejectInvite, bridgev2.BanInvited: + case bridgev2.RevokeInvite, bridgev2.RejectInvite: deletePendingMember := libsignalgo.NewACIServiceID(targetSignalID) gc.DeletePendingMembers = []*libsignalgo.ServiceID{&deletePendingMember} case bridgev2.Leave, bridgev2.Kick: @@ -426,11 +419,28 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 ACI: targetSignalID, Role: role, }} - case bridgev2.RetractKnock, bridgev2.RejectKnock, bridgev2.BanKnocked: + case bridgev2.RetractKnock, bridgev2.RejectKnock: gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID} + case bridgev2.BanKnocked, bridgev2.BanInvited, bridgev2.BanJoined, bridgev2.Ban: + gc.AddBannedMembers = []*signalmeow.BannedMember{{ + ServiceID: libsignalgo.NewACIServiceID(targetSignalID), + Timestamp: uint64(time.Now().UnixMilli()), + }} + switch msg.Type { + case bridgev2.BanJoined: + gc.DeleteMembers = []*uuid.UUID{&targetSignalID} + case bridgev2.BanInvited: + deletePendingMember := libsignalgo.NewACIServiceID(targetSignalID) + gc.DeletePendingMembers = []*libsignalgo.ServiceID{&deletePendingMember} + case bridgev2.BanKnocked: + gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID} + } case bridgev2.Unban: unbanUser := libsignalgo.NewACIServiceID(targetSignalID) gc.DeleteBannedMembers = []*libsignalgo.ServiceID{&unbanUser} + default: + log.Debug().Msg("unsupported membership change") + return false, nil } _, groupID, err := signalid.ParsePortalID(msg.Portal.ID) if err != nil || groupID == "" { diff --git a/pkg/signalid/ids.go b/pkg/signalid/ids.go index e9c83113..1209e90b 100644 --- a/pkg/signalid/ids.go +++ b/pkg/signalid/ids.go @@ -40,14 +40,11 @@ func ParseUserID(userID networkid.UserID) (uuid.UUID, error) { } func ParseUserLoginID(userLoginID networkid.UserLoginID) (uuid.UUID, error) { - serviceID, err := ParseUserLoginIDAsServiceID(userLoginID) + userID, err := ParseUserLoginID(userLoginID) if err != nil { return uuid.Nil, err - } else if serviceID.Type != libsignalgo.ServiceIDTypeACI { - return uuid.Nil, fmt.Errorf("invalid user ID: expected ACI type") - } else { - return serviceID.UUID, nil } + return userID, nil } func ParseUserIDAsServiceID(userID networkid.UserID) (libsignalgo.ServiceID, error) { From 0f3afe0ef6684e8c2870a974e1d654b3f0c727ef Mon Sep 17 00:00:00 2001 From: Malte E Date: Fri, 9 Aug 2024 22:10:55 +0200 Subject: [PATCH 3/5] update mautrix-go --- go.mod | 7 ------- go.sum | 5 ----- pkg/connector/handlematrix.go | 11 ++++++++++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index e7b3e390..c49fa0ff 100644 --- a/go.mod +++ b/go.mod @@ -44,10 +44,3 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect maunium.net/go/mauflag v1.0.0 // indirect ) -<<<<<<< HEAD -======= - -//replace maunium.net/go/mautrix => ../mautrix-go -//replace go.mau.fi/util => ../../Go/go-util -replace maunium.net/go/mautrix => github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124 ->>>>>>> aec8c02 (fixes) diff --git a/go.sum b/go.sum index ca3f9472..4972d7b5 100644 --- a/go.sum +++ b/go.sum @@ -25,11 +25,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -<<<<<<< HEAD -======= -github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124 h1:zgSOHfcfq6NXuHL+mo/IexMGksBmrZcVyPjipTjEILc= -github.com/maltee1/mautrix-go v0.0.0-20240808204140-9598e29d1124/go.mod h1:ZWyxoQxRTBxzWIMs0kQCVogZIY0clTu33h102veCT/Q= ->>>>>>> aec8c02 (fixes) github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 173ed278..2c4cb8fe 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -351,6 +351,15 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 var targetIntent bridgev2.MatrixAPI var targetSignalID uuid.UUID var err error + if msg.Portal.RoomType == database.RoomTypeDM { + //TODO: this probably needs to revert some changes and clean up the portal on leaves + switch msg.Type { + case bridgev2.Invite: + return false, fmt.Errorf("cannot invite additional user to dm") + default: + return false, nil + } + } if msg.TargetGhost != nil { targetIntent = msg.TargetGhost.Intent targetSignalID, err = signalid.ParseUserID(msg.TargetGhost.ID) @@ -421,7 +430,7 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 }} case bridgev2.RetractKnock, bridgev2.RejectKnock: gc.DeleteRequestingMembers = []*uuid.UUID{&targetSignalID} - case bridgev2.BanKnocked, bridgev2.BanInvited, bridgev2.BanJoined, bridgev2.Ban: + case bridgev2.BanKnocked, bridgev2.BanInvited, bridgev2.BanJoined, bridgev2.BanLeft: gc.AddBannedMembers = []*signalmeow.BannedMember{{ ServiceID: libsignalgo.NewACIServiceID(targetSignalID), Timestamp: uint64(time.Now().UnixMilli()), From d75cf039e23abcfd328f4c6ff27dfcbf44a542ed Mon Sep 17 00:00:00 2001 From: Malte E Date: Fri, 9 Aug 2024 22:30:12 +0200 Subject: [PATCH 4/5] remove global log --- pkg/connector/handlematrix.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/connector/handlematrix.go b/pkg/connector/handlematrix.go index 2c4cb8fe..2b8ca269 100644 --- a/pkg/connector/handlematrix.go +++ b/pkg/connector/handlematrix.go @@ -25,7 +25,6 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" - "github.com/rs/zerolog/log" "go.mau.fi/util/variationselector" "google.golang.org/protobuf/proto" "maunium.net/go/mautrix/bridgev2" @@ -380,6 +379,10 @@ func (s *SignalClient) HandleMatrixMembership(ctx context.Context, msg *bridgev2 targetIntent = ghost.Intent } } + log := zerolog.Ctx(ctx).With(). + Str("From Membership", string(msg.Type.From)). + Str("To Membership", string(msg.Type.To)). + Logger() gc := &signalmeow.GroupChange{} role := signalmeow.GroupMember_DEFAULT if msg.Type.To == event.MembershipInvite || msg.Type == bridgev2.AcceptKnock { From 06fcd2d352ee8412f77b46059a263f14edc04c41 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 9 Aug 2024 23:41:21 +0300 Subject: [PATCH 5/5] Apply suggestions from code review --- pkg/signalid/ids.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/signalid/ids.go b/pkg/signalid/ids.go index 1209e90b..99ef7b3e 100644 --- a/pkg/signalid/ids.go +++ b/pkg/signalid/ids.go @@ -40,7 +40,7 @@ func ParseUserID(userID networkid.UserID) (uuid.UUID, error) { } func ParseUserLoginID(userLoginID networkid.UserLoginID) (uuid.UUID, error) { - userID, err := ParseUserLoginID(userLoginID) + userID, err := uuid.Parse(string(userLoginID)) if err != nil { return uuid.Nil, err } @@ -51,10 +51,6 @@ func ParseUserIDAsServiceID(userID networkid.UserID) (libsignalgo.ServiceID, err return libsignalgo.ServiceIDFromString(string(userID)) } -func ParseUserLoginIDAsServiceID(userLoginID networkid.UserLoginID) (libsignalgo.ServiceID, error) { - return libsignalgo.ServiceIDFromString(string(userLoginID)) -} - func ParsePortalID(portalID networkid.PortalID) (userID libsignalgo.ServiceID, groupID types.GroupIdentifier, err error) { if len(portalID) == 44 { groupID = types.GroupIdentifier(portalID)